From: Eric Sunshine <sunshine@sunshineco.com>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: Git List <git@vger.kernel.org>, Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH 2/2] notes: add notes.merge option to select default strategy
Date: Fri, 31 Jul 2015 17:12:53 -0400 [thread overview]
Message-ID: <CAPig+cT+-d25NeXaNXP6rk8WPEtHJB7dobme72aLF1JL8y9mVg@mail.gmail.com> (raw)
In-Reply-To: <1438370496-26433-3-git-send-email-jacob.e.keller@intel.com>
On Fri, Jul 31, 2015 at 3:21 PM, Jacob Keller <jacob.e.keller@intel.com> wrote:
> 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 the configuration option. Ensure that command line
> --strategy option overrides the configured value. Ensure that -s can't
> be passed with --commit or --abort. Ensure that --abort and --commit
> can't be used together.
>
> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
> ---
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 88fdafb32bc0..7123311b563e 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -741,6 +744,36 @@ static int merge_commit(struct notes_merge_options *o)
> +static int parse_notes_strategy(const char *var, const char *arg,
> + enum notes_merge_strategy *strategy)
What is the 'var' argument for? It's not used by the function.
> +{
> + 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 error("Unknown notes merge strategy: %s", arg);
Perhaps reporting of the error should be left to the callers so they
can tailor the message ("--strategy" vs. "notes.merge")? Doing so
would make it easier for the user to trace the source of a bogus
value.
> + }
> +
> + return 0;
> +}
> +
> +static int parse_opt_strategy(const struct option *opt, const char *arg, int unset)
> +{
> + enum notes_merge_strategy *strategy = opt->value;
> +
> + /* let merge() know we overrode the configured strategy */
> + override_strategy = 1;
> +
> + return parse_notes_strategy(NULL, arg, strategy);
> +}
> +
> static int merge(int argc, const char **argv, const char *prefix)
> {
> struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
> @@ -749,14 +782,16 @@ static int merge(int argc, const char **argv, const char *prefix)
> - const char *strategy = NULL;
> struct option options[] = {
> OPT_GROUP(N_("General options")),
> OPT__VERBOSITY(&verbosity),
> OPT_GROUP(N_("Merge options")),
> - OPT_STRING('s', "strategy", &strategy, N_("strategy"),
> - N_("resolve notes conflicts using the given strategy "
> - "(manual/ours/theirs/union/cat_sort_uniq)")),
> + {
> + OPTION_CALLBACK, 's', "strategy", &strategy, N_("strategy"),
> + N_("resolve notes conflicts using the given strategy "
> + "(manual/ours/theirs/union/cat_sort_uniq)"),
> + PARSE_OPT_NONEG, parse_opt_strategy
> + },
Why change this from an OPT_STRING to an OPTION_CALLBACK? Couldn't you
just as easily have called parse_notes_strategy() after
parse_options()?
> OPT_GROUP(N_("Committing unmerged notes")),
> { OPTION_SET_INT, 0, "commit", &do_commit, NULL,
> N_("finalize notes merge by committing unmerged notes"),
> @@ -771,7 +806,7 @@ static int merge(int argc, const char **argv, const char *prefix)
> argc = parse_options(argc, argv, prefix, options,
> git_notes_merge_usage, 0);
>
> - if (strategy || do_commit + do_abort == 0)
> + if (override_strategy || do_commit + do_abort == 0)
> do_merge = 1;
> if (do_merge + do_commit + do_abort != 1) {
> error("cannot mix --commit, --abort or -s/--strategy");
> @@ -799,22 +834,7 @@ 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);
> - }
> - }
> + o.strategy = strategy;
next prev parent reply other threads:[~2015-07-31 21:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-31 19:21 [PATCH 0/2] add notes.merge configuration variable Jacob Keller
2015-07-31 19:21 ` [PATCH 1/2] notes: document cat_sort_uniq rewriteMode Jacob Keller
2015-07-31 19:21 ` [PATCH 2/2] notes: add notes.merge option to select default strategy Jacob Keller
2015-07-31 21:12 ` Eric Sunshine [this message]
2015-07-31 20:00 ` [PATCH 0/2] add notes.merge configuration variable Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPig+cT+-d25NeXaNXP6rk8WPEtHJB7dobme72aLF1JL8y9mVg@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jacob.keller@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).