git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Sébastien Guimmara <sebastien.guimmara@gmail.com>
Date
May 8, 2015, 21:08 UTC
Message-ID
<554D25B1.8050605@gmail.com>
In-Reply-To
<CAPig+cS=u-HK1qNicWiLOQC6RPkR7QueX+kOu8fQwpHekgs1yg@mail.gmail.com>
On 05/06/2015 05:16 AM, Eric Sunshine wrote:
Show 22 quoted lines
> On Mon, May 4, 2015 at 4:28 PM, Sébastien Guimmara
>> +
>> +       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);
>
>> +}
Your version raises:
help.c: In function ‘cmd_group_cmp’:
help.c:223:28: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default]
   struct cmdname_help *e1 = elem1;
                             ^
help.c:224:28: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default]
   struct cmdname_help *e2 = elem2;
                             ^
With the cast:
struct cmdname_help *e1 = (struct cmdname_help*)elem1;
It compiles without a warning (gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2)
Show 35 quoted lines
>> +
>>   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
>
Previous: Sébastien GuimmaraNext: Stefan Beller
Message 19 of 38 in “git help: group common commands by theme”
  1. 0/3 git help: group common commands by themeSébastien Guimmara, May 4, 2015
  2. 1/3 command-list.txt: group common commands by themeSébastien Guimmara, May 4, 2015
  3. Eric SunshineMay 6, 2015
  4. Sébastien GuimmaraMay 6, 2015
  5. Eric SunshineMay 7, 2015
  6. Johannes SixtMay 7, 2015
  7. Johannes SchindelinMay 8, 2015
  8. Andreas SchwabMay 8, 2015
  9. Johannes SchindelinMay 8, 2015
  10. Sébastien GuimmaraMay 8, 2015
  11. Eric SunshineMay 8, 2015
  12. 2/3 generate-cmdlist.sh: parse common group commandsSébastien Guimmara, May 4, 2015
  13. Eric SunshineMay 8, 2015
  14. Eric SunshineMay 8, 2015
  15. Sébastien GuimmaraMay 8, 2015
  16. 3/3 git help: group common commands by themeSébastien Guimmara, May 4, 2015
  17. Eric SunshineMay 6, 2015
  18. Sébastien GuimmaraMay 6, 2015
  19. Sébastien GuimmaraMay 8, 2015
  20. Stefan BellerMay 8, 2015
  21. Eric SunshineMay 8, 2015
  22. Sébastien GuimmaraMay 8, 2015
  23. Eric SunshineMay 6, 2015
  24. Sébastien GuimmaraMay 6, 2015
  25. Eric SunshineMay 6, 2015
  26. Junio C HamanoMay 6, 2015
  27. Sébastien GuimmaraMay 8, 2015
  28. Junio C HamanoMay 8, 2015
  29. Matthieu MoyMay 6, 2015
  30. Junio C HamanoMay 6, 2015
  31. Matthieu MoyMay 7, 2015
  32. Junio C HamanoMay 7, 2015
  33. Matthieu MoyMay 8, 2015
  34. Junio C HamanoMay 8, 2015
  35. Emma Jane Hogbin WestbyMay 7, 2015
  36. Sébastien GuimmaraMay 8, 2015
  37. Junio C HamanoMay 8, 2015
  38. Sébastien GuimmaraMay 8, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.