@matheusbsbs / matheus-bagliano / commits / db6195efab
Fork 0

handle arbitrary ints in git_config_maybe_bool

This function recently gained the ability to recognize the documented "0" and "1" values as false/true. However, unlike regular git_config_bool, it did not treat arbitrary non-zero numbers as true. While this is undocumented and probably ridiculous for somebody to rely on, it is safer to behave exactly as git_config_bool would. Because git_config_maybe_bool can be used to retrofit new non-bool values onto existing bool options, not behaving in exactly the same way is technically a regression. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 18, 2010 at 22:36 UTC db6195efab70aa3aca1cc8e39855f2cd58e0287b
1 file changed +3 -5
config.c
+3 -5
@@ -429,13 +429,11 @@ static int git_config_maybe_bool_text(const char *name, const char *value)
429
430 int git_config_maybe_bool(const char *name, const char *value)
431 {
432 - int v = git_config_maybe_bool_text(name, value);
432 + long v = git_config_maybe_bool_text(name, value);
433 if (0 <= v)
434 return v;
435 - if (!strcmp(value, "0"))
436 - return 0;
437 - if (!strcmp(value, "1"))
438 - return 1;
435 + if (git_parse_long(value, &v))
436 + return !!v;
437 return -1;
438 }
439