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

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

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Jul 26, 2008, 15:25 UTC
Message-ID
<20080726152502.GL32057@genesis.frugalware.org>
In-Reply-To
<alpine.DEB.1.00.0807261701520.26810@eeepc-johanness>
On Sat, Jul 26, 2008 at 05:08:11PM +0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 6 quoted lines
> > +		memset(&not_strategies, 0, sizeof(struct cmdnames));
> > +		for (i = 0; i < main_cmds.cnt; i++) {
> 
> Looking through all the discovered git commands?  Cute...  But does that 
> not exclude the commands that are in PATH, starting with git-merge-, even 
> if they are custom strategies?

main_cmds contains only commands in /usr/libexec/git-core, while I guess custom strategies are elsewhere in PATH, which commands are in other_cmds, not in main_cmds.

Sample output at me:

$ git merge -s theirss c2 HEAD is now at 1f5e3cc c1 Could not find merge strategy 'theirss'.

available strategies in '/usr/libexec/git-core/'
--------------------------------------------------
  octopus     ours        recursive   resolve     subtree
strategies available from elsewhere on your $PATH
---------------------------------------------------
  theirs
and I have git-merge-theirs in ~/bin (which is in PATH).
Show 10 quoted lines
> 
> > +			int j, found = 0;
> > +			for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
> > +				if (!strcmp(main_cmds.names[i]->name, all_strategy[j].name))
> > +					found = 1;
> > +			if (!found)
> > +				add_cmdname(&not_strategies, main_cmds.names[i]->name, strlen(main_cmds.names[i]->name));
> 
> Better have a local variable "name" instead of writing out 
> "main_cmds.names[i]->name" all the time...
Fixed.
> Oh, and you assume that the names are NUL-terminated (which I assume is 
> not the case in general, as the len member is the only thing that makes 
> struct cmdnames different from struct string_list.

I think the purpose of it is different, but the argument is still valie. That len member is to be able to have ->name contain "foo.exe" while having len at 3, so that git help -a will avoid the .exe suffixes.

Changed.

(I do not want to resend a full series yet, but I pushed out an amended patch to repo.or.cz in the 'merge-custom' branch.)

diff --git a/builtin-merge.c b/builtin-merge.c
index 4084e07..b0d1de5 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -93,11 +93,12 @@ static struct strategy *get_strategy(const char *name)
 		memset(&not_strategies, 0, sizeof(struct cmdnames));
 		for (i = 0; i < main_cmds.cnt; i++) {
 			int j, found = 0;
+			char *ent = main_cmds.names[i];
 			for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
-				if (!strcmp(main_cmds.names[i]->name, all_strategy[j].name))
+				if (!strncmp(ent->name, all_strategy[j].name, ent->len))
 					found = 1;
 			if (!found)
-				add_cmdname(&not_strategies, main_cmds.names[i]->name, strlen(main_cmds.names[i]->name));
+				add_cmdname(&not_strategies, ent->name, ent->len);
 		}
 		fprintf(stderr, "Could not find merge strategy '%s'.\n\n", name);
 		list_commands("git-merge-", "strategies", &not_strategies);
Previous: Johannes SchindelinNext: Miklos Vajna
Message 11 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.