git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Modifies the default git help message to be grouped by topic

From
Jeff King <peff@peff.net>
Date
Dec 2, 2008, 17:20 UTC
Message-ID
<20081202172025.GB15826@coredump.intra.peff.net>
In-Reply-To
<20081202060509.GA48796@agadorsparticus>
On Mon, Dec 01, 2008 at 10:05:09PM -0800, Scott Chacon wrote:
Show 7 quoted lines
> -     sed -n '
> -     /NAME/,/git-'"$cmd"'/H
> -     ${
> -            x
> -            s/.*git-'"$cmd"' - \(.*\)/  {"'"$cmd"'", "\1"},/
> -	    p
> -     }' "Documentation/git-$cmd.txt"

Sorry to reverse direction after you resubmitted, but my earlier comment on "this list shouldn't change frequently" didn't take into account that the _synopsis_ might change, which is much more likely. So maybe rather than ditching the auto-generation, it makes sense to just hardcode the order and categorization, but pull the rest from autogeneration.

Something like the patch below (though it makes the 'common' tag in command-list.txt somewhat redundant, so we should probably just remove that):

diff --git a/builtin-help.c b/builtin-help.c
index f076efa..b5eafb7 100644
--- a/builtin-help.c
+++ b/builtin-help.c
@@ -275,6 +275,15 @@ static int git_help_config(const char *var, const char *value, void *cb)
 
 static struct cmdnames main_cmds, other_cmds;
 
+static const char *find_cmdname_help(const char *name)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(common_cmds); i++)
+		if (!strcmp(common_cmds[i].name, name))
+			return common_cmds[i].help;
+	return "";
+}
+
 void list_common_cmds_help(void)
 {
 	int i, longest = 0;
@@ -285,11 +294,43 @@ void list_common_cmds_help(void)
 	}
 
 	puts("The most commonly used git commands are:");
-	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
-		printf("   %s   ", common_cmds[i].name);
-		mput_char(' ', longest - strlen(common_cmds[i].name));
-		puts(common_cmds[i].help);
-	}
+
+#define COMMON(x) \
+do { \
+	printf("   %s   ", x); \
+	mput_char(' ', longest - strlen(x)); \
+	puts(find_cmdname_help(x)); \
+} while(0)
+
+	puts("Basic Commands");
+	COMMON("init");
+	COMMON("add");
+	COMMON("status");
+	COMMON("commit");
+	puts("");
+
+	puts("History Commands");
+	COMMON("log");
+	COMMON("diff");
+	COMMON("reset");
+	COMMON("show");
+	puts("");
+
+	puts("Branch Commands");
+	COMMON("checkout");
+	COMMON("branch");
+	COMMON("merge");
+	COMMON("rebase");
+	COMMON("tag");
+	puts("");
+
+	puts("Remote Commands");
+	COMMON("clone");
+	COMMON("fetch");
+	COMMON("pull");
+	COMMON("push");
+
+#undef COMMON
 }
 
 static int is_git_command(const char *s)
Previous: Scott ChaconNext: Jeff King
Message 2 of 3 in “Modifies the default git help message to be grouped by topic”
  1. Modifies the default git help message to be grouped by topicScott Chacon, Dec 2, 2008
  2. Jeff KingDec 2, 2008
  3. Jeff KingDec 2, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.