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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 2, 2018 at 00:25 UTC
de1d81d5af635aaa8269d54ee06d99c2b0b75c62
1 file changed
+12
-6
diff.c
+12
-6
@@ -3897,13 +3897,14 @@ static void fill_metainfo(struct strbuf *msg,
3897
*must_show_header = 0;
3898
}
3899
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;
3902
3903
if (o->flags.binary) {
3904
mmfile_t mf;
3905
if ((!fill_mmfile(&mf, one) && diff_filespec_is_binary(one)) ||
3906
(!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
3906
- abbrev = 40;
3907
+ abbrev = hexsz;
3908
}
3909
strbuf_addf(msg, "%s%sindex %s..%s", line_prefix, set,
3910
diff_abbrev_oid(&one->oid, abbrev),
@@ -4138,6 +4139,11 @@ void diff_setup_done(struct diff_options *options)
4139
DIFF_FORMAT_NAME_STATUS |
4140
DIFF_FORMAT_CHECKDIFF |
4141
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;
4147
4148
if (options->set_default)
4149
options->set_default(options);
@@ -4218,8 +4224,8 @@ void diff_setup_done(struct diff_options *options)
4224
*/
4225
read_cache();
4226
}
4221
- if (40 < options->abbrev)
4222
- options->abbrev = 40; /* full */
4227
+ if (hexsz < options->abbrev)
4228
+ options->abbrev = hexsz; /* full */
4229
4230
/*
4231
* It does not make sense to show the first hit we happened
@@ -4797,8 +4803,8 @@ int diff_opt_parse(struct diff_options *options,
4803
options->abbrev = strtoul(arg, NULL, 10);
4804
if (options->abbrev < MINIMUM_ABBREV)
4805
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;
4808
}
4809
else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
4810
options->a_prefix = optarg;