Re: [PATCH] bash-completion: fix getting strategy list

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] bash-completion: fix getting strategy list

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:12

Junio C Hamano [off-list ref] writes:
"Mikael Magnusson" [off-list ref] writes:
quoted
I don't know if i somehow have some weird patch merged in, i tried to check
and didn't find anything, at least. But when i run git merge -s help i get:
Yes, there are some weird patch in 'next'.  Miklos, could you fix the
output format of that thing?
I do not think the code in 'next' that reuses the "help" thing to show
only the list to stdout while still giving the error message to stderr
makes any sense.

Let's do this.

---

 builtin-merge.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
diff --git c/builtin-merge.c w/builtin-merge.c
index 1f9389b..3e8db0d 100644
--- c/builtin-merge.c
+++ w/builtin-merge.c
@@ -110,9 +110,17 @@ static struct strategy *get_strategy(const char *name)
 		}
 	}
 	if (!is_in_cmdlist(&main_cmds, name) && !is_in_cmdlist(&other_cmds, name)) {
-
-		fprintf(stderr, "Could not find merge strategy '%s'.\n\n", name);
-		list_commands("strategies", longest, &main_cmds, &other_cmds);
+		fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
+		fprintf(stderr, "Available strategies are:");
+		for (i = 0; i < main_cmds.cnt; i++)
+			fprintf(stderr, " %s", main_cmds.names[i]->name);
+		fprintf(stderr, ".\n");
+		if (other_cmds.cnt) {
+			fprintf(stderr, "Available custom strategies are:");
+			for (i = 0; i < other_cmds.cnt; i++)
+				fprintf(stderr, " %s", other_cmds.names[i]->name);
+			fprintf(stderr, ".\n");
+		}
 		exit(1);
 	}
 

Re: [PATCH] bash-completion: fix getting strategy list

From: Miklos Vajna <hidden>
Date: 2016-06-15 22:45:12

On Wed, Aug 20, 2008 at 10:07:55PM -0700, Junio C Hamano [off-list ref] wrote:
quoted
Yes, there are some weird patch in 'next'.  Miklos, could you fix the
output format of that thing?
You were faster. ;-)
quoted hunk
I do not think the code in 'next' that reuses the "help" thing to show
only the list to stdout while still giving the error message to stderr
makes any sense.

Let's do this.

---

 builtin-merge.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
diff --git c/builtin-merge.c w/builtin-merge.c
index 1f9389b..3e8db0d 100644
--- c/builtin-merge.c
+++ w/builtin-merge.c
@@ -110,9 +110,17 @@ static struct strategy *get_strategy(const char *name)
 		}
 	}
 	if (!is_in_cmdlist(&main_cmds, name) && !is_in_cmdlist(&other_cmds, name)) {
-
-		fprintf(stderr, "Could not find merge strategy '%s'.\n\n", name);
-		list_commands("strategies", longest, &main_cmds, &other_cmds);
+		fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
+		fprintf(stderr, "Available strategies are:");
+		for (i = 0; i < main_cmds.cnt; i++)
+			fprintf(stderr, " %s", main_cmds.names[i]->name);
+		fprintf(stderr, ".\n");
+		if (other_cmds.cnt) {
+			fprintf(stderr, "Available custom strategies are:");
+			for (i = 0; i < other_cmds.cnt; i++)
+				fprintf(stderr, " %s", other_cmds.names[i]->name);
+			fprintf(stderr, ".\n");
+		}
 		exit(1);
 	}
Given that we don't have 100+ merge strategies like we have 100+ git
commands, I think printing them in one line should not be problematic,
and this definitely improves script usability, so I like it, thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help