summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorSteffen Prohaska <prohaska@zib.de>2014-08-26 17:23:21 +0200
committerJunio C Hamano <gitster@pobox.com>2014-08-28 10:24:54 -0700
commit23b0c4782e5f9357e6189253021053a4404ddf4e (patch)
treed65114d19760b165c80558b4996a161cecdcc05b /config.c
parent7ce7c7607b14248b1a3ae7cdd1c079eb3b6efa09 (diff)
downloadgit-23b0c4782e5f9357e6189253021053a4404ddf4e.tar.gz
config.c: add git_env_ulong() to parse environment variable
The new function parses an integeral value that fits in unsigned long in human readable form, i.e. possibly with unit suffix, e.g. 10k = 10240, etc., from an environment variable. Parsing of GIT_MMAP_LIMIT and GIT_ALLOC_LIMIT will use it in later patches. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/config.c b/config.c
index 058505cb8d..adab91909e 100644
--- a/config.c
+++ b/config.c
@@ -1116,12 +1116,28 @@ const char *git_etc_gitconfig(void)
return system_wide;
}
+/*
+ * Parse environment variable 'k' as a boolean (in various
+ * possible spellings); if missing, use the default value 'def'.
+ */
int git_env_bool(const char *k, int def)
{
const char *v = getenv(k);
return v ? git_config_bool(k, v) : def;
}
+/*
+ * Parse environment variable 'k' as ulong with possibly a unit
+ * suffix; if missing, use the default value 'val'.
+ */
+unsigned long git_env_ulong(const char *k, unsigned long val)
+{
+ const char *v = getenv(k);
+ if (v && !git_parse_ulong(v, &val))
+ die("failed to parse %s", k);
+ return val;
+}
+
int git_config_system(void)
{
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);