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

Re: [PATCH 4/5] builtin-merge: allow using a custom strategy

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2008, 19:47 UTC
Message-ID
<7v4p68eame.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<722d66a5a897b694f374aa96bd58aff01a2a5932.1217344803.git.vmiklos@frugalware.org>
Miklos Vajna <vmiklos@frugalware.org> writes:
Show 22 quoted lines
> Allow using a custom strategy, as long as it's named git-merge-foo. The
> error handling is now done using is_git_command(). The list of available
> strategies is now shown by list_commands().
>
> If an invalid strategy is supplied, like -s foobar, then git-merge would
> list all git-merge-* commands. This is not perfect, since for example
> git-merge-index is not a valid strategy.
> ...
> +	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);
> +		}

This feels overly wasteful. Granted, this is not a performance critical codepath, but you list all commands that begin with "git-merge-" in is_git_command(), only to discard it and then iterate over 140+ main_cmds list only to cull the ones whose name do not appear in the strategies list.

Perhaps this shows that changing the function is_git_command() is a wrong approach (for one thing, with the custom prefix, it is not about "Is it a git command" anymore). Wouldn't it be easier to read if you did this part like this instead?

 * make load_command_list capable of loading into a "struct cmdnames" (or
   pair if you want) supplied by the caller;
 * use it to grab all commands whose name begin with "git-merge-" here;
 * Check if name appears in that list; if it doesn't, you already have the
   list of commands that could be merge strategy for error reporting.

If you also update list_commands() not to run load_command_list() itself but take caller-supplied list of commands, then the API would become much cleaner. The caller would not be limited to "filter with prefix" anymore.

Hmm?
Previous: Miklos VajnaNext: Junio C Hamano
Message 7 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.