From d77a64d353cea0f72655b86dd04bcf9f86cbbea6 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 30 Dec 2006 22:13:05 -0500 Subject: Teach Git how to parse standard power of 2 suffixes. Sometimes its necessary to supply a value as a power of two in a configuration parameter. In this case the user may want to use the standard suffixes such as K, M, or G to indicate that the numerical value should be multiplied by a constant base before being used. Shell scripts/etc. can also benefit from this automatic option parsing with `git repo-config --int`. [jc: with a couple of test and a slight input tightening] Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- config.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'config.c') 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); } -- cgit v1.2.1