parse-options: move unsigned long option parsing out of pack-objects.c
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>
This commit is contained in:

committed by
Junio C Hamano

parent
81a48cc080
commit
2a514ed805
@ -2588,23 +2588,6 @@ static int option_parse_unpack_unreachable(const struct option *opt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int option_parse_ulong(const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
if (unset)
|
||||
die(_("option %s does not accept negative form"),
|
||||
opt->long_name);
|
||||
|
||||
if (!git_parse_ulong(arg, opt->value))
|
||||
die(_("unable to parse value '%s' for option %s"),
|
||||
arg, opt->long_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define OPT_ULONG(s, l, v, h) \
|
||||
{ OPTION_CALLBACK, (s), (l), (v), "n", (h), \
|
||||
PARSE_OPT_NONEG, option_parse_ulong }
|
||||
|
||||
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int use_internal_rev_list = 0;
|
||||
@ -2627,16 +2610,16 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
||||
{ OPTION_CALLBACK, 0, "index-version", NULL, N_("version[,offset]"),
|
||||
N_("write the pack index file in the specified idx format version"),
|
||||
0, option_parse_index_version },
|
||||
OPT_ULONG(0, "max-pack-size", &pack_size_limit,
|
||||
N_("maximum size of each output pack file")),
|
||||
OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,
|
||||
N_("maximum size of each output pack file")),
|
||||
OPT_BOOL(0, "local", &local,
|
||||
N_("ignore borrowed objects from alternate object store")),
|
||||
OPT_BOOL(0, "incremental", &incremental,
|
||||
N_("ignore packed objects")),
|
||||
OPT_INTEGER(0, "window", &window,
|
||||
N_("limit pack window by objects")),
|
||||
OPT_ULONG(0, "window-memory", &window_memory_limit,
|
||||
N_("limit pack window by memory in addition to object limit")),
|
||||
OPT_MAGNITUDE(0, "window-memory", &window_memory_limit,
|
||||
N_("limit pack window by memory in addition to object limit")),
|
||||
OPT_INTEGER(0, "depth", &depth,
|
||||
N_("maximum length of delta chain allowed in the resulting pack")),
|
||||
OPT_BOOL(0, "reuse-delta", &reuse_delta,
|
||||
|
Reference in New Issue
Block a user