Re: [PATCH 3/3] git help: group common commands by theme
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 6, 2015, 03:16 UTC
- Message-ID
- <CAPig+cS=u-HK1qNicWiLOQC6RPkR7QueX+kOu8fQwpHekgs1yg@mail.gmail.com>
- In-Reply-To
- <13c3dcbd2c5c9dfc0453381b5da53b5d68af7afe.1430770308.git.sebastien.guimmara@gmail.com>
On Mon, May 4, 2015 at 4:28 PM, Sébastien Guimmara <sebastien.guimmara@gmail.com> wrote:
Show 25 quoted lines
> '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...
Show 15 quoted lines
> ---
> 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
Show 7 quoted lines
> + > + 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);Show 22 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.
Show 6 quoted lines
> + printf(" %s ", common_cmds[i].name);
> mput_char(' ', longest - strlen(common_cmds[i].name));
> puts(_(common_cmds[i].help));
> }
> --
> 2.4.0