git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Tanay Abhra <tanayabh@gmail.com>,
	git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [PATCH] make config --add behave correctly for empty and NULL values
Date: Tue, 19 Aug 2014 01:17:32 -0400	[thread overview]
Message-ID: <20140819051732.GA13765@peff.net> (raw)
In-Reply-To: <xmqqvbppwtir.fsf@gitster.dls.corp.google.com>

On Mon, Aug 18, 2014 at 11:18:52AM -0700, Junio C Hamano wrote:

> Are we sure that "a^", which cannot be true for any string, will not
> be caught by anybody's regcomp() as an error?  I know regcomp()
> accepts the expression and regexec() fails to match with GNU libc,
> but that is not the whole of the world.

We do support negation (ourselves) in the regexp, so "!$foo" would work,
where "$foo" is some regexp that always matches. But that may be digging
ourselves the opposite hole, trying to find a pattern that reliably
matches everything.

> To be honest, I'd rather see this done "right", by giving an option
> to the caller to tell the function not to call regcomp/regexec in
> matches().

Yeah, that was my first thought, too on seeing the patch. I even worked
up an example before reading your message, but:

>  * Define a global exported via cache.h and defined in config.c
> 
> 	extern const char CONFIG_SET_MULTIVAR_NO_REPLACE[];
> 
>    and pass it from this calling site, instead of an arbitrary
>    literal string e.g. "a^"
> 
>  * Add a bit to the "store" struct, e.g. "unsigned value_never_matches:1";
> 
>  * In git_config_set_multivar_in_file() implementation, check for
>    this constant address and set store.value_never_matches to true;
> 
>  * in matches(), check this bit and always return "No, this existing
>    value do not match" when it is set.

I just used

  #define CONFIG_REGEX_NONE ((void *)1)

as my magic sentinel value, both for the string and compiled regex
versions. Adding a bit to the store struct is a lot less disgusting and
error-prone. So I won't share mine here. :)

-Peff

  reply	other threads:[~2014-08-19  5:17 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 [this message]
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

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=20140819051732.GA13765@peff.net \
    --to=peff@peff.net \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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 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).