hashmap: convert sha1hash() to oidhash()

There are no callers left of sha1hash() that do not simply pass the "hash" member of a "struct object_id". Let's get rid of the outdated sha1-specific function and provide one that operates on the whole struct (even though the technique, taking the first few bytes of the hash, will remain the same). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 20, 2019 at 03:41 UTC d40abc8e95f75b529feb140178b69a3783c2d108
8 files changed +13 -11
builtin/describe.c
+2 -2
@@ -76,7 +76,7 @@ static int commit_name_neq(const void *unused_cmp_data,
76
77 static inline struct commit_name *find_commit_name(const struct object_id *peeled)
78 {
79 - return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled);
79 + return hashmap_get_from_hash(&names, oidhash(peeled), peeled);
80 }
81
82 static int replace_name(struct commit_name *e,
@@ -123,7 +123,7 @@ static void add_to_known_names(const char *path,
123 if (!e) {
124 e = xmalloc(sizeof(struct commit_name));
125 oidcpy(&e->peeled, peeled);
126 - hashmap_entry_init(e, sha1hash(peeled->hash));
126 + hashmap_entry_init(e, oidhash(peeled));
127 hashmap_add(&names, e);
128 e->path = NULL;
129 }
decorate.c
+1 -1
@@ -8,7 +8,7 @@
8
9 static unsigned int hash_obj(const struct object *obj, unsigned int n)
10 {
11 - return sha1hash(obj->oid.hash) % n;
11 + return oidhash(&obj->oid) % n;
12 }
13
14 static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)
diffcore-rename.c
+1 -1
@@ -266,7 +266,7 @@ static unsigned int hash_filespec(struct repository *r,
266 hash_object_file(filespec->data, filespec->size, "blob",
267 &filespec->oid);
268 }
269 - return sha1hash(filespec->oid.hash);
269 + return oidhash(&filespec->oid);
270 }
271
272 static int find_identical_files(struct hashmap *srcs,
hashmap.h
+5 -3
@@ -1,6 +1,8 @@
1 #ifndef HASHMAP_H
2 #define HASHMAP_H
3
4 +#include "hash.h"
5 +
6 /*
7 * Generic implementation of hash-based key-value mappings.
8 *
@@ -118,14 +120,14 @@ unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
120 * the results will be different on big-endian and little-endian
121 * platforms, so they should not be stored or transferred over the net.
122 */
121 -static inline unsigned int sha1hash(const unsigned char *sha1)
123 +static inline unsigned int oidhash(const struct object_id *oid)
124 {
125 /*
124 - * Equivalent to 'return *(unsigned int *)sha1;', but safe on
126 + * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
127 * platforms that don't support unaligned reads.
128 */
129 unsigned int hash;
128 - memcpy(&hash, sha1, sizeof(hash));
130 + memcpy(&hash, oid->hash, sizeof(hash));
131 return hash;
132 }
133
khash.h
+1 -1
@@ -326,7 +326,7 @@ static const double __ac_HASH_UPPER = 0.77;
326
327 static inline unsigned int oidhash_by_value(struct object_id oid)
328 {
329 - return sha1hash(oid.hash);
329 + return oidhash(&oid);
330 }
331
332 static inline int oideq_by_value(struct object_id a, struct object_id b)
object.c
+1 -1
@@ -61,7 +61,7 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
61 */
62 static unsigned int hash_obj(const struct object_id *oid, unsigned int n)
63 {
64 - return sha1hash(oid->hash) & (n - 1);
64 + return oidhash(oid) & (n - 1);
65 }
66
67 /*
pack-objects.c
+1 -1
@@ -11,7 +11,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata,
11 {
12 uint32_t i, mask = (pdata->index_size - 1);
13
14 - i = sha1hash(oid->hash) & mask;
14 + i = oidhash(oid) & mask;
15
16 while (pdata->index[i] > 0) {
17 uint32_t pos = pdata->index[i] - 1;
patch-ids.c
+1 -1
@@ -83,7 +83,7 @@ static int init_patch_id_entry(struct patch_id *patch,
83 if (commit_patch_id(commit, &ids->diffopts, &header_only_patch_id, 1, 0))
84 return -1;
85
86 - hashmap_entry_init(patch, sha1hash(header_only_patch_id.hash));
86 + hashmap_entry_init(patch, oidhash(&header_only_patch_id));
87 return 0;
88 }
89