hash: make `is_null_oid()` independent of `the_repository`

The function `is_null_oid()` uses `oideq(oid, null_oid())` to check whether a given object ID is the all-zero object ID. `null_oid()` implicitly relies on `the_repository` though to return the correct null object ID. Get rid of this dependency by always comparing the complete hash array for being all-zeroes. This is possible due to the refactoring of object IDs so that their hash arrays are always fully initialized. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 14, 2024 at 08:50 UTC 861e8c76f6668a8cbb764ec0ea3ba425dfb86b2a
2 files changed +6 -5
hash-ll.h
+6
@@ -341,6 +341,12 @@ static inline unsigned int oidhash(const struct object_id *oid)
341 return hash;
342 }
343
344 +static inline int is_null_oid(const struct object_id *oid)
345 +{
346 + static const unsigned char null_hash[GIT_MAX_RAWSZ];
347 + return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
348 +}
349 +
350 const char *empty_tree_oid_hex(void);
351 const char *empty_blob_oid_hex(void);
352
hash.h
-5
@@ -6,11 +6,6 @@
6
7 #define the_hash_algo the_repository->hash_algo
8
9 -static inline int is_null_oid(const struct object_id *oid)
10 -{
11 - return oideq(oid, null_oid());
12 -}
13 -
9 static inline int is_empty_blob_oid(const struct object_id *oid)
10 {
11 return oideq(oid, the_hash_algo->empty_blob);