object-file: handle compat objects in check_object_signature

Update check_object_signature to find the hash algorithm the exising signature uses, and to use the same hash algorithm when recomputing it to check the signature is valid. This will be useful when teaching git ls-tree to display objects encoded with the compat hash algorithm. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric W. Biederman committed Oct 1, 2023 at 21:40 UTC 8d691757b8fcbe9b7898a5d1dcb37b198a8c60e1
1 file changed +3 -1
object-file.c
+3 -1
@@ -1094,9 +1094,11 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
1094 void *buf, unsigned long size,
1095 enum object_type type)
1096 {
1097 + const struct git_hash_algo *algo =
1098 + oid->algo ? &hash_algos[oid->algo] : r->hash_algo;
1099 struct object_id real_oid;
1100
1099 - hash_object_file(r->hash_algo, buf, size, type, &real_oid);
1101 + hash_object_file(algo, buf, size, type, &real_oid);
1102
1103 return !oideq(oid, &real_oid) ? -1 : 0;
1104 }