git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Sébastien Guimmara" <sebastien.guimmara@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH v2 3/3] git help: group common commands by theme
Date: Sat, 02 May 2015 01:12:18 +0200	[thread overview]
Message-ID: <55440852.4000500@gmail.com> (raw)
In-Reply-To: <554405D5.9080702@gmail.com>

help.c - group common commands by theme

Use qsort to sort the common_cmds array by group name,
then print those common commands, skipping a line between each group.

Signed-off-by: Sébastien Guimmara <sebastien.guimmara@gmail.com>

---
  help.c | 21 +++++++++++++++++++++
  1 file changed, 21 insertions(+)

diff --git a/help.c b/help.c
index 2072a87..2169a59 100644
--- a/help.c
+++ b/help.c
@@ -218,17 +218,38 @@ void list_commands(unsigned int colopts,
      }
  }

+/* sort the command name struct by group name */
+int cmd_group_cmp(const void *elem1, const void *elem2)
+{
+    struct cmdname_help *cmd1 = (struct cmdname_help*) elem1;
+    struct cmdname_help *cmd2 = (struct cmdname_help*) elem2;
+
+    return strcmp(cmd1->group, cmd2->group);
+}
+
  void list_common_cmds_help(void)
  {
      int i, longest = 0;
+    char *current_grp = NULL;

      for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
          if (longest < strlen(common_cmds[i].name))
              longest = strlen(common_cmds[i].name);
      }

+    /* sort common commands by group (i.e, beginner's relevance) */
+    qsort(common_cmds, ARRAY_SIZE(common_cmds),
+        sizeof(struct cmdname_help), cmd_group_cmp);
+
      puts(_("The most commonly used git commands are:"));
      for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
+
+        /* skip a line each time we encounter a new command group */
+        if (current_grp != NULL && strcmp(common_cmds[i].group, 
current_grp))
+            printf("\n");
+
+        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));
-- 
2.4.0

  parent reply	other threads:[~2015-05-01 23:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-01 23:01 [PATCH v2 1/3] git help: group common commands by theme Sébastien Guimmara
2015-05-01 23:06 ` [PATCH v2 2/3] " Sébastien Guimmara
2015-05-02  6:32   ` Luke Diamand
2015-05-02 11:09     ` Sébastien Guimmara
2015-05-02 11:43     ` Andreas Schwab
2015-05-02 11:52       ` Sébastien Guimmara
2015-05-02 14:18       ` Sébastien Guimmara
2015-05-01 23:12 ` Sébastien Guimmara [this message]
2015-05-03  0:19 ` [PATCH v3 0/4] git help: group common commands by themes Sébastien Guimmara
2015-05-03  0:21   ` [PATCH v3 1/4] command-list.txt: " Sébastien Guimmara
2015-05-03  0:22   ` [PATCH v3 2/4] generate-cmdlist.sh: parse common command groups Sébastien Guimmara
2015-05-03 17:55     ` Junio C Hamano
2015-05-03 20:40       ` Eric Sunshine
2015-05-03 20:53         ` Sébastien Guimmara
2015-05-03 21:10           ` Eric Sunshine
2015-05-03 19:18     ` Eric Sunshine
2015-05-03 20:10       ` Eric Sunshine
2015-05-03  0:23   ` [PATCH v3 3/4] help.c - group common commands by theme Sébastien Guimmara
2015-05-03 19:44     ` Eric Sunshine
2015-05-03  0:24   ` [PATCH v3 4/4] api-builtin.txt: explain common command groups Sébastien Guimmara
2015-05-03 20:02     ` Eric Sunshine
2015-05-03 20:59       ` Sébastien Guimmara
2015-05-03 21:13         ` Eric Sunshine
     [not found]         ` <CAHYJk3S3s4RjFMUaomP2wUVBbcTLRGYrAOa-uDjrfsKqUuWPog@mail.gmail.com>
2015-05-03 22:32           ` Sébastien Guimmara
2015-05-03  2:23 ` [PATCH v2 1/3] git help: group common commands by theme Junio C Hamano
2015-05-03 13:54   ` Sébastien Guimmara
2015-05-03 13:57     ` Sébastien Guimmara
2015-05-03 17:16     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55440852.4000500@gmail.com \
    --to=sebastien.guimmara@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).