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

[PATCH] builtin-merge: avoid non-strategy git-merge commands in error message

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Jul 26, 2008, 17:12 UTC
Message-ID
<1217092367-29114-1-git-send-email-vmiklos@frugalware.org>
In-Reply-To
<alpine.DEB.1.00.0807261900180.26810@eeepc-johanness>

If an invalid strategy is supplied, like -s foobar, then git-merge listed all git-merge-* commands. This is not perfect, since for example git-merge-index is not a valid strategy.

These are now removed from the output by scanning the list of main commands; if the git-merge-foo command is listed in the all_strategy list, then it's shown, otherwise excluded. This does not exclude commands somewhere else in the PATH, where custom strategies are expected.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Sat, Jul 26, 2008 at 07:01:16PM +0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 11 quoted lines
> > Hmm. So let's say ent->name is "ours.exe", ent->len is set to 4.
> >
> > Then !strncmp(ent->name, all_strategy[j].name, ent->len) will be
> > true,
> > and the command will not be added to the exclude list.
>
> What I meant is: if you change the strcmp to strncmp because one of
> the
> both strings is not supposed to be NUL terminated, you still want to
> make
> sure that one is not a strict prefix of the other.
Aah, I forgot about all_strategy[j].name is NUL terminated.
Updated patch below.
 builtin-merge.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index cdbc692..29826b1 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -88,8 +88,21 @@ static struct strategy *get_strategy(const char *name)
 			return &all_strategy[i];
 
 	if (!is_git_command(name, "git-merge-")) {
+		struct cmdnames not_strategies;
+
+		memset(&not_strategies, 0, sizeof(struct cmdnames));
+		for (i = 0; i < main_cmds.cnt; i++) {
+			int j, found = 0;
+			struct cmdname *ent = main_cmds.names[i];
+			for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
+				if (!strncmp(ent->name, all_strategy[j].name, ent->len)
+						&& !all_strategy[j].name[ent->len])
+					found = 1;
+			if (!found)
+				add_cmdname(&not_strategies, ent->name, ent->len);
+		}
 		fprintf(stderr, "Could not find merge strategy '%s'.\n\n", name);
-		list_commands("git-merge-", "strategies");
+		list_commands("git-merge-", "strategies", &not_strategies);
 		exit(1);
 	}
 
-- 
1.6.0.rc0.14.g95f8.dirty
Previous: Johannes SchindelinNext: Jonathan Nieder
Message 16 of 46 in “Allow custom merge strategies”
  1. 0/7 Allow custom merge strategiesMiklos Vajna, Jul 26, 2008
  2. 1/7 Make is_git_command() usable outside builtin-helpMiklos Vajna, Jul 26, 2008
  3. t7601: extend the 'merge picks up the best result' testMiklos Vajna, Jul 26, 2008
  4. 2/7 builtin-help: change the current directory back in list_commands_in_dir()Miklos Vajna, Jul 26, 2008
  5. 3/7 builtin-help: make list_commands() a bit more genericMiklos Vajna, Jul 26, 2008
  6. 4/7 builtin-merge: allow using a custom strategyMiklos Vajna, Jul 26, 2008
  7. 5/7 Add a new test for using a custom merge strategyMiklos Vajna, Jul 26, 2008
  8. 6/7 builtin-help: make it possible to exclude some commands in list_commands()Miklos Vajna, Jul 26, 2008
  9. 7/7 builtin-merge: avoid non-strategy git-merge commands in error messageMiklos Vajna, Jul 26, 2008
  10. Johannes SchindelinJul 26, 2008
  11. Miklos VajnaJul 26, 2008
  12. 7/7 builtin-merge: avoid non-strategy git-merge commands in error messageMiklos Vajna, Jul 26, 2008
  13. Johannes SchindelinJul 26, 2008
  14. Miklos VajnaJul 26, 2008
  15. Johannes SchindelinJul 26, 2008
  16. builtin-merge: avoid non-strategy git-merge commands in error messageMiklos Vajna, Jul 26, 2008
  17. Jonathan NiederJul 26, 2008
  18. 3/7 builtin-help: make list_commands() a bit more genericMiklos Vajna, Jul 26, 2008
  19. Johannes SchindelinJul 26, 2008
  20. Junio C HamanoJul 27, 2008
  21. Johannes SchindelinJul 27, 2008
  22. Avoid chdir() in list_commands_in_dir()Johannes Schindelin, Jul 27, 2008
  23. Miklos VajnaJul 26, 2008
  24. Jonathan NiederJul 26, 2008
  25. Miklos VajnaJul 28, 2008
  26. 0/6 Allow custom merge strategies, take 2Miklos Vajna, Jul 28, 2008
  27. 1/6 builtin-help: make is_git_command() usable outside builtin-helpMiklos Vajna, Jul 28, 2008
  28. 2/6 builtin-help: make list_commands() a bit more genericMiklos Vajna, Jul 28, 2008
  29. 3/6 builtin-help: make it possible to exclude some commands in list_commands()Miklos Vajna, Jul 28, 2008
  30. 4/6 builtin-merge: allow using a custom strategyMiklos Vajna, Jul 28, 2008
  31. 5/6 builtin-merge: avoid non-strategy git-merge commands in error messageMiklos Vajna, Jul 28, 2008
  32. 6/6 Add a new test for using a custom merge strategyMiklos Vajna, Jul 28, 2008
  33. Johannes SchindelinJul 28, 2008
  34. 6/6 Add a new test for using a custom merge strategyMiklos Vajna, Jul 28, 2008
  35. Johannes SchindelinJul 28, 2008
  36. Miklos VajnaJul 28, 2008
  37. Miklos VajnaJul 29, 2008
  38. Johannes SchindelinJul 28, 2008
  39. builtin-merge: allow using a custom strategyMiklos Vajna, Jul 28, 2008
  40. Johannes SchindelinJul 28, 2008
  41. Junio C HamanoJul 28, 2008
  42. Johannes SchindelinJul 28, 2008
  43. Junio C HamanoJul 28, 2008
  44. Junio C HamanoJul 28, 2008
  45. Johannes SchindelinJul 28, 2008
  46. 3/6 builtin-help: make it possible to exclude some commands in list_commands()Miklos Vajna, Jul 28, 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.