Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] help: include list of aliases in git-help --all

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:00:00

Joel Nothman [off-list ref] writes:
Git help --all had listed all git commands, but no configured aliases.
This includes aliases as a separate listing, after commands in the main
git directory and other $PATH directories.

Signed-off-by: Joel Nothman <joel.nothman <at> gmail.com>
---
Thanks.
quoted hunk
diff --git a/help.c b/help.c
index df7d16d..3c14af4 100644
--- a/help.c
+++ b/help.c
@@ -86,7 +86,7 @@ static void pretty_print_string_list(struct cmdnames *cmds,
 	int i;
 
 	for (i = 0; i < cmds->cnt; i++)
-		string_list_append(&list, cmds->names[i]->name);
+	    string_list_append(&list, cmds->names[i]->name);
Why?
quoted hunk
@@ -202,8 +202,48 @@ void load_command_list(const char *prefix,
 	exclude_cmds(other_cmds, main_cmds);
 }
 
+static struct cmdnames aliases;
Instead of using a static global variable, perhaps make this an
on-stack variable in load_commands_and_aliases() that is passed as a
callback parameter to load_aliases_cb() thru git_config()?
+static int load_aliases_cb(const char *var, const char *value, void *cb)
+{
That is, cb here is the second parameter you gave to git_config().
quoted hunk
 void list_commands(unsigned int colopts,
-		   struct cmdnames *main_cmds, struct cmdnames *other_cmds)
+		   struct cmdnames *main_cmds, struct cmdnames *other_cmds,
+		   struct cmdnames *alias_cmds)
 {
 	if (main_cmds->cnt) {
 		const char *exec_path = git_exec_path();
@@ -219,6 +259,13 @@ void list_commands(unsigned int colopts,
 		pretty_print_string_list(other_cmds, colopts);
 		putchar('\n');
 	}
+
+	if (alias_cmds->cnt) {
+		printf_ln(_("aliases defined in git configuration"));
This will not break the use of "git help -a" in our completion
script, because it ignores anything that does not begin with two SP
followed by alphanumerics.

It may however break scripts that read from "help -a" done by other
people that may remove the lines in the output that are known to
them as not names of commands (i.e. "available git commands..."  and
"git commands avaliable elsewhere...")---they haven't seen this new
string and would not know that this line must be skipped.

Other than that, looks reasonably cleanly done.  We'd need a test to
cover this so that other people will not break it in future patches.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help