X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fgit.git;a=blobdiff_plain;f=refs.c;h=1ab0bb54d3d73bfe17f0eab4cd02d760bb9a7d01;hp=cd297ee4bdbe48b04696ddf923273a857ce59884;hb=12a4aeaad8aa2071f9b20f6ac87454c5f6d2d4fb;hpb=a477abe9e4bdf1dd3627c20b69ed8b51f27c2f81 diff --git a/refs.c b/refs.c index cd297ee4bd..1ab0bb54d3 100644 --- a/refs.c +++ b/refs.c @@ -1772,7 +1772,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname, struct ref_store_hash_entry { - struct hashmap_entry ent; /* must be the first member! */ + struct hashmap_entry ent; struct ref_store *refs; @@ -1781,11 +1781,16 @@ struct ref_store_hash_entry }; static int ref_store_hash_cmp(const void *unused_cmp_data, - const void *entry, const void *entry_or_key, + const struct hashmap_entry *eptr, + const struct hashmap_entry *entry_or_key, const void *keydata) { - const struct ref_store_hash_entry *e1 = entry, *e2 = entry_or_key; - const char *name = keydata ? keydata : e2->name; + const struct ref_store_hash_entry *e1, *e2; + const char *name; + + e1 = container_of(eptr, const struct ref_store_hash_entry, ent); + e2 = container_of(entry_or_key, const struct ref_store_hash_entry, ent); + name = keydata ? keydata : e2->name; return strcmp(e1->name, name); } @@ -1796,7 +1801,7 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry( struct ref_store_hash_entry *entry; FLEX_ALLOC_STR(entry, name, name); - hashmap_entry_init(entry, strhash(name)); + hashmap_entry_init(&entry->ent, strhash(name)); entry->refs = refs; return entry; } @@ -1815,12 +1820,15 @@ static struct ref_store *lookup_ref_store_map(struct hashmap *map, const char *name) { struct ref_store_hash_entry *entry; + unsigned int hash; if (!map->tablesize) /* It's initialized on demand in register_ref_store(). */ return NULL; - entry = hashmap_get_from_hash(map, strhash(name), name); + hash = strhash(name); + entry = hashmap_get_entry_from_hash(map, hash, name, + struct ref_store_hash_entry, ent); return entry ? entry->refs : NULL; } @@ -1863,10 +1871,13 @@ static void register_ref_store_map(struct hashmap *map, struct ref_store *refs, const char *name) { + struct ref_store_hash_entry *entry; + if (!map->tablesize) hashmap_init(map, ref_store_hash_cmp, NULL, 0); - if (hashmap_put(map, alloc_ref_store_hash_entry(name, refs))) + entry = alloc_ref_store_hash_entry(name, refs); + if (hashmap_put(map, &entry->ent)) BUG("%s ref_store '%s' initialized twice", type, name); }