Re: [PATCH v5 1/3] builtin/config: introduce `--default`

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

 



On Fri, Apr 06, 2018 at 02:53:45AM -0400, Eric Sunshine wrote:
> On Fri, Apr 6, 2018 at 2:30 AM, Taylor Blau <me@xxxxxxxxxxxx> wrote:
> > [...]
> > This commit (and those following it in this series) aim to eventually
> > replace `--get-color` with a consistent alternative. By introducing
> > `--default`, we allow the `--get-color` action to be promoted to a
> > `--type=color` type specifier, retaining the "fallback" behavior via the
> > `--default` flag introduced in this commit.
> >
> > For example, we aim to replace:
> >
> >   $ git config --get-color variable [default] [...]
> >
> > with:
> >
> >   $ git config --default default --type=color variable [...]
> >
> > Signed-off-by: Taylor Blau <me@xxxxxxxxxxxx>
> > ---
> > diff --git a/builtin/config.c b/builtin/config.c
> > @@ -286,6 +288,16 @@ static int get_value(const char *key_, const char *regex_)
> > +       if (!values.nr && default_value) {
> > +               struct strbuf *item;
> > +               ALLOC_GROW(values.items, values.nr + 1, values.alloc);
> > +               item = &values.items[values.nr++];
> > +               strbuf_init(item, 0);
> > +               if (format_config(item, key_, default_value) < 0) {
> > +                       die(_("failed to format default config value"));
> > +               }
>
> Unnecessary braces.

Ah, that's leftover from changing this around in your last round of
review. Cleaned up locally.

> Also, an error message such as this is typically more helpful when it
> shows the item which caused the problem:
>
>     die(_("failed to format default config value: %s"), default_value);
>
> However, since the message already says "default", it's pretty easy to
> understand that it's talking about the argument to --default, so it's
> perhaps not such a big deal in this case.
>
> Anyhow, neither point is worth a re-roll.

I like including the value of default_value. I've included it locally,

>
> > +       }
> > @@ -624,6 +636,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
> >                 usage_with_options(builtin_config_usage, builtin_config_options);
> >         }
> >
> > +
>
> Unnecessary new blank line.
>
> > +       if (default_value && !(actions & ACTION_GET)) {
> > +               error("--default is only applicable to --get");
> > +               usage_with_options(builtin_config_usage,
> > +                       builtin_config_options);
> > +       }
> > diff --git a/t/t1310-config-default.sh b/t/t1310-config-default.sh
> > @@ -0,0 +1,38 @@
> > +test_expect_success 'uses --default when missing entry' '
> > +       echo quux >expect &&
> > +       git config -f config --default quux core.foo >actual &&
> > +       test_cmp expect actual
> > +'
> >
> > +test_expect_success 'canonicalizes --default with appropriate type' '
> > +       echo true >expect &&
> > +       git config -f config --default=true --bool core.foo >actual &&
> > +       test_cmp expect actual
> > +'
>
> I would trust this canonicalization test a lot more if it used one of
> the aliases for "true" since it doesn't presently prove that
> canonicalization is taking place. For instance:
>
>     git config -f config --default=yes --bool core.foo >actual &&
>
> > +test_expect_success 'uses entry when available' '
> > +       echo bar >expect &&
> > +       git config --add core.foo bar &&
> > +       git config --default baz core.foo >actual &&
> > +       git config --unset core.foo &&
> > +       test_cmp expect actual
> > +'
>
> If you happen to re-roll, can we move this test so it immediately
> follows the "uses --default when missing entry" test? That's where I
> had expected to find it and had even written a review comment saying
> so (but deleted the comment once I got down to this spot in the
> patch). Also, perhaps rename the test to make it clearer that it
> complements the "uses --default when missing entry" test; perhaps
> "does not fallback to --default when entry present" or something.

That location makes much more sense, as does using --default=yes to
ensure that canonicalization is taking place. I've updated that locally,
as well as the preceding test to make it clearer that they are
contrasting tests:

	- 'falls back to --default when missing entry'
	- 'does not fallback to --default when entry present'

Though I am not sure about "falls back" to mean "uses --default". I am
not sure which to pick here... what are your thoughts?

Thanks,
Taylor



[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]

  Powered by Linux