Re: [PATCH 2/2] notes: add notes.merge option to select default strategy

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

 



On Fri, Jul 31, 2015 at 3:21 PM, Jacob Keller <jacob.e.keller@xxxxxxxxx> 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@xxxxxxxxx>
> ---
> 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;
--
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]