Thread (25 messages) flat view 25 messages, 6 authors, 2016-06-15

Re: [PATCH 3/3] git help: group common commands by theme

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:04:39

On Mon, May 4, 2015 at 4:28 PM, Sébastien Guimmara
[off-list ref] wrote:
'git help' shows common commands in alphabetical order:

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   [...]

without any indication of how commands relate to high-level
concepts or each other. Revise the output to group commands by
concept, like this:

The most commonly used git commands are:

   * starting a working area:
      clone      Clone a repository into a new directory
      init       Create an empty Git repository or reinitialize an existing one

   * working on the current change:
      add        Add file contents to the index
      reset      Reset current HEAD to the specified state
      [...]
This looks better. A couple minor style nits and a question below...
quoted hunk ↗ jump to hunk
---
diff --git a/help.c b/help.c
index 2072a87..c8b0bb6 100644
--- a/help.c
+++ b/help.c
@@ -218,18 +218,44 @@ void list_commands(unsigned int colopts,
        }
 }

+int cmd_group_cmp(const void *elem1, const void *elem2)
+{
+       int group1, group2;
+
+       group1 = ((struct cmdname_help *) elem1)->group;
+       group2 = ((struct cmdname_help *) elem2)->group;
Style: Drop space after the cast: (type *)var
+
+       if (group1 == group2)
+               return 0;
+       if (group1 > group2)
+               return 1;
+       else
+               return -1;
Do you also want to sort the commands alphabetically within group?
That is, something like this?

    struct cmdname_help *e1 = elem1;
    struct cmdname_help *e2 = elem2;

    if (e1->group < e2->group)
        return -1;
    if (e1->group > e2->group)
        return 1;
    return strcmp(e1->name, e2->name);
+}
+
 void list_common_cmds_help(void)
 {
        int i, longest = 0;
+       unsigned char current_grp = -1;

        for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
                if (longest < strlen(common_cmds[i].name))
                        longest = strlen(common_cmds[i].name);
        }

+       qsort(common_cmds, ARRAY_SIZE(common_cmds),
+               sizeof(common_cmds[0]), cmd_group_cmp);
+
        puts(_("The most commonly used git commands are:"));
+
        for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
-               printf("   %s   ", common_cmds[i].name);
+               if (common_cmds[i].group != current_grp) {
+                       printf("\n   * %s:\n", _(common_cmd_groups[common_cmds[i].group]));
+               }
Style: Drop unnecessary braces.
+               current_grp = common_cmds[i].group;
Alternately, move this assignment inside the braces.
+               printf("      %s   ", common_cmds[i].name);
                mput_char(' ', longest - strlen(common_cmds[i].name));
                puts(_(common_cmds[i].help));
        }
--
2.4.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help