# [PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page.

3 messages from 2005-11-15 to 2005-11-16. Participants: Andreas Ericsson, Junio C Hamano.
Thread: https://gitlist.dev/t/2539

## Andreas Ericsson, 2005-11-15 23:31

Subject: [PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page.
Message-ID: <20051115233125.2C0355BF73@nox.op5.se>
URL: https://gitlist.dev/e/20051115233125.2C0355BF73%40nox.op5.se

```

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 <ae@op5.se>

---

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

applies-to: 8a47ae8a825ab0e68ac46392bccd1ec16df39456
3b7d6e6722b0d27ef5f9ae99a76d3ff909d3e98a
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..583923d 100644
--- a/git.c
+++ b/git.c
@@ -160,6 +160,26 @@ static void prepend_to_path(const char *
 	setenv("PATH", path, 1);
 }
 
+/* has anyone seen 'man' installed anywhere else than in /usr/bin? */
+#define PATH_TO_MAN "/usr/bin/man"
+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(PATH_TO_MAN, "man", page, NULL);
+}
+
 int main(int argc, char **argv, char **envp)
 {
 	char git_command[PATH_MAX + 1];
@@ -199,8 +219,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

```

## Junio C Hamano, 2005-11-15 23:49

Subject: Re: [PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page.
Message-ID: <7vsltxeakh.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vsltxeakh.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20051115233125.2C0355BF73@nox.op5.se>

```
exon@op5.se (Andreas Ericsson) writes:

> 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 <ae@op5.se>

Thanks, stupid is fine.

> +/* has anyone seen 'man' installed anywhere else than in /usr/bin? */
> +#define PATH_TO_MAN "/usr/bin/man"
> +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(PATH_TO_MAN, "man", page, NULL);
> +}

If you do PATH_TO_MAN absolute, execl would suffice, but just
saying "man" and have execlp look for it would be easier to
manage.

```

## Andreas Ericsson, 2005-11-16 00:24

Subject: Re: [PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page.
Message-ID: <437A7C26.5020400@op5.se>
URL: https://gitlist.dev/e/437A7C26.5020400%40op5.se
In-Reply-To: <7vsltxeakh.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:
>>+
>>+	execlp(PATH_TO_MAN, "man", page, NULL);
>>+}
> 
> 
> If you do PATH_TO_MAN absolute, execl would suffice, but just
> saying "man" and have execlp look for it would be easier to
> manage.
> 
> 

Never even occurred to me, actually. I just re-submitted the patch.


-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

```
