Skip to content

Commit 861e8c7

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d4d364b commit 861e8c7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

hash-ll.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ static inline unsigned int oidhash(const struct object_id *oid)
341341
return hash;
342342
}
343343

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+
344350
const char *empty_tree_oid_hex(void);
345351
const char *empty_blob_oid_hex(void);
346352

hash.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
#define the_hash_algo the_repository->hash_algo
88

9-
static inline int is_null_oid(const struct object_id *oid)
10-
{
11-
return oideq(oid, null_oid());
12-
}
13-
149
static inline int is_empty_blob_oid(const struct object_id *oid)
1510
{
1611
return oideq(oid, the_hash_algo->empty_blob);

0 commit comments

Comments
 (0)