Re: [PATCH v3 10/21] diff-parseopt: convert --stat*
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 20, 2019, 21:08 UTC
- Message-ID
- <xmqq1s42w4k7.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20190216113655.25728-11-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 29 quoted lines
> -static int stat_opt(struct diff_options *options, const char **av)
> +static int diff_opt_stat(const struct option *opt, const char *value, int unset)
> {
> - const char *arg = av[0];
> - char *end;
> + struct diff_options *options = opt->value;
> ...
> - switch (*arg) {
> - case '-':
> - if (skip_prefix(arg, "-width", &arg)) {
> - if (*arg == '=')
> - width = strtoul(arg + 1, &end, 10);
> - else if (!*arg && !av[1])
> - die_want_option("--stat-width");
> - else if (!*arg) {
> - width = strtoul(av[1], &end, 10);
> - argcount = 2;
> - }
> ...
> + if (!strcmp(opt->long_name, "stat")) {
> + if (value) {
> + width = strtoul(value, &end, 10);
> + if (*end == ',')
> + name_width = strtoul(end+1, &end, 10);
> + if (*end == ',')
> + count = strtoul(end+1, &end, 10);
> + if (*end)
> + return error(_("invalid --stat value: %s"), value);
> }It took me a while to recall and figure out what the original is doing, primarily because the code was designed to handle both "-$option $arg" and "--$option=$arg". But thanks to the switch to parse-options API, this helper no longer has to worry about that, which is a very big plus. It only needs to parse what is in value.
Very nice.