Skip to content

Commit de1d81d

Browse files
bk2204gitster
authored andcommitted
diff: specify abbreviation size in terms of the_hash_algo
Instead of using hard-coded 40 constants, refer to the_hash_algo for the current hash size. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55dc227 commit de1d81d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

diff.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,13 +3897,14 @@ static void fill_metainfo(struct strbuf *msg,
38973897
*must_show_header = 0;
38983898
}
38993899
if (one && two && oidcmp(&one->oid, &two->oid)) {
3900-
int abbrev = o->flags.full_index ? 40 : DEFAULT_ABBREV;
3900+
const unsigned hexsz = the_hash_algo->hexsz;
3901+
int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV;
39013902

39023903
if (o->flags.binary) {
39033904
mmfile_t mf;
39043905
if ((!fill_mmfile(&mf, one) && diff_filespec_is_binary(one)) ||
39053906
(!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
3906-
abbrev = 40;
3907+
abbrev = hexsz;
39073908
}
39083909
strbuf_addf(msg, "%s%sindex %s..%s", line_prefix, set,
39093910
diff_abbrev_oid(&one->oid, abbrev),
@@ -4138,6 +4139,11 @@ void diff_setup_done(struct diff_options *options)
41384139
DIFF_FORMAT_NAME_STATUS |
41394140
DIFF_FORMAT_CHECKDIFF |
41404141
DIFF_FORMAT_NO_OUTPUT;
4142+
/*
4143+
* This must be signed because we're comparing against a potentially
4144+
* negative value.
4145+
*/
4146+
const int hexsz = the_hash_algo->hexsz;
41414147

41424148
if (options->set_default)
41434149
options->set_default(options);
@@ -4218,8 +4224,8 @@ void diff_setup_done(struct diff_options *options)
42184224
*/
42194225
read_cache();
42204226
}
4221-
if (40 < options->abbrev)
4222-
options->abbrev = 40; /* full */
4227+
if (hexsz < options->abbrev)
4228+
options->abbrev = hexsz; /* full */
42234229

42244230
/*
42254231
* It does not make sense to show the first hit we happened
@@ -4797,8 +4803,8 @@ int diff_opt_parse(struct diff_options *options,
47974803
options->abbrev = strtoul(arg, NULL, 10);
47984804
if (options->abbrev < MINIMUM_ABBREV)
47994805
options->abbrev = MINIMUM_ABBREV;
4800-
else if (40 < options->abbrev)
4801-
options->abbrev = 40;
4806+
else if (the_hash_algo->hexsz < options->abbrev)
4807+
options->abbrev = the_hash_algo->hexsz;
48024808
}
48034809
else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
48044810
options->a_prefix = optarg;

0 commit comments

Comments
 (0)