hash: require hash algorithm in oidread() and oidclr()

Both `oidread()` and `oidclr()` use `the_repository` to derive the hash
function that shall be used. Require callers to pass in the hash
algorithm to get rid of this implicit dependency.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-06-14 08:49:54 +02:00
committed by Junio C Hamano
parent f4836570a7
commit 9da95bda74
48 changed files with 163 additions and 140 deletions

17
hash.h
View File

@@ -47,23 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
dst->algo = src->algo;
}
static inline void oidclr(struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
}
static inline void oidread_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
{
memcpy(oid->hash, hash, algop->rawsz);
oid->algo = hash_algo_by_ptr(algop);
}
static inline void oidread(struct object_id *oid, const unsigned char *hash)
{
oidread_algop(oid, hash, the_hash_algo);
}
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);