Thread (25 messages) 25 messages, 6 authors, 2016-06-15

[PATCH 3/3] git help: group common commands by theme

flat view
STALE3773d SUPERSEDED

From: Sébastien Guimmara <hidden>
Date: 2016-06-15 23:04:38
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v1 of 4 in this series.

Revisions (4)
  1. v1 current
  2. v5 [diff vs current]
  3. v1
  4. v7 [diff vs current]
'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
      [...]

Helped-by: Junio C Hamano [off-list ref]
Helped-by: Eric Sunshine [off-list ref]
Signed-off-by: Sébastien Guimmara <redacted>
---
 help.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
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;
+
+	if (group1 == group2)
+		return 0;
+	if (group1 > group2)
+		return 1;
+	else
+		return -1;
+}
+
 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]));
+		}
+
+		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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help