mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
129cb1b99d
commit
f4836570a7
24
hash.h
24
hash.h
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user