git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] make config --add behave correctly for empty and NULL values

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 19, 2014, 06:03 UTC
Message-ID
<xmqqmwb1vwvs.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140819051732.GA13765@peff.net>
Jeff King <peff@peff.net> writes:
Show 7 quoted lines
> 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.

Previous: Jeff KingNext: Jeff King
Message 5 of 12 in “make config --add behave correctly for empty and NULL values”
  1. make config --add behave correctly for empty and NULL valuesTanay Abhra, Aug 18, 2014
  2. Matthieu MoyAug 18, 2014
  3. Junio C HamanoAug 18, 2014
  4. Jeff KingAug 19, 2014
  5. Junio C HamanoAug 19, 2014
  6. Jeff KingAug 19, 2014
  7. Junio C HamanoSep 11, 2014
  8. Jeff KingSep 12, 2014
  9. 1/2 document irregular config --add behaviour for empty and NULL valuesTanay Abhra, Sep 12, 2014
  10. 2/2 make config --add behave correctly for empty and NULL valuesTanay Abhra, Sep 12, 2014
  11. Matthieu MoySep 12, 2014
  12. Junio C HamanoSep 12, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.