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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 01, 2008 at 10:05:09PM -0800, Scott Chacon wrote:

> -     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)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux