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

[PATCH 2/5] builtin-help: make list_commands() a bit more generic

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Jul 29, 2008, 15:25 UTC
Message-ID
<5a003a0e20d0942c946680e4eade8e9d19f0036b.1217344803.git.vmiklos@frugalware.org>
In-Reply-To
<fd19583955e9cea5b78a465d23bc127a51940048.1217344803.git.vmiklos@frugalware.org>

That function now takes two paramters to control the prefix of the listed commands, and a second parameter to specify the title of the table. This can be useful for listing not only all git commands, but specific ones, like merge strategies.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 help.c |   18 ++++++++++--------
 help.h |    1 +
 2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/help.c b/help.c
index 08188f5..7a42517 100644
--- a/help.c
+++ b/help.c
@@ -506,23 +506,25 @@ static unsigned int load_command_list(const char *prefix)
 	return longest;
 }
 
-static void list_commands(void)
+void list_commands(const char *prefix, const char *title)
 {
-	unsigned int longest = load_command_list(NULL);
+	unsigned int longest = load_command_list(prefix);
 	const char *exec_path = git_exec_path();
 
 	if (main_cmds.cnt) {
-		printf("available git commands in '%s'\n", exec_path);
-		printf("----------------------------");
-		mput_char('-', strlen(exec_path));
+		printf("available %s in '%s'\n", title, exec_path);
+		printf("----------------");
+		mput_char('-', strlen(title) + strlen(exec_path));
 		putchar('\n');
 		pretty_print_string_list(&main_cmds, longest);
 		putchar('\n');
 	}
 
 	if (other_cmds.cnt) {
-		printf("git commands available from elsewhere on your $PATH\n");
-		printf("---------------------------------------------------\n");
+		printf("%s available from elsewhere on your $PATH\n", title);
+		printf("---------------------------------------");
+		mput_char('-', strlen(title));
+		putchar('\n');
 		pretty_print_string_list(&other_cmds, longest);
 		putchar('\n');
 	}
@@ -702,7 +704,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 
 	if (show_all) {
 		printf("usage: %s\n\n", git_usage_string);
-		list_commands();
+		list_commands("git-", "git commands");
 		printf("%s\n", git_more_info_string);
 		return 0;
 	}
diff --git a/help.h b/help.h
index 73da8d6..0741662 100644
--- a/help.h
+++ b/help.h
@@ -2,5 +2,6 @@
 #define HELP_H
 
 int is_git_command(const char *s, const char *prefix);
+void list_commands(const char *prefix, const char *title);
 
 #endif /* HELP_H */
-- 
1.6.0.rc0.14.g95f8.dirty
Previous: Miklos VajnaNext: Miklos Vajna
Message 3 of 9 in “Allow custom merge strategies, take 3”
  1. 0/5 Allow custom merge strategies, take 3Miklos Vajna, Jul 29, 2008
  2. 1/5 builtin-help: make is_git_command() usable outside builtin-helpMiklos Vajna, Jul 29, 2008
  3. 2/5 builtin-help: make list_commands() a bit more genericMiklos Vajna, Jul 29, 2008
  4. 3/5 builtin-help: make it possible to exclude some commands in list_commands()Miklos Vajna, Jul 29, 2008
  5. 4/5 builtin-merge: allow using a custom strategyMiklos Vajna, Jul 29, 2008
  6. 5/5 Add a new test for using a custom merge strategyMiklos Vajna, Jul 29, 2008
  7. Junio C HamanoJul 29, 2008
  8. Junio C HamanoJul 29, 2008
  9. 3/5 builtin-help: make it possible to exclude some commands in list_commands()Miklos Vajna, Jul 29, 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.