]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hashmap_put takes "struct hashmap_entry *"
authorEric Wong <e@80x24.org>
Sun, 6 Oct 2019 23:30:32 +0000 (23:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2019 01:20:10 +0000 (10:20 +0900)
This is less error-prone than "void *" as the compiler now
detects invalid types being passed.

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c
hashmap.c
hashmap.h
merge-recursive.c
oidmap.c
refs.c
remote.c
revision.c
sequencer.c
submodule-config.c
t/helper/test-hashmap.c

index c693cf6a8c95f9b9592696a8ef6be8a9b55354cf..192e21dae40e99bfa0aea3c00644f297aa7e421b 100644 (file)
@@ -160,7 +160,7 @@ static const void *anonymize_mem(struct hashmap *map,
                ret->orig_len = *len;
                ret->anon = generate(orig, len);
                ret->anon_len = *len;
-               hashmap_put(map, ret);
+               hashmap_put(map, &ret->hash);
        }
 
        *len = ret->anon_len;
index bdf33e0381a91cbe7d720faadb8a9bb7abaf22fb..9b83e73d03346f18073a42547ba20f9983e02ac4 100644 (file)
--- a/hashmap.c
+++ b/hashmap.c
@@ -241,7 +241,7 @@ void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
        return old;
 }
 
-void *hashmap_put(struct hashmap *map, void *entry)
+void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry)
 {
        struct hashmap_entry *old = hashmap_remove(map, entry, NULL);
        hashmap_add(map, entry);
index c4c31b462f95b893fb60bf76d285d37d2ffa80b6..d122c75d0f13ef61a1462e0188b1a5a871d1de6c 100644 (file)
--- a/hashmap.h
+++ b/hashmap.h
@@ -340,7 +340,7 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
  * `entry` is the entry to add or replace.
  * Returns the replaced entry, or NULL if not found (i.e. the entry was added).
  */
-void *hashmap_put(struct hashmap *map, void *entry);
+void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry);
 
 /*
  * Removes a hashmap entry matching the specified key. If the hashmap contains
index f60451d396f203d506096d112b51ec66fd54a675..a685b4fb6982b8892ec74eec741bec202b54e843 100644 (file)
@@ -2229,7 +2229,7 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs)
                if (!entry) {
                        entry = xmalloc(sizeof(*entry));
                        dir_rename_entry_init(entry, old_dir);
-                       hashmap_put(dir_renames, entry);
+                       hashmap_put(dir_renames, &entry->ent);
                } else {
                        free(old_dir);
                }
@@ -2360,7 +2360,7 @@ static void compute_collisions(struct hashmap *collisions,
                                                sizeof(struct collision_entry));
                        hashmap_entry_init(&collision_ent->ent,
                                                strhash(new_path));
-                       hashmap_put(collisions, collision_ent);
+                       hashmap_put(collisions, &collision_ent->ent);
                        collision_ent->target_file = new_path;
                } else {
                        free(new_path);
index 6d6e840d037657721a5aa975e2567c8415547d93..cd22b3a8bf4b745253c2539867611de3e455acd6 100644 (file)
--- a/oidmap.c
+++ b/oidmap.c
@@ -51,5 +51,5 @@ void *oidmap_put(struct oidmap *map, void *entry)
                oidmap_init(map, 0);
 
        hashmap_entry_init(&to_put->internal_entry, oidhash(&to_put->oid));
-       return hashmap_put(&map->map, to_put);
+       return hashmap_put(&map->map, &to_put->internal_entry);
 }
diff --git a/refs.c b/refs.c
index c43ec59c6e845d55848c6e8474e6a54f2022b222..3e5503125666abeaa0fa99c14bf91bc0011b7c3d 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1863,10 +1863,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);
 }
 
index bd81cb71bc1fcdb894f72ee5ee39325d2bca2062..8ca23d95dc9008c1d214cb9048ae8a4f840c1cd6 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -159,7 +159,7 @@ static struct remote *make_remote(const char *name, int len)
        remotes[remotes_nr++] = ret;
 
        hashmap_entry_init(&ret->ent, lookup_entry.hash);
-       replaced = hashmap_put(&remotes_hash, ret);
+       replaced = hashmap_put(&remotes_hash, &ret->ent);
        assert(replaced == NULL);  /* no previous entry overwritten */
        return ret;
 }
index 4336281286476074a479b9a601cfab783435245d..a7e23390640d0d09582678275d849c7efb968b0c 100644 (file)
@@ -153,7 +153,7 @@ static void paths_and_oids_insert(struct hashmap *map,
                hashmap_entry_init(&entry->ent, hash);
                entry->path = xstrdup(key.path);
                oidset_init(&entry->trees, 16);
-               hashmap_put(map, entry);
+               hashmap_put(map, &entry->ent);
        }
 
        oidset_insert(&entry->trees, oid);
index ee11cda7e79155d737a731e67b4e1ea7c83584dc..b4ef70e26063c50e887d20fda90a7b248738866d 100644 (file)
@@ -5254,7 +5254,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
                        entry->i = i;
                        hashmap_entry_init(&entry->entry,
                                        strhash(entry->subject));
-                       hashmap_put(&subject2item, entry);
+                       hashmap_put(&subject2item, &entry->entry);
                }
        }
 
index 7486745a6a091353d94b5f219648b7727395cbe3..9248c5ea5b3c7cb298854adb75ec343dca74805b 100644 (file)
@@ -125,7 +125,7 @@ static void cache_put_path(struct submodule_cache *cache,
        struct submodule_entry *e = xmalloc(sizeof(*e));
        hashmap_entry_init(&e->ent, hash);
        e->config = submodule;
-       hashmap_put(&cache->for_path, e);
+       hashmap_put(&cache->for_path, &e->ent);
 }
 
 static void cache_remove_path(struct submodule_cache *cache,
index 49e715f1cd1392e95c3095d067babdb473e02237..de2bd083b9b1f630450bc9ba9a2c308f9a3cc1aa 100644 (file)
@@ -187,7 +187,7 @@ int cmd__hashmap(int argc, const char **argv)
                        entry = alloc_test_entry(hash, p1, p2);
 
                        /* add / replace entry */
-                       entry = hashmap_put(&map, entry);
+                       entry = hashmap_put(&map, &entry->ent);
 
                        /* print and free replaced entry, if any */
                        puts(entry ? get_value(entry) : "NULL");