Thread (14 messages) flat view 14 messages, 2 authors, 2016-06-15
STALE3740d

Revision v5 of 4 in this series.

Revisions (4)
  1. v1 [diff vs current]
  2. v5 current
  3. v1 [diff vs current]
  4. v7 [diff vs current]

[PATCH v5 2/6] help.c: output the typical Git workflow

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

'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:

The typical Git workflow includes:

   * 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 [off-list ref]
Signed-off-by: Sébastien Guimmara <redacted>
---
 help.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/help.c b/help.c
index 2072a87..1df205f 100644
--- a/help.c
+++ b/help.c
@@ -218,6 +218,18 @@ void list_commands(unsigned int colopts,
 	}
 }
 
+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;
@@ -227,9 +239,18 @@ void list_common_cmds_help(void)
 			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(_("The typical Git workflow includes:"));
+
 	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