{"thread":{"id":"11186","subject":"[PATCH] git-help: simplify and fix option parsing.","startedAt":"2007-12-08T05:06:27Z","lastAt":"2007-12-08T05:06:27Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"62371","messageId":"20071208060627.4d89f488.chriscool@tuxfamily.org","threadId":"11186","inReplyTo":null,"subject":"[PATCH] git-help: simplify and fix option parsing.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-12-08T05:06:27Z","receivedAt":"2007-12-08T05:06:27Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n help.c |   31 +++++++++++--------------------\n 1 files changed, 11 insertions(+), 20 deletions(-)\n\n\tJunio wrote about \"help.c\" in my \n\t\"git-help: add -w|--web option to display html man page in a browser.\"\n\tpatch:\n\t> Isn't this \"check-help-cmd\" duplication ugly, by the way?\n\n\tYou are right, this patch should fix it.\n\tThanks.\n\ndiff --git a/help.c b/help.c\nindex ecc8c66..78686db 100644\n--- a/help.c\n+++ b/help.c\n@@ -241,7 +241,9 @@ void list_common_cmds_help(void)\n \n static const char *cmd_to_page(const char *git_cmd)\n {\n-\tif (!prefixcmp(git_cmd, \"git\"))\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@@ -283,38 +285,27 @@ int cmd_version(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static void check_help_cmd(const char *help_cmd)\n+int cmd_help(int argc, const char **argv, const char *prefix)\n {\n-\tif (!help_cmd) {\n+\tif (argc < 2) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n \t\tlist_common_cmds_help();\n \t\texit(0);\n \t}\n \n-\telse if (!strcmp(help_cmd, \"--all\") || !strcmp(help_cmd, \"-a\")) {\n+\tconst char *help_cmd = argv[1];\n+\n+\tif (!strcmp(help_cmd, \"--all\") || !strcmp(help_cmd, \"-a\")) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n \t\tlist_commands();\n-\t\texit(0);\n \t}\n-}\n \n-int cmd_help(int argc, const char **argv, const char *prefix)\n-{\n-\tconst char *help_cmd = argc > 1 ? argv[1] : NULL;\n-\tcheck_help_cmd(help_cmd);\n-\n-\tif (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\")) {\n-\t\thelp_cmd = argc > 2 ? argv[2] : NULL;\n-\t\tcheck_help_cmd(help_cmd);\n-\n-\t\tshow_html_page(help_cmd);\n+\telse if (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\")) {\n+\t\tshow_html_page(argc > 2 ? argv[2] : NULL);\n \t}\n \n \telse if (!strcmp(help_cmd, \"--info\") || !strcmp(help_cmd, \"-i\")) {\n-\t\thelp_cmd = argc > 2 ? argv[2] : NULL;\n-\t\tcheck_help_cmd(help_cmd);\n-\n-\t\tshow_info_page(help_cmd);\n+\t\tshow_info_page(argc > 2 ? argv[2] : NULL);\n \t}\n \n \telse\n-- \n1.5.3.7.2199.ge1512-dirty\n"}]}