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.