summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorAndreas Ericsson <exon@op5.se>2005-11-15 23:31:25 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-11-16 00:03:00 (GMT)
commit97fc6c5fbacc2181319bbd7e2faa8ac04476f862 (patch)
tree1d6fd74ad1e1f6cd678b35e2de2388e6ee1310ef /git.c
parentcb22bc44474686f1e0d1ad991732ccd634498729 (diff)
downloadgit-97fc6c5fbacc2181319bbd7e2faa8ac04476f862.zip
git-97fc6c5fbacc2181319bbd7e2faa8ac04476f862.tar.gz
git-97fc6c5fbacc2181319bbd7e2faa8ac04476f862.tar.bz2
git --help COMMAND brings up the git-COMMAND man-page.
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git.c')
-rw-r--r--git.c28
1 files changed, 26 insertions, 2 deletions
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 *dir, int len)
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 **envp)
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)) {