@matheusbsbs / matheus-bagliano / commits / 8420ccd8b8
Fork 0

git_config_maybe_bool()

Some configuration variables can take boolean values in addition to enumeration specific to them. Introduce git_config_maybe_bool() that returns 0 or 1 if the given value is boolean, or -1 if not, so that a parser for such a variable can check for boolean first and then parse other kinds of values as a fallback. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 16, 2010 at 23:59 UTC 8420ccd8b884e1edceca9ea5824f3ff300c0c4ba
2 files changed +18 -4
cache.h
+1
@@ -924,6 +924,7 @@ extern int git_config_int(const char *, const char *);
924 extern unsigned long git_config_ulong(const char *, const char *);
925 extern int git_config_bool_or_int(const char *, const char *, int *);
926 extern int git_config_bool(const char *, const char *);
927 +extern int git_config_maybe_bool(const char *, const char *);
928 extern int git_config_string(const char **, const char *, const char *);
929 extern int git_config_pathname(const char **, const char *, const char *);
930 extern int git_config_set(const char *, const char *);
config.c
+17 -4
@@ -322,17 +322,30 @@ unsigned long git_config_ulong(const char *name, const char *value)
322 return ret;
323 }
324
325 -int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
325 +int git_config_maybe_bool(const char *name, const char *value)
326 {
327 - *is_bool = 1;
327 if (!value)
328 return 1;
329 if (!*value)
330 return 0;
332 - if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
331 + if (!strcasecmp(value, "true")
332 + || !strcasecmp(value, "yes")
333 + || !strcasecmp(value, "on"))
334 return 1;
334 - if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
335 + if (!strcasecmp(value, "false")
336 + || !strcasecmp(value, "no")
337 + || !strcasecmp(value, "off"))
338 return 0;
339 + return -1;
340 +}
341 +
342 +int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
343 +{
344 + int v = git_config_maybe_bool(name, value);
345 + if (0 <= v) {
346 + *is_bool = 1;
347 + return v;
348 + }
349 *is_bool = 0;
350 return git_config_int(name, value);
351 }