aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-repo-config.txt5
-rw-r--r--config.c6
-rwxr-xr-xt/t1300-repo-config.sh10
3 files changed, 20 insertions, 1 deletions
diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt
index b379ec507..c55a8ba0d 100644
--- a/Documentation/git-repo-config.txt
+++ b/Documentation/git-repo-config.txt
@@ -87,7 +87,10 @@ OPTIONS
git-repo-config will ensure that the output is "true" or "false"
--int::
- git-repo-config will ensure that the output is a simple decimal number
+ git-repo-config will ensure that the output is a simple
+ decimal number. An optional value suffix of 'k', 'm', or 'g'
+ in the config file will cause the value to be multiplied
+ by 1024, 1048576, or 1073741824 prior to output.
ENVIRONMENT
diff --git a/config.c b/config.c
index fcccf7e2a..458ae512f 100644
--- a/config.c
+++ b/config.c
@@ -238,6 +238,12 @@ int git_config_int(const char *name, const char *value)
int val = strtol(value, &end, 0);
if (!*end)
return val;
+ if (!strcasecmp(end, "k"))
+ return val * 1024;
+ if (!strcasecmp(end, "m"))
+ return val * 1024 * 1024;
+ if (!strcasecmp(end, "g"))
+ return val * 1024 * 1024 * 1024;
}
die("bad config value for '%s' in %s", name, config_file_name);
}
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index e48a4ecdc..a29caa06d 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -391,5 +391,15 @@ EOF
test_expect_success "rename succeeded" "diff -u expect .git/config"
+test_expect_success numbers '
+
+ git-repo-config kilo.gram 1k &&
+ git-repo-config mega.ton 1m &&
+ k=$(git-repo-config --int --get kilo.gram) &&
+ test z1024 = "z$k" &&
+ m=$(git-repo-config --int --get mega.ton) &&
+ test z1048576 = "z$m"
+'
+
test_done