{"thread":{"id":"14116","subject":"[PATCH] help: check early if we have a command, if not try a documentation topic","startedAt":"2008-06-24T06:46:53Z","lastAt":"2008-06-24T06:46:53Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"80837","messageId":"20080624084653.8b181a0a.chriscool@tuxfamily.org","threadId":"14116","inReplyTo":null,"subject":"[PATCH] help: check early if we have a command, if not try a documentation topic","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-06-24T06:46:53Z","receivedAt":"2008-06-24T06:46:53Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Before this patch, something like \"git help tutorial\" did not work,\npeople had to use \"git help gittutorial\" which is not very intuitive.\n\nThis patch uses the \"is_git_command\" function to test early if the\nargument passed to \"git help\" is a git command, and if this is not the\ncase then we prefix the argument with \"git\" instead of \"git-\".\n\nThis way, things like \"git help tutorial\" or \"git help glossary\" will\nwork fine.\n\nThe little downside of this patch is that the \"is_git_command\" is a\nlittle bit slow.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n help.c |   23 +++++++++++++++--------\n 1 files changed, 15 insertions(+), 8 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 8aff94c..ef2e6b7 100644\n--- a/help.c\n+++ b/help.c\n@@ -527,20 +527,27 @@ static int is_git_command(const char *s)\n \t\tis_in_cmdlist(&other_cmds, s);\n }\n \n+static const char *add_prefix(const char *prefix, const char *cmd)\n+{\n+\tsize_t pre_len = strlen(prefix);\n+\tsize_t cmd_len = strlen(cmd);\n+\tchar *p = xmalloc(pre_len + cmd_len + 1);\n+\tstrcpy(p, prefix);\n+\tstrcpy(p + pre_len, cmd);\n+\tp[pre_len + cmd_len] = 0;\n+\treturn p;\n+}\n+\n static const char *cmd_to_page(const char *git_cmd)\n {\n \tif (!git_cmd)\n \t\treturn \"git\";\n \telse if (!prefixcmp(git_cmd, \"git\"))\n \t\treturn git_cmd;\n-\telse {\n-\t\tint page_len = strlen(git_cmd) + 4;\n-\t\tchar *p = xmalloc(page_len + 1);\n-\t\tstrcpy(p, \"git-\");\n-\t\tstrcpy(p + 4, git_cmd);\n-\t\tp[page_len] = 0;\n-\t\treturn p;\n-\t}\n+\telse if (is_git_command(git_cmd))\n+\t\treturn add_prefix(\"git-\", git_cmd);\n+\telse\n+\t\treturn add_prefix(\"git\", git_cmd);\n }\n \n static void setup_man_path(void)\n-- \n1.5.6.109.g4f927.dirty\n"}]}