Thread (1 message) 1 message, 1 author, 2016-06-15

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:12

Linus Torvalds [off-list ref] 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help