Skip to content

Commit d877418

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2d3f27 commit d877418

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

diff.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5254,6 +5254,7 @@ static void prep_parse_options(struct diff_options *options)
52545254
OPT_SET_INT('z', NULL, &options->line_termination,
52555255
N_("do not munge pathnames and use NULs as output field terminators in --raw or --numstat"),
52565256
0),
5257+
OPT__ABBREV(&options->abbrev),
52575258
OPT_CALLBACK_F(0, "output-indicator-new",
52585259
&options->output_indicators[OUTPUT_INDICATOR_NEW],
52595260
N_("<char>"),
@@ -5448,17 +5449,6 @@ int diff_opt_parse(struct diff_options *options,
54485449
}
54495450

54505451
/* 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-
}
54625452
else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
54635453
options->a_prefix = optarg;
54645454
return argcount;

parse-options-cb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
2222
opt->long_name);
2323
if (v && v < MINIMUM_ABBREV)
2424
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;
2727
}
2828
*(int *)(opt->value) = v;
2929
return 0;

0 commit comments

Comments
 (0)