From: Junio C Hamano <gitster@pobox.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: Tanay Abhra <tanayabh@gmail.com>, Jeff King <peff@peff.net>,
git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>
Subject: Re: [PATCH v2 2/2] make config --add behave correctly for empty and NULL values
Date: Fri, 12 Sep 2014 10:29:25 -0700 [thread overview]
Message-ID: <xmqqa964bvd6.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <vpqegvhfe5p.fsf@anie.imag.fr> (Matthieu Moy's message of "Fri, 12 Sep 2014 10:15:14 +0200")
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> Tanay Abhra <tanayabh@gmail.com> writes:
>
>> +const char CONFIG_REGEX_NONE[] = "a^";
>
> I have a slight preference for this version (no magic (void *)1 value,
> and belts-and-suspenders solution since someone actually using the regex
> should still get a correct behavior.
>
> But I'm fine with both Junio/Peff's version or this one.
I do not care too deeply either way, to be honest.
But if we were to redo this in the right way, I suspect that the
best solution may be to correct the root cause, which is the design
mistake in the git_config_set_multivar_in_file API. The function
takes a regexp (possibly NULL) and a multi_replace bit, and with
that expresses these three combinations:
- a non-NULL regexp means only the existing ones that match are
subject to replacement;
- NULL regexp means all of the existing ones that match are
subject to replacement;
- multi-replace bit controls which ones among the replacement
candidates are replaced (either the first one or all).
But we actually want to express three, not two, different handling
for the existing entries. Either (1) use the regexp to decide which
ones are subject to replacement, (2) declare all of them are subject
to replacement, or (3) declare none of them are to be replaced. The
last one cannot be expressed without coming up with a trick to say
"I am giving a regexp that hopefully will not match anything as a
workaround because otherwise you will replace all of them but what I
really want to say is I do not want you to replace anything", and
this thread discusses a fix to the bug in the implementation that
failed to come up with a "hopefully will not match anything"
pattern. And we are still discussing to fix a better workaround.
Instead of polishing the workaround, wouldn't it be better to make
it unnecessary to work it around? For exaple, we could turn the
last parameter to the function into an "unsigned flag" with two
bits, CONFIG_SET_USE_REGEXP_TO_FILTER (if set, use the regexp to
filter which of the existing entries to be replaced) and
CONFIG_SET_REPLACE_MULTI (if set, replace all the eligible ones),
and the result would be conceptually a lot cleaner, no?
Some notes:
- Because most callers expect "replace" behaviour, instead of
adding CONFIG_SET_USE_REGEXP_TO_FILTER to the majority of
existing callers, a new flag CONFIG_SET_JUST_APPEND (which is
exactly the negation of the USE_REGEXP_TO_FILTER) would be a more
practical thing to introduce.
- We can keep using value_regexp==NULL (under !JUST_APPEND) to mean
value_regexp=".*", i.e. matches anything, as a short-hand.
Hmm?
prev parent reply other threads:[~2014-09-12 17:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-18 10:17 [PATCH] make config --add behave correctly for empty and NULL values Tanay Abhra
2014-08-18 12:33 ` Matthieu Moy
2014-08-18 18:18 ` Junio C Hamano
2014-08-19 5:17 ` Jeff King
2014-08-19 6:03 ` Junio C Hamano
2014-08-19 6:20 ` Jeff King
2014-09-11 23:35 ` Junio C Hamano
2014-09-12 2:29 ` Jeff King
2014-09-12 7:23 ` [PATCH v2 1/2] document irregular config --add behaviour " Tanay Abhra
2014-09-12 7:25 ` [PATCH v2 2/2] make config --add behave correctly " Tanay Abhra
2014-09-12 8:15 ` Matthieu Moy
2014-09-12 17:29 ` Junio C Hamano [this message]
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=xmqqa964bvd6.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=tanayabh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.