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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/06/2015 05:16 AM, Eric Sunshine wrote:
On Mon, May 4, 2015 at 4:28 PM, Sébastien Guimmara
<sebastien.guimmara@xxxxxxxxx> 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...

---
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);


Hmmm yes. Good idea.

+}
+
  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.

Understood.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]