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>
This commit is contained in:
parent
7ce7c7607b
commit
23b0c4782e
1
cache.h
1
cache.h
@ -1318,6 +1318,7 @@ extern int git_config_rename_section_in_file(const char *, const char *, const c
|
|||||||
extern const char *git_etc_gitconfig(void);
|
extern const char *git_etc_gitconfig(void);
|
||||||
extern int check_repository_format_version(const char *var, const char *value, void *cb);
|
extern int check_repository_format_version(const char *var, const char *value, void *cb);
|
||||||
extern int git_env_bool(const char *, int);
|
extern int git_env_bool(const char *, int);
|
||||||
|
extern unsigned long git_env_ulong(const char *, unsigned long);
|
||||||
extern int git_config_system(void);
|
extern int git_config_system(void);
|
||||||
extern int config_error_nonbool(const char *);
|
extern int config_error_nonbool(const char *);
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
|
16
config.c
16
config.c
@ -1116,12 +1116,28 @@ const char *git_etc_gitconfig(void)
|
|||||||
return system_wide;
|
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)
|
int git_env_bool(const char *k, int def)
|
||||||
{
|
{
|
||||||
const char *v = getenv(k);
|
const char *v = getenv(k);
|
||||||
return v ? git_config_bool(k, v) : def;
|
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)
|
int git_config_system(void)
|
||||||
{
|
{
|
||||||
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
|
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user