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

Re: [PATCH v3 3/4] notes: add notes.merge option to select default strategy

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 5, 2015, 20:47 UTC
Message-ID
<xmqqegjh31js.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1438510226-1163-4-git-send-email-jacob.e.keller@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 14 quoted lines
> From: Jacob Keller <jacob.keller@gmail.com>
>
> Teach git-notes about a new configuration option "notes.merge" for
> selecting the default notes merge strategy. Document the option in
> config.txt and git-notes.txt
>
> Add tests for use of the configuration option. Include a test to ensure
> that --strategy correctly overrides the configured setting.
>
> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
> Cc: Johan Herland <johan@herland.net>
> Cc: Michael Haggerty <mhagger@alum.mit.edu>
> Cc: Eric Sunshine <sunshine@sunshineco.com>
> ---

Perhaps I am biased because we do not usually use Cc: around here, but the above looks in a somewhat strange order. Shouldn't your sign-off be at the end?

> +static enum notes_merge_strategy merge_strategy;
OK.
Show 17 quoted lines
> +static int parse_notes_strategy(const char *arg, enum notes_merge_strategy *strategy)
> +{
> +	if (!strcmp(arg, "manual"))
> +		*strategy = NOTES_MERGE_RESOLVE_MANUAL;
> +	else if (!strcmp(arg, "ours"))
> +		*strategy = NOTES_MERGE_RESOLVE_OURS;
> +	else if (!strcmp(arg, "theirs"))
> +		*strategy = NOTES_MERGE_RESOLVE_THEIRS;
> +	else if (!strcmp(arg, "union"))
> +		*strategy = NOTES_MERGE_RESOLVE_UNION;
> +	else if (!strcmp(arg, "cat_sort_uniq"))
> +		*strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
> +	else
> +		return -1;
> +
> +	return 0;
> +}
OK.
Show 29 quoted lines
>  static int merge(int argc, const char **argv, const char *prefix)
>  {
>  	struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
> @@ -795,23 +815,13 @@ static int merge(int argc, const char **argv, const char *prefix)
>  	expand_notes_ref(&remote_ref);
>  	o.remote_ref = remote_ref.buf;
>  
> -	if (strategy) {
> -		if (!strcmp(strategy, "manual"))
> -			o.strategy = NOTES_MERGE_RESOLVE_MANUAL;
> -		else if (!strcmp(strategy, "ours"))
> -			o.strategy = NOTES_MERGE_RESOLVE_OURS;
> -		else if (!strcmp(strategy, "theirs"))
> -			o.strategy = NOTES_MERGE_RESOLVE_THEIRS;
> -		else if (!strcmp(strategy, "union"))
> -			o.strategy = NOTES_MERGE_RESOLVE_UNION;
> -		else if (!strcmp(strategy, "cat_sort_uniq"))
> -			o.strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
> -		else {
> -			error("Unknown -s/--strategy: %s", strategy);
> -			usage_with_options(git_notes_merge_usage, options);
> -		}
> +	if (strategy && parse_notes_strategy(strategy, &merge_strategy)) {
> +		error("Unknown -s/--strategy: %s", strategy);
> +		usage_with_options(git_notes_merge_usage, options);
>  	}
>  
> +	o.strategy = merge_strategy;
> +

This may be a minor taste thing, but initializing "o.strategy" with merge_strategy at the same place as "o.remote_ref" is initialized, and then passing &o.merge_strategy to parse_notes_strategy(), may be easier to follow.

Renaming the global "merge_strategy" to "configured_merge_strategy" might make it even easier to follow. If anybody uses the variable instead of o.strategy after this point, it would be immediately obvious that it is either a bug or it is deliberately using the value from the configuration file, not command line.

Thanks.
Previous: Jacob KellerNext: Eric Sunshine
Message 5 of 8 in “notes: add support for notes.merge option”
  1. 0/4 notes: add support for notes.merge optionJacob Keller, Aug 2, 2015
  2. 1/4 notes: document cat_sort_uniq rewriteModeJacob Keller, Aug 2, 2015
  3. 2/4 notes: add tests for --commit/--abort/--strategy exclusivityJacob Keller, Aug 2, 2015
  4. 3/4 notes: add notes.merge option to select default strategyJacob Keller, Aug 2, 2015
  5. Junio C HamanoAug 5, 2015
  6. Eric SunshineAug 6, 2015
  7. 4/4 notes: add per-ref configuration of merge strategyJacob Keller, Aug 2, 2015
  8. Junio C HamanoAug 5, 2015

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.