{"thread":{"id":"12147","subject":"[PATCH] git help: sort commands by topi","startedAt":"2008-02-17T14:48:21Z","lastAt":"2008-02-18T17:16:00Z","messageCount":3,"participants":["Santi Bejar","Junio C Hamano","Santi Béjar"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"68991","messageId":"87hcg77i6i.fsf@gmail.com","threadId":"12147","inReplyTo":null,"subject":"[PATCH] git help: sort commands by topi","fromName":"Santi Bejar","fromEmail":"sbejar@gmail.com","sentAt":"2008-02-17T14:48:21Z","receivedAt":"2008-02-17T14:48:21Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"Hi *,\n\n here is a patch that I've sent a lot of times to the list and it has not\narrived, I suppose because the spam filtering, but I've look the filter\napplied and I do not find anything. I've also compared this with other\nmails I've sent and I don't see anything relevant. I'm sending the\nthe patch as an attachment.\n\nSanti\n\nP.D: Does anyone know how can I know the reason for the drops?\n\n\n\n>From 3379f6e84035748fc9d1a14fbfcbc31b20a3582c Mon Sep 17 00:00:00 2001\nFrom: =?utf-8?q?Santi=20B=C3=A9jar?= <sbejar@gmail.com>\nDate: Sun, 27 Jan 2008 01:34:57 +0100\nSubject: [PATCH] git help -t|--topic: lists all the commands classified by topic\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n\nAdditionally shows a hint to get the long list when listing the common commands.\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\n Documentation/git-help.txt |    8 +++++-\n Makefile                   |    2 +-\n generate-cmdlist.sh        |   28 ++++++++++++++++++------\n help.c                     |   51 ++++++++++++++++++++++++++++++++++++-------\n topic-list.txt             |   12 ++++++++++\n 5 files changed, 82 insertions(+), 19 deletions(-)\n create mode 100644 topic-list.txt\n\ndiff --git a/Documentation/git-help.txt b/Documentation/git-help.txt\nindex 0926dc1..26998c5 100644\n--- a/Documentation/git-help.txt\n+++ b/Documentation/git-help.txt\n@@ -7,7 +7,7 @@ git-help - display help information about git\n \n SYNOPSIS\n --------\n-'git help' [-a|--all|-i|--info|-m|--man|-w|--web] [COMMAND]\n+'git help' [-a|--all|-i|--info|-m|--man|-t|--topic|-w|--web] [COMMAND]\n \n DESCRIPTION\n -----------\n@@ -17,7 +17,8 @@ command and a list of the most commonly used git commands are printed\n on the standard output.\n \n If the option '--all' or '-a' is given, then all available commands are\n-printed on the standard output.\n+printed on the standard output. For a list of all git commands classified by\n+topic use '--topic' of '-t'.\n \n If a git command is named, a manual page for that command is brought\n up. The 'man' program is used by default for this purpose, but this\n@@ -41,6 +42,9 @@ OPTIONS\n \tused to override a value set in the 'help.format'\n \tconfiguration variable.\n \n+-t|--topic::\n+\tPrints all the commands classified by topic.\n+\n -w|--web::\n \tUse a web browser to display the HTML manual page, instead of\n \tthe 'man' program that is used by default.\ndiff --git a/Makefile b/Makefile\nindex 83c359a..64ca31a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -837,7 +837,7 @@ git-merge-subtree$X: git-merge-recursive$X\n $(BUILT_INS): git$X\n \t$(QUIET_BUILT_IN)$(RM) $@ && ln git$X $@\n \n-common-cmds.h: ./generate-cmdlist.sh command-list.txt\n+common-cmds.h: ./generate-cmdlist.sh command-list.txt topic-list.txt\n \n common-cmds.h: $(wildcard Documentation/git-*.txt)\n \t$(QUIET_GEN)./generate-cmdlist.sh > $@+ && mv $@+ $@\ndiff --git a/generate-cmdlist.sh b/generate-cmdlist.sh\nindex a2913c2..ec623dd 100755\n--- a/generate-cmdlist.sh\n+++ b/generate-cmdlist.sh\n@@ -3,22 +3,36 @@\n echo \"/* Automatically generated by $0 */\n struct cmdname_help\n {\n-    char name[16];\n+    char name[23];\n     char help[80];\n+    char topic[22];\n+    char subtopic[10];\n };\n \n-static struct cmdname_help common_cmds[] = {\"\n+struct topicname_help\n+{\n+    char name[23];\n+    char subtopic[10];\n+    char help[80];\n+};\n \n-sed -n -e 's/^git-\\([^ \t]*\\)[ \t].* common.*/\\1/p' command-list.txt |\n-sort |\n-while read cmd\n+static struct cmdname_help cmd_list[] = {\"\n+\n+sed -n -e 's/^git-\\([^ \t]*\\)\\(.*\\)$/\\1\\2/p' command-list.txt |\n+grep -v deprecated | sort |\n+while read cmd topic subtopic\n do\n      sed -n '\n-     /NAME/,/git-'\"$cmd\"'/H\n+     /^NAME$/,/git-'\"$cmd\"'/H\n      ${\n             x\n-            s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\"},/\n+            s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\",/\n \t    p\n      }' \"Documentation/git-$cmd.txt\"\n+     echo  \"\\\"$topic\\\", \\\"$subtopic\\\" },\"\n done\n echo \"};\"\n+\n+echo \"static struct topicname_help topic_list[] = {\"\n+sed -n -e 's/^topic-\\([^ ]*\\)\t\\(common\\|\\)\t\\(.*\\)$/{\\\"\\1\\\", \\\"\\2\\\", \\\"\\3\\\"},/p' topic-list.txt\n+echo \"};\"\ndiff --git a/help.c b/help.c\nindex 6e28ad9..0e3a350 100644\n--- a/help.c\n+++ b/help.c\n@@ -262,20 +262,48 @@ static void list_commands(void)\n \t}\n }\n \n-void list_common_cmds_help(void)\n+void list_topic_cmds_help(const char *topic, const char *subtopic)\n {\n \tint i, longest = 0;\n \n-\tfor (i = 0; i < ARRAY_SIZE(common_cmds); i++) {\n-\t\tif (longest < strlen(common_cmds[i].name))\n-\t\t\tlongest = strlen(common_cmds[i].name);\n+\tfor (i = 0; i < ARRAY_SIZE(topic_list); i++) {\n+\t\tif (!strcmp(topic_list[i].name, topic) &&\n+\t\t    !strcmp(topic_list[i].subtopic, subtopic)) {\n+\t\t\tprintf(\"%s:\\n\",topic_list[i].help);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < ARRAY_SIZE(cmd_list); i++) {\n+\t\tif (strcmp(cmd_list[i].topic, topic)) continue;\n+\t\tif (!strcmp(topic_list[i].subtopic,\"\") &&\n+\t\t    strcmp(cmd_list[i].subtopic, subtopic)) continue;\n+\t\tif (longest < strlen(cmd_list[i].name))\n+\t\t\tlongest = strlen(cmd_list[i].name);\n \t}\n \n-\tputs(\"The most commonly used git commands are:\");\n-\tfor (i = 0; i < ARRAY_SIZE(common_cmds); i++) {\n-\t\tprintf(\"   %s   \", common_cmds[i].name);\n-\t\tmput_char(' ', longest - strlen(common_cmds[i].name));\n-\t\tputs(common_cmds[i].help);\n+\tfor (i = 0; i < ARRAY_SIZE(cmd_list); i++) {\n+\t\tif (strcmp(cmd_list[i].topic, topic)) continue;\n+\t\tif (!strcmp(topic_list[i].subtopic,\"\") &&\n+\t\t    strcmp(cmd_list[i].subtopic, subtopic)) continue;\n+\t\t\tprintf(\"   %s   \", cmd_list[i].name);\n+\t\t\tmput_char(' ', longest - strlen(cmd_list[i].name));\n+\t\t\tputs(cmd_list[i].help);\n+\t}\n+\tputchar('\\n');\n+}\n+\n+void list_common_cmds_help(void)\n+{\n+\tlist_topic_cmds_help(\"mainporcelain\",\"common\");\n+\tputs(\"(use 'git help -t' to get a longer list)\");\n+}\n+\n+void list_topics_help()\n+{\n+\tint i;\n+\tfor (i = 0; i < ARRAY_SIZE(topic_list); i++) {\n+\t\tif(strcmp(topic_list[i].subtopic,\"\")) continue;\n+\t\tlist_topic_cmds_help(topic_list[i].name,\"\");\n \t}\n }\n \n@@ -391,6 +419,11 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\tshow_man_page(argc > 2 ? argv[2] : NULL);\n \t}\n \n+\telse if (!strcmp(help_cmd, \"--topic\") || !strcmp(help_cmd, \"-t\")) {\n+\t\tsetup_pager();\n+\t\tlist_topics_help();\n+\t}\n+\n \telse {\n \t\tint nongit;\n \ndiff --git a/topic-list.txt b/topic-list.txt\nnew file mode 100644\nindex 0000000..2ba11a9\n--- /dev/null\n+++ b/topic-list.txt\n@@ -0,0 +1,12 @@\n+# List of known git topics.\n+# topic name\t\t\t\thelp\n+common                                  The most commonly used commands\n+mainporcelain                           Main porcelain commands\n+ancillarymanipulators\t\t\tInterrogators commands\n+ancillaryinterrogators\t\t\tManipulators commands\n+foreignscminterface \t\t\tCommands dealing with foreing SCM\n+plumbingmanipulators\t\t\tLow-level manipulation commands\n+plumbinginterrogators\t\t\tLow-level Interrogation commands\n+synchingrepositories\t\t\tSynching repositories\n+synchelpers\t\t\t\tSynching helper commands\n+purehelpers\t\t\t\tInternal helper commands\n-- \n1.5.4.1219.g65b9\n\n"},{"id":"69112","messageId":"7vlk5ipo3c.fsf@gitster.siamese.dyndns.org","threadId":"12147","inReplyTo":"87hcg77i6i.fsf@gmail.com","subject":"Re: [PATCH] git help: sort commands by topi","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-18T10:15:35Z","receivedAt":"2008-02-18T10:15:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Santi Bejar\" <sbejar@gmail.com> writes:\n\n> P.D: Does anyone know how can I know the reason for the drops?\n\nI'd love to know that myself.\n\nIt would be interesting to install the kernel's checkpatch.pl\nas anti-bogo-style filter on the mailing list ;-)\n\n> diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh\n> index a2913c2..ec623dd 100755\n> --- a/generate-cmdlist.sh\n> +++ b/generate-cmdlist.sh\n> @@ -3,22 +3,36 @@\n>  echo \"/* Automatically generated by $0 */\n>  struct cmdname_help\n>  {\n> -    char name[16];\n> +    char name[23];\n>      char help[80];\n> +    char topic[22];\n> +    char subtopic[10];\n>  };\n\nThese limits are very magic.  If you are generating them in the\nscript perhaps you would want to count bytes?\n\nI dunno.  Honestly, I am not very interested in this patch\nmyself.\n\n\tSide Note: my not being interested does not mean I\n        strongly oppose to its inclusion (I do not even care).\n        It is just that I won't be the one who will be pushing\n        for its inclusion, and you would want supporters other\n        than me to push for it.\n\n> -static struct cmdname_help common_cmds[] = {\"\n> +struct topicname_help\n> +{\n> +    char name[23];\n> +    char subtopic[10];\n> +    char help[80];\n> +};\n\nLikewise.\n\n> -sed -n -e 's/^git-\\([^ \t]*\\)[ \t].* common.*/\\1/p' command-list.txt |\n> -sort |\n> -while read cmd\n> +static struct cmdname_help cmd_list[] = {\"\n> +\n> +sed -n -e 's/^git-\\([^ \t]*\\)\\(.*\\)$/\\1\\2/p' command-list.txt |\n> +grep -v deprecated | sort |\n> +while read cmd topic subtopic\n\nI do not like this pipeline to send output of sed to an _overly_\nloose grep.  What happens when we introduce \"git-deprecated\"\ncommand later?\n\n>  do\n>       sed -n '\n> -     /NAME/,/git-'\"$cmd\"'/H\n> +     /^NAME$/,/git-'\"$cmd\"'/H\n\nGood tightening.\n\n>       ${\n>              x\n> -            s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\"},/\n> +            s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\",/\n>  \t    p\n>       }' \"Documentation/git-$cmd.txt\"\n> +     echo  \"\\\"$topic\\\", \\\"$subtopic\\\" },\"\n\nBreaks nicely indented entries like:\n\n    {\"add\", \"Add file contents...\n\n> diff --git a/help.c b/help.c\n> index 6e28ad9..0e3a350 100644\n> --- a/help.c\n> +++ b/help.c\n> @@ -262,20 +262,48 @@ static void list_commands(void)\n> ...\n\n> +\tfor (i = 0; i < ARRAY_SIZE(cmd_list); i++) {\n> +\t\tif (strcmp(cmd_list[i].topic, topic)) continue;\n> +\t\tif (!strcmp(topic_list[i].subtopic,\"\") &&\n> +\t\t    strcmp(cmd_list[i].subtopic, subtopic)) continue;\n> +\t\tif (longest < strlen(cmd_list[i].name))\n> +\t\t\tlongest = strlen(cmd_list[i].name);\n>  \t}\n\nStyle.  A statement comes on its own line, even if it is a\n\"continue\" statement.\n\n> +\tfor (i = 0; i < ARRAY_SIZE(cmd_list); i++) {\n> +\t\tif (strcmp(cmd_list[i].topic, topic)) continue;\n> +\t\tif (!strcmp(topic_list[i].subtopic,\"\") &&\n> +\t\t    strcmp(cmd_list[i].subtopic, subtopic)) continue;\n> +\t\t\tprintf(\"   %s   \", cmd_list[i].name);\n> +\t\t\tmput_char(' ', longest - strlen(cmd_list[i].name));\n> +\t\t\tputs(cmd_list[i].help);\n> +\t}\n> +\tputchar('\\n');\n\nLikewise.\n\n> +void list_topics_help()\n> +{\n> +\tint i;\n> +\tfor (i = 0; i < ARRAY_SIZE(topic_list); i++) {\n> +\t\tif(strcmp(topic_list[i].subtopic,\"\")) continue;\n> +\t\tlist_topic_cmds_help(topic_list[i].name,\"\");\n>  \t}\n>  }\n\nStyle.  Have a SP before '(' if the previous token is not a\nfunction name.\n\n> diff --git a/topic-list.txt b/topic-list.txt\n> new file mode 100644\n> index 0000000..2ba11a9\n> --- /dev/null\n> +++ b/topic-list.txt\n> @@ -0,0 +1,12 @@\n> +# List of known git topics.\n> +# topic name\t\t\t\thelp\n> +common                                  The most commonly used commands\n> +mainporcelain                           Main porcelain commands\n> ...\n> +synchelpers\t\t\t\tSynching helper commands\n> +purehelpers\t\t\t\tInternal helper commands\n\nI wonder if this can be shared with the section headings of\nDocumentation/git.txt; either generate the section headings from\nthis file, or generate this file from the section headings.\n"},{"id":"69173","messageId":"8aa486160802180916t3807d505g9ed85c18d8884649@mail.gmail.com","threadId":"12147","inReplyTo":"7vlk5ipo3c.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git help: sort commands by topi","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-02-18T17:16:00Z","receivedAt":"2008-02-18T17:16:00Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"On Feb 18, 2008 11:15 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Santi Bejar\" <sbejar@gmail.com> writes:\n> > diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh\n> > index a2913c2..ec623dd 100755\n> > --- a/generate-cmdlist.sh\n> > +++ b/generate-cmdlist.sh\n> > @@ -3,22 +3,36 @@\n> >  echo \"/* Automatically generated by $0 */\n> >  struct cmdname_help\n> >  {\n> > -    char name[16];\n> > +    char name[23];\n> >      char help[80];\n> > +    char topic[22];\n> > +    char subtopic[10];\n> >  };\n>\n> These limits are very magic.  If you are generating them in the\n> script perhaps you would want to count bytes?\n>\n\nThey were already there. Maybe in a cleanup patch.\n\n> I dunno.  Honestly, I am not very interested in this patch\n> myself.\n>\n>         Side Note: my not being interested does not mean I\n>         strongly oppose to its inclusion (I do not even care).\n>         It is just that I won't be the one who will be pushing\n>         for its inclusion, and you would want supporters other\n>         than me to push for it.\n\nOK.\n\n>\n> > -static struct cmdname_help common_cmds[] = {\"\n> > +struct topicname_help\n> > +{\n> > +    char name[23];\n> > +    char subtopic[10];\n> > +    char help[80];\n> > +};\n>\n> Likewise.\n>\n> > -sed -n -e 's/^git-\\([^       ]*\\)[   ].* common.*/\\1/p' command-list.txt |\n> > -sort |\n> > -while read cmd\n> > +static struct cmdname_help cmd_list[] = {\"\n> > +\n> > +sed -n -e 's/^git-\\([^       ]*\\)\\(.*\\)$/\\1\\2/p' command-list.txt |\n> > +grep -v deprecated | sort |\n> > +while read cmd topic subtopic\n>\n> I do not like this pipeline to send output of sed to an _overly_\n> loose grep.  What happens when we introduce \"git-deprecated\"\n> command later?\n\nI'll look at it.\n\n[...]\n\n> >       ${\n> >              x\n> > -            s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\"},/\n> > +            s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\",/\n> >           p\n> >       }' \"Documentation/git-$cmd.txt\"\n> > +     echo  \"\\\"$topic\\\", \\\"$subtopic\\\" },\"\n>\n> Breaks nicely indented entries like:\n>\n>     {\"add\", \"Add file contents...\n>\n\nSorry, but I do not undestand this.\n\n[...]\n\n> > diff --git a/topic-list.txt b/topic-list.txt\n> > new file mode 100644\n> > index 0000000..2ba11a9\n> > --- /dev/null\n> > +++ b/topic-list.txt\n> > @@ -0,0 +1,12 @@\n> > +# List of known git topics.\n> > +# topic name                         help\n> > +common                                  The most commonly used commands\n> > +mainporcelain                           Main porcelain commands\n> > ...\n> > +synchelpers                          Synching helper commands\n> > +purehelpers                          Internal helper commands\n>\n> I wonder if this can be shared with the section headings of\n> Documentation/git.txt; either generate the section headings from\n> this file, or generate this file from the section headings.\n\nI'll look at it.\n\nThanks for the review.\n\nSanti\n"}]}