[PATCH 06/21] hash: make `is_null_oid()` independent of `the_repository`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 hash-ll.h | 6 ++++++
 hash.h    | 5 -----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/hash-ll.h b/hash-ll.h
index b04fe12aef..faf6c292d2 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -341,6 +341,12 @@ static inline unsigned int oidhash(const struct object_id *oid)
 	return hash;
 }
 
+static inline int is_null_oid(const struct object_id *oid)
+{
+	static const unsigned char null_hash[GIT_MAX_RAWSZ];
+	return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
+}
+
 const char *empty_tree_oid_hex(void);
 const char *empty_blob_oid_hex(void);
 
diff --git a/hash.h b/hash.h
index ddc2e5ca47..84f2296cfb 100644
--- a/hash.h
+++ b/hash.h
@@ -6,11 +6,6 @@
 
 #define the_hash_algo the_repository->hash_algo
 
-static inline int is_null_oid(const struct object_id *oid)
-{
-	return oideq(oid, null_oid());
-}
-
 static inline int is_empty_blob_oid(const struct object_id *oid)
 {
 	return oideq(oid, the_hash_algo->empty_blob);
-- 
2.45.2.436.gcd77e87115.dirty

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux