From: Eric Sunshine Date: Wed, 25 Apr 2018 18:16:04 GMT Subject: Re: [PATCH v4/wip 08/12] git: support --list-cmds= Message-ID: In-Reply-To: <20180425163107.10399-9-pclouds@gmail.com> On Wed, Apr 25, 2018 at 12:31 PM, Nguyễn Thái Ngọc Duy wrote: > This allows us to select any group of commands by a category defined > in command-list.txt. This is an internal/hidden option so we don't > have to be picky about the category name or worried about exposing too > much. > > This will be used later by git-completion.bash to retrieve certain > command groups. > > Signed-off-by: Nguyễn Thái Ngọc Duy > --- > diff --git a/help.c b/help.c > @@ -305,6 +305,25 @@ void list_all_cmds(void) > +void list_cmds_by_category(const char *cat) > +{ > + int i; > + int cat_id = 0; Should 'cat_id' be unsigned... > + > + for (i = 0; category_names[i]; i++) { > + if (!strcmp(cat, category_names[i])) { > + cat_id = 1 << i; ...since you're shifting it here? > + break; > + } > + } > + if (!cat_id) > + die("unsupported command listing type '%s'", cat); > + > + for (i = 0; command_list[i].name; i++) > + if (command_list[i].category & cat_id) > + puts(command_list[i].name); > +}