Skip to content

Commit

Permalink
help: check early if we have a command, if not try a documentation topic
Browse files Browse the repository at this point in the history
Before this patch, something like "git help tutorial" did not work,
people had to use "git help gittutorial" which is not very intuitive.

This patch uses the "is_git_command" function to test early if the
argument passed to "git help" is a git command, and if this is not the
case then we prefix the argument with "git" instead of "git-".

This way, things like "git help tutorial" or "git help glossary" will
work fine.

The little downside of this patch is that the "is_git_command" is a
little bit slow.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Christian Couder authored and Junio C Hamano committed Jun 28, 2008
1 parent d0658ec commit 2dce956
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,20 +527,26 @@ static int is_git_command(const char *s)
is_in_cmdlist(&other_cmds, s);
}

static const char *prepend(const char *prefix, const char *cmd)
{
size_t pre_len = strlen(prefix);
size_t cmd_len = strlen(cmd);
char *p = xmalloc(pre_len + cmd_len + 1);
memcpy(p, prefix, pre_len);
strcpy(p + pre_len, cmd);
return p;
}

static const char *cmd_to_page(const char *git_cmd)
{
if (!git_cmd)
return "git";
else if (!prefixcmp(git_cmd, "git"))
return git_cmd;
else {
int page_len = strlen(git_cmd) + 4;
char *p = xmalloc(page_len + 1);
strcpy(p, "git-");
strcpy(p + 4, git_cmd);
p[page_len] = 0;
return p;
}
else if (is_git_command(git_cmd))
return prepend("git-", git_cmd);
else
return prepend("git", git_cmd);
}

static void setup_man_path(void)
Expand Down

0 comments on commit 2dce956

Please sign in to comment.