Skip to content

Commit 23b0c47

Browse files
sprohaskagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ce7c76 commit 23b0c47

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,7 @@ extern int git_config_rename_section_in_file(const char *, const char *, const c
13181318
extern const char *git_etc_gitconfig(void);
13191319
extern int check_repository_format_version(const char *var, const char *value, void *cb);
13201320
extern int git_env_bool(const char *, int);
1321+
extern unsigned long git_env_ulong(const char *, unsigned long);
13211322
extern int git_config_system(void);
13221323
extern int config_error_nonbool(const char *);
13231324
#if defined(__GNUC__)

config.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,12 +1116,28 @@ const char *git_etc_gitconfig(void)
11161116
return system_wide;
11171117
}
11181118

1119+
/*
1120+
* Parse environment variable 'k' as a boolean (in various
1121+
* possible spellings); if missing, use the default value 'def'.
1122+
*/
11191123
int git_env_bool(const char *k, int def)
11201124
{
11211125
const char *v = getenv(k);
11221126
return v ? git_config_bool(k, v) : def;
11231127
}
11241128

1129+
/*
1130+
* Parse environment variable 'k' as ulong with possibly a unit
1131+
* suffix; if missing, use the default value 'val'.
1132+
*/
1133+
unsigned long git_env_ulong(const char *k, unsigned long val)
1134+
{
1135+
const char *v = getenv(k);
1136+
if (v && !git_parse_ulong(v, &val))
1137+
die("failed to parse %s", k);
1138+
return val;
1139+
}
1140+
11251141
int git_config_system(void)
11261142
{
11271143
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);

0 commit comments

Comments
 (0)