diff-parseopt: convert --[no-]abbrev

OPT__ABBREV() has the same behavior as the deleted code with one difference: it does check for valid number and error out if not. And the '40' change is self explanatory. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 24, 2019 at 15:20 UTC d877418390168c9696fd46d5e78ca3362f26f74c
2 files changed +3 -13
diff.c
+1 -11
@@ -5254,6 +5254,7 @@ static void prep_parse_options(struct diff_options *options)
5254 OPT_SET_INT('z', NULL, &options->line_termination,
5255 N_("do not munge pathnames and use NULs as output field terminators in --raw or --numstat"),
5256 0),
5257 + OPT__ABBREV(&options->abbrev),
5258 OPT_CALLBACK_F(0, "output-indicator-new",
5259 &options->output_indicators[OUTPUT_INDICATOR_NEW],
5260 N_("<char>"),
@@ -5448,17 +5449,6 @@ int diff_opt_parse(struct diff_options *options,
5449 }
5450
5451 /* misc options */
5451 - else if (!strcmp(arg, "--no-abbrev"))
5452 - options->abbrev = 0;
5453 - else if (!strcmp(arg, "--abbrev"))
5454 - options->abbrev = DEFAULT_ABBREV;
5455 - else if (skip_prefix(arg, "--abbrev=", &arg)) {
5456 - options->abbrev = strtoul(arg, NULL, 10);
5457 - if (options->abbrev < MINIMUM_ABBREV)
5458 - options->abbrev = MINIMUM_ABBREV;
5459 - else if (the_hash_algo->hexsz < options->abbrev)
5460 - options->abbrev = the_hash_algo->hexsz;
5461 - }
5452 else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
5453 options->a_prefix = optarg;
5454 return argcount;
parse-options-cb.c
+2 -2
@@ -22,8 +22,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
22 opt->long_name);
23 if (v && v < MINIMUM_ABBREV)
24 v = MINIMUM_ABBREV;
25 - else if (v > 40)
26 - v = 40;
25 + else if (v > the_hash_algo->hexsz)
26 + v = the_hash_algo->hexsz;
27 }
28 *(int *)(opt->value) = v;
29 return 0;