diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-08-03 11:01:13 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-08-03 11:01:13 -0700 |
commit | e12b51e4d685c30f488c99c5d89f3310c3fcd9b0 (patch) | |
tree | 57edea5f304464e3865ffecc6fb475b41f2fa0e8 /parse-options.c | |
parent | ba12cb299f831f29c256c644b01108710c2629e6 (diff) | |
parent | 2a514ed8058e35841d3d7b05a898991b83e5eaf0 (diff) | |
download | git-e12b51e4d685c30f488c99c5d89f3310c3fcd9b0.tar.gz |
Merge branch 'cb/parse-magnitude'
Move machinery to parse human-readable scaled numbers like 1k, 4M,
and 2G as an option parameter's value from pack-objects to
parse-options API, to make it available to other codepaths.
* cb/parse-magnitude:
parse-options: move unsigned long option parsing out of pack-objects.c
test-parse-options: update to handle negative ints
Diffstat (limited to 'parse-options.c')
-rw-r--r-- | parse-options.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/parse-options.c b/parse-options.c index 80106c06bc..3eceba4463 100644 --- a/parse-options.c +++ b/parse-options.c @@ -180,6 +180,23 @@ static int get_value(struct parse_opt_ctx_t *p, return opterror(opt, "expects a numerical value", flags); return 0; + case OPTION_MAGNITUDE: + if (unset) { + *(unsigned long *)opt->value = 0; + return 0; + } + if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { + *(unsigned long *)opt->value = opt->defval; + return 0; + } + if (get_arg(p, opt, flags, &arg)) + return -1; + if (!git_parse_ulong(arg, opt->value)) + return opterror(opt, + "expects a non-negative integer value with an optional k/m/g suffix", + flags); + return 0; + default: die("should not happen, someone must be hit on the forehead"); } |