Use the final_oid_fn to finalize hashing of object IDs

When we're hashing a value which is going to be an object ID, we want to zero-pad that value if necessary. To do so, use the final_oid_fn instead of the final_fn anytime we're going to create an object ID to ensure we perform this operation. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 26, 2021 at 01:02 UTC 5951bf467ea92458c3bea3051c8413041f3b27d5
7 files changed +11 -11
builtin/fast-import.c
+2 -2
@@ -940,7 +940,7 @@ static int store_object(
940 the_hash_algo->init_fn(&c);
941 the_hash_algo->update_fn(&c, hdr, hdrlen);
942 the_hash_algo->update_fn(&c, dat->buf, dat->len);
943 - the_hash_algo->final_fn(oid.hash, &c);
943 + the_hash_algo->final_oid_fn(&oid, &c);
944 if (oidout)
945 oidcpy(oidout, &oid);
946
@@ -1136,7 +1136,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1136 }
1137 }
1138 git_deflate_end(&s);
1139 - the_hash_algo->final_fn(oid.hash, &c);
1139 + the_hash_algo->final_oid_fn(&oid, &c);
1140
1141 if (oidout)
1142 oidcpy(oidout, &oid);
builtin/index-pack.c
+1 -1
@@ -489,7 +489,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
489 bad_object(offset, _("inflate returned %d"), status);
490 git_inflate_end(&stream);
491 if (oid)
492 - the_hash_algo->final_fn(oid->hash, &c);
492 + the_hash_algo->final_oid_fn(oid, &c);
493 return buf == fixed_buf ? NULL : buf;
494 }
495
builtin/unpack-objects.c
+1 -1
@@ -576,7 +576,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
576 the_hash_algo->init_fn(&ctx);
577 unpack_all();
578 the_hash_algo->update_fn(&ctx, buffer, offset);
579 - the_hash_algo->final_fn(oid.hash, &ctx);
579 + the_hash_algo->final_oid_fn(&oid, &ctx);
580 if (strict) {
581 write_rest();
582 if (fsck_finish(&fsck_options))
bulk-checkin.c
+1 -1
@@ -238,7 +238,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
238 if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
239 return error("cannot seek back");
240 }
241 - the_hash_algo->final_fn(result_oid->hash, &ctx);
241 + the_hash_algo->final_oid_fn(result_oid, &ctx);
242 if (!idx)
243 return 0;
244
diff.c
+1 -1
@@ -6234,7 +6234,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
6234 }
6235
6236 if (!stable)
6237 - the_hash_algo->final_fn(oid->hash, &ctx);
6237 + the_hash_algo->final_oid_fn(oid, &ctx);
6238
6239 return 0;
6240 }
http.c
+1 -1
@@ -2576,7 +2576,7 @@ int finish_http_object_request(struct http_object_request *freq)
2576 }
2577
2578 git_inflate_end(&freq->stream);
2579 - the_hash_algo->final_fn(freq->real_oid.hash, &freq->c);
2579 + the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c);
2580 if (freq->zret != Z_STREAM_END) {
2581 unlink_or_warn(freq->tmpfile.buf);
2582 return -1;
object-file.c
+4 -4
@@ -1054,7 +1054,7 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
1054 break;
1055 r->hash_algo->update_fn(&c, buf, readlen);
1056 }
1057 - r->hash_algo->final_fn(real_oid.hash, &c);
1057 + r->hash_algo->final_oid_fn(&real_oid, &c);
1058 close_istream(st);
1059 return !oideq(oid, &real_oid) ? -1 : 0;
1060 }
@@ -1755,7 +1755,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
1755 algo->init_fn(&c);
1756 algo->update_fn(&c, hdr, *hdrlen);
1757 algo->update_fn(&c, buf, len);
1758 - algo->final_fn(oid->hash, &c);
1758 + algo->final_oid_fn(oid, &c);
1759 }
1760
1761 /*
@@ -1927,7 +1927,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
1927 if (ret != Z_OK)
1928 die(_("deflateEnd on object %s failed (%d)"), oid_to_hex(oid),
1929 ret);
1930 - the_hash_algo->final_fn(parano_oid.hash, &c);
1930 + the_hash_algo->final_oid_fn(&parano_oid, &c);
1931 if (!oideq(oid, &parano_oid))
1932 die(_("confused by unstable object source data for %s"),
1933 oid_to_hex(oid));
@@ -2508,7 +2508,7 @@ static int check_stream_oid(git_zstream *stream,
2508 return -1;
2509 }
2510
2511 - the_hash_algo->final_fn(real_oid.hash, &c);
2511 + the_hash_algo->final_oid_fn(&real_oid, &c);
2512 if (!oideq(expected_oid, &real_oid)) {
2513 error(_("hash mismatch for %s (expected %s)"), path,
2514 oid_to_hex(expected_oid));