All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
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: Mon, 18 Aug 2014 23:03:51 -0700	[thread overview]
Message-ID: <xmqqmwb1vwvs.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20140819051732.GA13765@peff.net> (Jeff King's message of "Tue, 19 Aug 2014 01:17:32 -0400")

Jeff King <peff@peff.net> writes:

> 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. :)

Actually, I wrote something like that aloud but did not type it out
;-).  Great minds think alike.

We already have some code paths that use ((void *)1) as a special
pointer value, so in that sense I would say it is not the end of the
world if you added a new one.  At the end-user level (i.e. people
who write callers to set-multivar-in-file function), I actually like
your idea of inventing our own string syntax and parse it at the
place where we strip '!' out and remember that the pattern's match
status needs to be negated.  For example, instead of "a^" (to which
I cannot say with confidence that no implementation would match the
not-at-the-beginning caret literally), I would not mind if we taught
set-multivar-in-file that we use "!*" as a mark to tell "this
pattern never matches", and have it assign your "never matches"
mark, i.e. (void *)1, to store.value_regex.  Then matches() would
become

	static int matches(const char *key, const char *value)
        {
        	if (strcmp(key, store.key))
                	return 0; /* not ours */
		if (!store.value_regex)
                	return 1; /* always matches */
		if (store.value_regex == CONFIG_REGEX_NONE)
                	return 0; /* never matches */
		return store.do_not_match ^
                	!regexec(store.value_regex, value, 0, NULL, 0);
	}

or something like that, and the ugly "magic" will be localized,
which may make it more palatable.

  reply	other threads:[~2014-08-19  6:04 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 [this message]
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=xmqqmwb1vwvs.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.