config: allow uppercase number suffixes Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/config.c b/src/config.c
index 9e62df0..ec350f8 100644
--- a/src/config.c
+++ b/src/config.c
@@ -394,12 +394,15 @@ int git_config_get_long(git_config *cfg, const char *name, long int *out)
case '\0':
break;
case 'k':
+ case 'K':
num *= 1024;
break;
case 'm':
+ case 'M':
num *= 1024 * 1024;
break;
case 'g':
+ case 'G':
num *= 1024 * 1024 * 1024;
break;
default:
diff --git a/tests/resources/config/config5 b/tests/resources/config/config5
index 645fe76..8ab60cc 100644
--- a/tests/resources/config/config5
+++ b/tests/resources/config/config5
@@ -2,5 +2,8 @@
[number]
simple = 1
k = 1k
+ kk = 1K
m = 1m
+ mm = 1M
g = 1g
+ gg = 1G
diff --git a/tests/t15-config.c b/tests/t15-config.c
index 1cf4b41..8e0d321 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -142,12 +142,21 @@ BEGIN_TEST(config5, "test number suffixes")
must_pass(git_config_get_long(cfg, "number.k", &i));
must_be_true(i == 1 * 1024);
+ must_pass(git_config_get_long(cfg, "number.kk", &i));
+ must_be_true(i == 1 * 1024);
+
must_pass(git_config_get_long(cfg, "number.m", &i));
must_be_true(i == 1 * 1024 * 1024);
+ must_pass(git_config_get_long(cfg, "number.mm", &i));
+ must_be_true(i == 1 * 1024 * 1024);
+
must_pass(git_config_get_long(cfg, "number.g", &i));
must_be_true(i == 1 * 1024 * 1024 * 1024);
+ must_pass(git_config_get_long(cfg, "number.gg", &i));
+ must_be_true(i == 1 * 1024 * 1024 * 1024);
+
git_config_free(cfg);
END_TEST