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

Re: Alternative approach to the git config NULL value checking patches..

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 11, 2008, 00:40 UTC
Message-ID
<7vhcggcokx.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LFD.1.00.0802101538030.2920@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
> And here's an example of this kind of effect. I'm not actually suggesting 
> you apply this patch, but tell me it isn't simpler done this way?
Yes, that is a good example of simplification.
> So this is where it *does* make a difference whether we use NULL or 
> config_bool, and where config_bool is simply better: it allows a config 
> routine to simply never care..

But that applies only to "originally bool but now has additional states" kind of variables.

For a variable that is never about boolean, if the original code said:

	if (!strcmp(var, "section.variable"))
        	foo = xstrdup(value);
it is wrong (would strdup NULL), and the correct fix would be:
	if (!strcmp(var, "section.variable")) {
		if (!value)
			die("missing value for '%s'", var);
        	foo = xstrdup(value);
	}

It does not make much of a difference if that "if (!value)" becomes "if (value == config_true)". If you omit that check, as your "user.name" example shows, foo may get an empty string or a string "true", neither of which is what the user intended to say.

Previous: Linus TorvaldsNext: Christian Couder
Message 10 of 13 in “Alternative approach to the git config NULL value checking patches..”
  1. Linus TorvaldsFeb 10, 2008
  2. Junio C HamanoFeb 10, 2008
  3. Linus TorvaldsFeb 10, 2008
  4. Junio C HamanoFeb 10, 2008
  5. Junio C HamanoFeb 10, 2008
  6. Pierre HabouzitFeb 10, 2008
  7. Linus TorvaldsFeb 10, 2008
  8. Linus TorvaldsFeb 10, 2008
  9. Linus TorvaldsFeb 10, 2008
  10. Junio C HamanoFeb 11, 2008
  11. Christian CouderFeb 11, 2008
  12. Junio C HamanoFeb 11, 2008
  13. Daniel BarkalowFeb 11, 2008

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.