@matheusbsbs / matheus-bagliano / commits / 2dce956e39
Fork 0

help: check early if we have a command, if not try a documentation topic

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>

Christian Couder committed Jun 28, 2008 at 06:35 UTC 2dce956e397be8a769624e8693565b8a30056060
1 file changed +14 -8
help.c
+14 -8
@@ -527,20 +527,26 @@ static int is_git_command(const char *s)
527 is_in_cmdlist(&other_cmds, s);
528 }
529
530 +static const char *prepend(const char *prefix, const char *cmd)
531 +{
532 + size_t pre_len = strlen(prefix);
533 + size_t cmd_len = strlen(cmd);
534 + char *p = xmalloc(pre_len + cmd_len + 1);
535 + memcpy(p, prefix, pre_len);
536 + strcpy(p + pre_len, cmd);
537 + return p;
538 +}
539 +
540 static const char *cmd_to_page(const char *git_cmd)
541 {
542 if (!git_cmd)
543 return "git";
544 else if (!prefixcmp(git_cmd, "git"))
545 return git_cmd;
536 - else {
537 - int page_len = strlen(git_cmd) + 4;
538 - char *p = xmalloc(page_len + 1);
539 - strcpy(p, "git-");
540 - strcpy(p + 4, git_cmd);
541 - p[page_len] = 0;
542 - return p;
543 - }
546 + else if (is_git_command(git_cmd))
547 + return prepend("git-", git_cmd);
548 + else
549 + return prepend("git", git_cmd);
550 }
551
552 static void setup_man_path(void)