hash: provide per-algorithm null OIDs

Up until recently, object IDs did not have an algorithm member, only a
hash.  Consequently, it was possible to share one null (all-zeros)
object ID among all hash algorithms.  Now that we're going to be
handling objects from multiple hash algorithms, it's important to make
sure that all object IDs have a correct algorithm field.

Introduce a per-algorithm null OID, and add it to struct hash_algo.
Introduce a wrapper function as well, and use it everywhere we used to
use the null_oid constant.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson
2021-04-26 01:02:56 +00:00
committed by Junio C Hamano
parent 5a6dce70d7
commit 14228447c9
42 changed files with 119 additions and 95 deletions

7
hash.h
View File

@ -170,6 +170,9 @@ struct git_hash_algo {
/* The OID of the empty blob. */
const struct object_id *empty_blob;
/* The all-zeros OID. */
const struct object_id *null_oid;
};
extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
@ -190,7 +193,7 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
#define the_hash_algo the_repository->hash_algo
extern const struct object_id null_oid;
const struct object_id *null_oid(void);
static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
@ -246,7 +249,7 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
static inline int is_null_oid(const struct object_id *oid)
{
return oideq(oid, &null_oid);
return oideq(oid, null_oid());
}
static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)