summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-06-22 10:03:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-24 19:34:20 (GMT)
commit39c575c96967f325a995cf9716a46f7e924714f5 (patch)
treedbc3d1e379336cd70d43d08a64061f1574dab276 /config.c
parent664178e8e23fbd6d79b02ea51374015023c02102 (diff)
downloadgit-39c575c96967f325a995cf9716a46f7e924714f5.zip
git-39c575c96967f325a995cf9716a46f7e924714f5.tar.gz
git-39c575c96967f325a995cf9716a46f7e924714f5.tar.bz2
config: simplify parsing of unit factors
Just return the value of the factor or zero for unrecognized strings instead of using an output reference and a separate return value to indicate success. This is shorter and simpler. It basically reverts that function to before c8deb5a146 ("Improve error messages when int/long cannot be parsed from config", 2007-12-25), while keeping the better messages, so restore its old name, get_unit_factor(), as well. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/config.c b/config.c
index a8bd1d8..26196bd 100644
--- a/config.c
+++ b/config.c
@@ -834,24 +834,16 @@ static int git_parse_source(config_fn_t fn, void *data,
return error_return;
}
-static int parse_unit_factor(const char *end, uintmax_t *factor)
+static uintmax_t get_unit_factor(const char *end)
{
- if (!*end) {
- *factor = 1;
+ if (!*end)
return 1;
- }
- else if (!strcasecmp(end, "k")) {
- *factor = 1024;
- return 1;
- }
- else if (!strcasecmp(end, "m")) {
- *factor = 1024 * 1024;
- return 1;
- }
- else if (!strcasecmp(end, "g")) {
- *factor = 1024 * 1024 * 1024;
- return 1;
- }
+ else if (!strcasecmp(end, "k"))
+ return 1024;
+ else if (!strcasecmp(end, "m"))
+ return 1024 * 1024;
+ else if (!strcasecmp(end, "g"))
+ return 1024 * 1024 * 1024;
return 0;
}
@@ -867,7 +859,8 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
val = strtoimax(value, &end, 0);
if (errno == ERANGE)
return 0;
- if (!parse_unit_factor(end, &factor)) {
+ factor = get_unit_factor(end);
+ if (!factor) {
errno = EINVAL;
return 0;
}
@@ -896,7 +889,8 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max)
val = strtoumax(value, &end, 0);
if (errno == ERANGE)
return 0;
- if (!parse_unit_factor(end, &factor)) {
+ factor = get_unit_factor(end);
+ if (!factor) {
errno = EINVAL;
return 0;
}