summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-02-16 23:59:46 -0800
committerJunio C Hamano <gitster@pobox.com>2010-02-17 09:39:03 -0800
commit8420ccd8b884e1edceca9ea5824f3ff300c0c4ba (patch)
treee3dea24d016ce539ebffc20c32664601c99ea28d /config.c
parente923eaeb901ff056421b9007adcbbce271caa7b6 (diff)
downloadgit-8420ccd8b884e1edceca9ea5824f3ff300c0c4ba.tar.gz
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>
Diffstat (limited to 'config.c')
-rw-r--r--config.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/config.c b/config.c
index 6963fbea43..64e41bea22 100644
--- a/config.c
+++ b/config.c
@@ -322,17 +322,30 @@ unsigned long git_config_ulong(const char *name, const char *value)
return ret;
}
-int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+int git_config_maybe_bool(const char *name, const char *value)
{
- *is_bool = 1;
if (!value)
return 1;
if (!*value)
return 0;
- if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
+ if (!strcasecmp(value, "true")
+ || !strcasecmp(value, "yes")
+ || !strcasecmp(value, "on"))
return 1;
- if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
+ if (!strcasecmp(value, "false")
+ || !strcasecmp(value, "no")
+ || !strcasecmp(value, "off"))
return 0;
+ return -1;
+}
+
+int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+{
+ int v = git_config_maybe_bool(name, value);
+ if (0 <= v) {
+ *is_bool = 1;
+ return v;
+ }
*is_bool = 0;
return git_config_int(name, value);
}