diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-06-14 08:49:50 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-06-14 19:26:32 +0200 |
commit | f4836570a7adbd8c70ad7a8edf6ae5a977647c06 (patch) | |
tree | 568c8b46cc7324a45e2c1d42f07ed80b36bf1230 /hash.h | |
parent | hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions (diff) | |
download | git-f4836570a7adbd8c70ad7a8edf6ae5a977647c06.tar.xz git-f4836570a7adbd8c70ad7a8edf6ae5a977647c06.zip |
hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
Many of our hash functions have two variants, one receiving a `struct
git_hash_algo` and one that derives it via `the_repository`. Adapt all
of those functions to always require the hash algorithm as input and
drop the variants that do not accept one.
As those functions are now independent of `the_repository`, we can move
them from "hash.h" to "hash-ll.h".
Note that both in this and subsequent commits in this series we always
just pass `the_repository->hash_algo` as input even if it is obvious
that there is a repository in the context that we should be using the
hash from instead. This is done to be on the safe side and not introduce
any regressions. All callsites should eventually be amended to use a
repo passed via parameters, but this is outside the scope of this patch
series.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash.h')
-rw-r--r-- | hash.h | 24 |
1 files changed, 2 insertions, 22 deletions
@@ -6,11 +6,6 @@ #define the_hash_algo the_repository->hash_algo -static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) -{ - return hashcmp_algop(sha1, sha2, the_hash_algo); -} - static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2) { const struct git_hash_algo *algop; @@ -18,12 +13,7 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o algop = the_hash_algo; else algop = &hash_algos[oid1->algo]; - return hashcmp_algop(oid1->hash, oid2->hash, algop); -} - -static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2) -{ - return hasheq_algop(sha1, sha2, the_hash_algo); + return hashcmp(oid1->hash, oid2->hash, algop); } static inline int oideq(const struct object_id *oid1, const struct object_id *oid2) @@ -33,7 +23,7 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi algop = the_hash_algo; else algop = &hash_algos[oid1->algo]; - return hasheq_algop(oid1->hash, oid2->hash, algop); + return hasheq(oid1->hash, oid2->hash, algop); } static inline int is_null_oid(const struct object_id *oid) @@ -41,11 +31,6 @@ static inline int is_null_oid(const struct object_id *oid) return oideq(oid, null_oid()); } -static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) -{ - memcpy(sha_dst, sha_src, the_hash_algo->rawsz); -} - /* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */ static inline void oidcpy_with_padding(struct object_id *dst, const struct object_id *src) @@ -62,11 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst, dst->algo = src->algo; } -static inline void hashclr(unsigned char *hash) -{ - memset(hash, 0, the_hash_algo->rawsz); -} - static inline void oidclr(struct object_id *oid) { memset(oid->hash, 0, GIT_MAX_RAWSZ); |