X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=help.c;h=5d1a773ad7f3ed811c35a6b9fa8afe1697615cc8;hb=0989fe9623dc8d98033f6acdcc0c84ec28571b19;hp=8aff94c64a1204f8a359e522a554f29c8f0fdc20;hpb=ea81e10ff4e31820407f4cb1b8ebd87de9e51737;p=git.git diff --git a/help.c b/help.c index 8aff94c64..5d1a773ad 100644 --- a/help.c +++ b/help.c @@ -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)