Re: [PATCH v9 5/5] help: respect new common command grouping
- From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
- Date
- May 20, 2015, 21:39 UTC
- Message-ID
- <555CFEF4.5000002@ramsay1.demon.co.uk>
- In-Reply-To
- <1432149781-24596-6-git-send-email-sebastien.guimmara@gmail.com>
On 20/05/15 20:23, Sébastien Guimmara wrote:
Show 33 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 explain their relationship > with the typical Git workflow: > > These are common Git commands used in various situations: > > start a working area (see also: git help tutorial) > clone Clone a repository into a new directory > init Create an empty Git repository or reinitialize [...] > > work on the current change (see also: git help everyday) > add Add file contents to the index > reset Reset current HEAD to the specified state > > examine the history and state (see also: git help revisions) > log Show commit logs > status Show the working tree status > > [...] > > Helped-by: Eric Sunshine <sunshine@sunshineco.com> > Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
This should be (at most) 'Helped-by:' - my 'contribution' was so minor that even a 'Helped-by:' is generous! :-D
ATB, Ramsay Jones
Show 51 quoted lines
> Signed-off-by: Sébastien Guimmara <sebastien.guimmara@gmail.com>
> ---
> help.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/help.c b/help.c
> index 2072a87..8f72051 100644
> --- a/help.c
> +++ b/help.c
> @@ -218,17 +218,39 @@ void list_commands(unsigned int colopts,
> }
> }
>
> +static int cmd_group_cmp(const void *elem1, const void *elem2)
> +{
> + 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);
> +}
> +
> void list_common_cmds_help(void)
> {
> int i, longest = 0;
> + int 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);
> }
>
> - puts(_("The most commonly used git commands are:"));
> + qsort(common_cmds, ARRAY_SIZE(common_cmds),
> + sizeof(common_cmds[0]), cmd_group_cmp);
> +
> + puts(_("These are common Git commands used in various situations:"));
> +
> for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
> + if (common_cmds[i].group != current_grp) {
> + printf("\n%s\n", _(common_cmd_groups[common_cmds[i].group]));
> + current_grp = common_cmds[i].group;
> + }
> +
> printf(" %s ", common_cmds[i].name);
> mput_char(' ', longest - strlen(common_cmds[i].name));
> puts(_(common_cmds[i].help));
>