Re: [PATCH 3/3] git help: group common commands by theme
From: Stefan Beller <hidden>
Date: 2016-06-15 23:04:42
On Fri, May 8, 2015 at 2:08 PM, Sébastien Guimmara [off-list ref] wrote:
On 05/06/2015 05:16 AM, Eric Sunshine wrote:quoted
On Mon, May 4, 2015 at 4:28 PM, Sébastien Guimmaraquoted
+ + 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);quoted
+}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)
I'd rather change the type of struct cmdname_help to be const, such
that it reads:
const struct cmdname_help *e1 = elem1;
const 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);
instead of casting if possible.