Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2021-01-28 09:19:42 +0300
committerJunio C Hamano <gitster@pobox.com>2021-01-28 23:02:39 +0300
commit45ee13b942b26925b33d827bda2856e1ed0af0b7 (patch)
tree87f89914fdf93c8d3ef42411657c668680ccadcf /hash-lookup.c
parent680ff910b0329c8482f98ad9d3c49f4628c1bafa (diff)
hash_pos(): convert to oid_pos()
All of our callers are actually looking up an object_id, not a bare hash. Likewise, the arrays they are looking in are actual arrays of object_id (not just raw bytes of hashes, as we might find in a pack .idx; those are handled by bsearch_hash()). Using an object_id gives us more type safety, and makes the callers slightly shorter. It also gets rid of the word "sha1" from several access functions, though we could obviously also rename those with s/sha1/hash/. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash-lookup.c')
-rw-r--r--hash-lookup.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/hash-lookup.c b/hash-lookup.c
index 1191856a32..d15bb34574 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,9 +1,9 @@
#include "cache.h"
#include "hash-lookup.h"
-static uint32_t take2(const unsigned char *hash)
+static uint32_t take2(const struct object_id *oid, size_t ofs)
{
- return ((hash[0] << 8) | hash[1]);
+ return ((oid->hash[ofs] << 8) | oid->hash[ofs + 1]);
}
/*
@@ -47,11 +47,11 @@ static uint32_t take2(const unsigned char *hash)
*/
/*
* The table should contain "nr" elements.
- * The hash of element i (between 0 and nr - 1) should be returned
+ * The oid of element i (between 0 and nr - 1) should be returned
* by "fn(i, table)".
*/
-int hash_pos(const unsigned char *hash, void *table, size_t nr,
- hash_access_fn fn)
+int oid_pos(const struct object_id *oid, void *table, size_t nr,
+ oid_access_fn fn)
{
size_t hi = nr;
size_t lo = 0;
@@ -64,9 +64,9 @@ int hash_pos(const unsigned char *hash, void *table, size_t nr,
size_t lov, hiv, miv, ofs;
for (ofs = 0; ofs < the_hash_algo->rawsz - 2; ofs += 2) {
- lov = take2(fn(0, table) + ofs);
- hiv = take2(fn(nr - 1, table) + ofs);
- miv = take2(hash + ofs);
+ lov = take2(fn(0, table), ofs);
+ hiv = take2(fn(nr - 1, table), ofs);
+ miv = take2(oid, ofs);
if (miv < lov)
return -1;
if (hiv < miv)
@@ -88,7 +88,7 @@ int hash_pos(const unsigned char *hash, void *table, size_t nr,
do {
int cmp;
- cmp = hashcmp(fn(mi, table), hash);
+ cmp = oidcmp(fn(mi, table), oid);
if (!cmp)
return mi;
if (cmp > 0)