[PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page., take two

Subsystems: documentation, the rest

DORMANTno replies

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page., take two

From: Andreas Ericsson <hidden>
Date: 2016-06-15 22:42:12

It's by design a bit stupid (matching ^git rather than ^git-), so as
to work with 'gitk' and 'git' as well.

Signed-off-by: Andreas Ericsson <redacted>

---

 Documentation/git.txt |    2 ++
 git.c                 |   26 ++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

applies-to: 8a47ae8a825ab0e68ac46392bccd1ec16df39456
53e2024f89514d31a45936e3596e3d285dfd1bfe
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 91e9f9f..7cbfaf8 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -24,6 +24,8 @@ OPTIONS
 
 --help::
 	prints the synopsis and a list of available commands.
+	If a git command is named this option will bring up the
+	man-page for that command.
 
 --exec-path::
 	path to wherever your core git programs are installed.
diff --git a/git.c b/git.c
index d189801..4b7cbf6 100644
--- a/git.c
+++ b/git.c
@@ -160,6 +160,24 @@ static void prepend_to_path(const char *
 	setenv("PATH", path, 1);
 }
 
+static void show_man_page(char *git_cmd)
+{
+	char *page;
+
+	if (!strncmp(git_cmd, "git", 3))
+		page = git_cmd;
+	else {
+		int page_len = strlen(git_cmd) + 4;
+
+		page = malloc(page_len + 1);
+		strcpy(page, "git-");
+		strcpy(page + 4, git_cmd);
+		page[page_len] = 0;
+	}
+
+	execlp("man", "man", page, NULL);
+}
+
 int main(int argc, char **argv, char **envp)
 {
 	char git_command[PATH_MAX + 1];
@@ -199,8 +217,12 @@ int main(int argc, char **argv, char **e
 			usage(NULL, NULL);
 	}
 
-	if (i >= argc || show_help)
-		usage(exec_path, NULL);
+	if (i >= argc || show_help) {
+		if (i >= argc)
+			usage(exec_path, NULL);
+
+		show_man_page(argv[i]);
+	}
 
 	/* allow relative paths, but run with exact */
 	if (chdir(exec_path)) {
---
0.99.9.GIT

Re: [PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page., take two

From: "H. Peter Anvin" <hpa@zytor.com>
Date: 2016-06-15 22:42:12

Andreas Ericsson wrote:
 
+static void show_man_page(char *git_cmd)
+{
+	char *page;
+
+	if (!strncmp(git_cmd, "git", 3))
+		page = git_cmd;
+	else {
+		int page_len = strlen(git_cmd) + 4;
+
+		page = malloc(page_len + 1);
+		strcpy(page, "git-");
+		strcpy(page + 4, git_cmd);
+		page[page_len] = 0;
+	}
+
+	execlp("man", "man", page, NULL);
+}
+
The way this made it into the actual tree was to call /usr/bin/man, but 
still using execlp().  This is clearly bogus.  There *ARE* good reasons 
to use PATH resolutions for this, since man is one of the interactive 
commands the user may want to wrapper.

So please drop PATH_TO_MAN that made it into the repository and revert 
to the original patch.

	-hpa

Re: [PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page., take two

From: Andreas Ericsson <hidden>
Date: 2016-06-15 22:42:12

H. Peter Anvin wrote:
Andreas Ericsson wrote:
quoted
+
+    execlp("man", "man", page, NULL);
+}
+

The way this made it into the actual tree was to call /usr/bin/man, but 
still using execlp().  This is clearly bogus.  There *ARE* good reasons 
to use PATH resolutions for this, since man is one of the interactive 
commands the user may want to wrapper.
Everyone agrees. I just brained the original implementation.
So please drop PATH_TO_MAN that made it into the repository and revert 
to the original patch.
PATH_TO_MAN *was* the original. This is the updated version. I think 
Junio imported the wrong one by mistake, cause I sent this one 
specifically to fix the first one.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help