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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jacob Keller <jacob.e.keller@xxxxxxxxx> writes:

> From: Jacob Keller <jacob.keller@xxxxxxxxx>
>
> 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@xxxxxxxxx>
> Cc: Johan Herland <johan@xxxxxxxxxxx>
> Cc: Michael Haggerty <mhagger@xxxxxxxxxxxx>
> Cc: Eric Sunshine <sunshine@xxxxxxxxxxxxxx>
> ---

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.

> +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.

>  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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]