diff options
author | Charles Bailey <cbailey32@bloomberg.net> | 2015-06-21 19:25:44 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-06-22 15:07:21 -0700 |
commit | 2a514ed8058e35841d3d7b05a898991b83e5eaf0 (patch) | |
tree | eb121b83543970a0f21988d5f301743692e788b3 /parse-options.c | |
parent | 81a48cc08033a453bcb884ec0838a8f064a6611e (diff) | |
download | git-2a514ed8058e35841d3d7b05a898991b83e5eaf0.tar.gz |
parse-options: move unsigned long option parsing out of pack-objects.ccb/parse-magnitude
The unsigned long option parsing (including 'k'/'m'/'g' suffix
parsing) is more widely applicable. Add support for OPT_MAGNITUDE
to parse-options.h and change pack-objects.c use this support.
The error behavior on parse errors follows that of OPT_INTEGER. The
name of the option that failed to parse is reported with a brief
message describing the expect format for the option argument and
then the full usage message for the command invoked.
This differs from the previous behavior for OPT_ULONG used in
pack-objects for --max-pack-size and --window-memory which used to
display the value supplied in the error message and did not display
the full usage message.
Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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"); } |