Re: [PATCH v4/wip 08/12] git: support --list-cmds=<category>
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 25, 2018, 18:16 UTC
- Message-ID
- <CAPig+cT2FJodBeVO8RO9CqSAFvmcMQbEwyTEsxPBYovA6ivXGQ@mail.gmail.com>
- 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 <pclouds@gmail.com> wrote:
Show 16 quoted lines
> 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 <pclouds@gmail.com>
> ---
> 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?
Show 10 quoted lines
> + 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);
> +}