hashmap_add takes "struct hashmap_entry *"

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>

Eric Wong committed Oct 6, 2019 at 23:30 UTC b94e5c1df674eb4ec8fdeaaae1ad8df552cb5d70
20 files changed +31 -31
attr.c
+1 -1
@@ -122,7 +122,7 @@ static void attr_hashmap_add(struct attr_hashmap *map,
122 e->keylen = keylen;
123 e->value = value;
124
125 - hashmap_add(&map->map, e);
125 + hashmap_add(&map->map, &e->ent);
126 }
127
128 struct all_attrs_item {
blame.c
+1 -1
@@ -424,7 +424,7 @@ static void get_fingerprint(struct fingerprint *result,
424 found_entry->count += 1;
425 } else {
426 entry->count = 1;
427 - hashmap_add(&result->map, entry);
427 + hashmap_add(&result->map, &entry->entry);
428 ++entry;
429 }
430 }
builtin/describe.c
+1 -1
@@ -124,7 +124,7 @@ static void add_to_known_names(const char *path,
124 e = xmalloc(sizeof(struct commit_name));
125 oidcpy(&e->peeled, peeled);
126 hashmap_entry_init(&e->entry, oidhash(peeled));
127 - hashmap_add(&names, e);
127 + hashmap_add(&names, &e->entry);
128 e->path = NULL;
129 }
130 e->tag = tag;
builtin/difftool.c
+3 -3
@@ -168,7 +168,7 @@ static void add_left_or_right(struct hashmap *map, const char *path,
168 e = existing;
169 } else {
170 e->left[0] = e->right[0] = '\0';
171 - hashmap_add(map, e);
171 + hashmap_add(map, &e->entry);
172 }
173 strlcpy(is_right ? e->right : e->left, content, PATH_MAX);
174 }
@@ -235,7 +235,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
235 struct path_entry *entry;
236 FLEX_ALLOC_STR(entry, path, buf.buf);
237 hashmap_entry_init(&entry->entry, strhash(buf.buf));
238 - hashmap_add(result, entry);
238 + hashmap_add(result, &entry->entry);
239 }
240 fclose(fp);
241 if (finish_command(&diff_files))
@@ -466,7 +466,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
466 free(entry);
467 continue;
468 }
469 - hashmap_add(&working_tree_dups, entry);
469 + hashmap_add(&working_tree_dups, &entry->entry);
470
471 if (!use_wt_file(workdir, dst_path, &roid)) {
472 if (checkout_path(rmode, &roid, dst_path,
builtin/fetch.c
+1 -1
@@ -278,7 +278,7 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map,
278 FLEX_ALLOC_MEM(ent, refname, refname, len);
279 hashmap_entry_init(&ent->ent, strhash(refname));
280 oidcpy(&ent->oid, oid);
281 - hashmap_add(map, ent);
281 + hashmap_add(map, &ent->ent);
282 return ent;
283 }
284
config.c
+1 -1
@@ -1885,7 +1885,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
1885 hashmap_entry_init(&e->ent, strhash(key));
1886 e->key = xstrdup(key);
1887 string_list_init(&e->value_list, 1);
1888 - hashmap_add(&cs->config_hash, e);
1888 + hashmap_add(&cs->config_hash, &e->ent);
1889 }
1890 si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));
1891
diff.c
+1 -1
@@ -1003,7 +1003,7 @@ static void add_lines_to_move_detection(struct diff_options *o,
1003 if (prev_line && prev_line->es->s == o->emitted_symbols->buf[n].s)
1004 prev_line->next_line = key;
1005
1006 - hashmap_add(hm, key);
1006 + hashmap_add(hm, &key->ent);
1007 prev_line = key;
1008 }
1009 }
diffcore-rename.c
+1 -1
@@ -330,7 +330,7 @@ static void insert_file_table(struct repository *r,
330 entry->filespec = filespec;
331
332 hashmap_entry_init(&entry->entry, hash_filespec(r, filespec));
333 - hashmap_add(table, entry);
333 + hashmap_add(table, &entry->entry);
334 }
335
336 /*
hashmap.c
+3 -3
@@ -201,12 +201,12 @@ void *hashmap_get_next(const struct hashmap *map,
201 return NULL;
202 }
203
204 -void hashmap_add(struct hashmap *map, void *entry)
204 +void hashmap_add(struct hashmap *map, struct hashmap_entry *entry)
205 {
206 unsigned int b = bucket(map, entry);
207
208 /* add entry */
209 - ((struct hashmap_entry *) entry)->next = map->table[b];
209 + entry->next = map->table[b];
210 map->table[b] = entry;
211
212 /* fix size and rehash if appropriate */
@@ -302,7 +302,7 @@ const void *memintern(const void *data, size_t len)
302 FLEX_ALLOC_MEM(e, data, data, len);
303 hashmap_entry_init(&e->ent, key.ent.hash);
304 e->len = len;
305 - hashmap_add(&map, e);
305 + hashmap_add(&map, &e->ent);
306 }
307 return e->data;
308 }
hashmap.h
+2 -2
@@ -50,7 +50,7 @@
50 * FLEX_ALLOC_STR(e, value, value);
51 * hashmap_entry_init(&e->ent, memhash(&key, sizeof(long)));
52 * e->key = key;
53 - * hashmap_add(&map, e);
53 + * hashmap_add(&map, &e->ent);
54 * }
55 *
56 * if (!strcmp("print_all_by_key", action)) {
@@ -328,7 +328,7 @@ void *hashmap_get_next(const struct hashmap *map,
328 * `map` is the hashmap structure.
329 * `entry` is the entry to add.
330 */
331 -void hashmap_add(struct hashmap *map, void *entry);
331 +void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
332
333 /*
334 * Adds or replaces a hashmap entry. If the hashmap contains duplicate
merge-recursive.c
+2 -2
@@ -455,7 +455,7 @@ static int save_files_dirs(const struct object_id *oid,
455
456 FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
457 hashmap_entry_init(&entry->e, path_hash(entry->path));
458 - hashmap_add(&opt->current_file_dir_set, entry);
458 + hashmap_add(&opt->current_file_dir_set, &entry->e);
459
460 strbuf_setlen(base, baselen);
461 return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@ -732,7 +732,7 @@ static char *unique_path(struct merge_options *opt, const char *path, const char
732
733 FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
734 hashmap_entry_init(&entry->e, path_hash(entry->path));
735 - hashmap_add(&opt->current_file_dir_set, entry);
735 + hashmap_add(&opt->current_file_dir_set, &entry->e);
736 return strbuf_detach(&newpath, NULL);
737 }
738
name-hash.c
+4 -4
@@ -70,7 +70,7 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
70 FLEX_ALLOC_MEM(dir, name, ce->name, namelen);
71 hashmap_entry_init(&dir->ent, memihash(ce->name, namelen));
72 dir->namelen = namelen;
73 - hashmap_add(&istate->dir_hash, dir);
73 + hashmap_add(&istate->dir_hash, &dir->ent);
74
75 /* recursively add missing parent directories */
76 dir->parent = hash_dir_entry(istate, ce, namelen);
@@ -107,7 +107,7 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
107 return;
108 ce->ce_flags |= CE_HASHED;
109 hashmap_entry_init(&ce->ent, memihash(ce->name, ce_namelen(ce)));
110 - hashmap_add(&istate->name_hash, ce);
110 + hashmap_add(&istate->name_hash, &ce->ent);
111
112 if (ignore_case)
113 add_dir_entry(istate, ce);
@@ -283,7 +283,7 @@ static struct dir_entry *hash_dir_entry_with_parent_and_prefix(
283 hashmap_entry_init(&dir->ent, hash);
284 dir->namelen = prefix->len;
285 dir->parent = parent;
286 - hashmap_add(&istate->dir_hash, dir);
286 + hashmap_add(&istate->dir_hash, &dir->ent);
287
288 if (parent) {
289 unlock_dir_mutex(lock_nr);
@@ -473,7 +473,7 @@ static void *lazy_name_thread_proc(void *_data)
473 struct cache_entry *ce_k = d->istate->cache[k];
474 ce_k->ce_flags |= CE_HASHED;
475 hashmap_entry_init(&ce_k->ent, d->lazy_entries[k].hash_name);
476 - hashmap_add(&d->istate->name_hash, ce_k);
476 + hashmap_add(&d->istate->name_hash, &ce_k->ent);
477 }
478
479 return NULL;
packfile.c
+1 -1
@@ -1488,7 +1488,7 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
1488 if (!delta_base_cache.cmpfn)
1489 hashmap_init(&delta_base_cache, delta_base_cache_hash_cmp, NULL, 0);
1490 hashmap_entry_init(&ent->ent, pack_entry_hash(p, base_offset));
1491 - hashmap_add(&delta_base_cache, ent);
1491 + hashmap_add(&delta_base_cache, &ent->ent);
1492 }
1493
1494 int packed_object_info(struct repository *r, struct packed_git *p,
patch-ids.c
+1 -1
@@ -116,6 +116,6 @@ struct patch_id *add_commit_patch_id(struct commit *commit,
116 return NULL;
117 }
118
119 - hashmap_add(&ids->patches, key);
119 + hashmap_add(&ids->patches, &key->ent);
120 return key;
121 }
range-diff.c
+1 -1
@@ -218,7 +218,7 @@ static void find_exact_matches(struct string_list *a, struct string_list *b)
218 util->patch = a->items[i].string;
219 util->diff = util->patch + util->diff_offset;
220 hashmap_entry_init(&util->e, strhash(util->diff));
221 - hashmap_add(&map, util);
221 + hashmap_add(&map, &util->e);
222 }
223
224 /* Now try to find exact matches in b */
ref-filter.c
+1 -1
@@ -1568,7 +1568,7 @@ static void populate_worktree_map(struct hashmap *map, struct worktree **worktre
1568 hashmap_entry_init(&entry->ent,
1569 strhash(worktrees[i]->head_ref));
1570
1571 - hashmap_add(map, entry);
1571 + hashmap_add(map, &entry->ent);
1572 }
1573 }
1574 }
sequencer.c
+1 -1
@@ -4539,7 +4539,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
4539
4540 FLEX_ALLOC_STR(labels_entry, label, label);
4541 hashmap_entry_init(&labels_entry->entry, strihash(label));
4542 - hashmap_add(&state->labels, labels_entry);
4542 + hashmap_add(&state->labels, &labels_entry->entry);
4543
4544 FLEX_ALLOC_STR(string_entry, string, label);
4545 oidcpy(&string_entry->entry.oid, oid);
sub-process.c
+1 -1
@@ -105,7 +105,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
105 return err;
106 }
107
108 - hashmap_add(hashmap, entry);
108 + hashmap_add(hashmap, &entry->ent);
109 return 0;
110 }
111
submodule-config.c
+1 -1
@@ -149,7 +149,7 @@ static void cache_add(struct submodule_cache *cache,
149 struct submodule_entry *e = xmalloc(sizeof(*e));
150 hashmap_entry_init(&e->ent, hash);
151 e->config = submodule;
152 - hashmap_add(&cache->for_name, e);
152 + hashmap_add(&cache->for_name, &e->ent);
153 }
154
155 static const struct submodule *cache_lookup_path(struct submodule_cache *cache,
t/helper/test-hashmap.c
+3 -3
@@ -104,7 +104,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
104 /* add entries */
105 for (i = 0; i < TEST_SIZE; i++) {
106 hashmap_entry_init(&entries[i]->ent, hashes[i]);
107 - hashmap_add(&map, entries[i]);
107 + hashmap_add(&map, &entries[i]->ent);
108 }
109
110 hashmap_free(&map, 0);
@@ -117,7 +117,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
117 j = (method & TEST_SPARSE) ? TEST_SIZE / 10 : TEST_SIZE;
118 for (i = 0; i < j; i++) {
119 hashmap_entry_init(&entries[i]->ent, hashes[i]);
120 - hashmap_add(&map, entries[i]);
120 + hashmap_add(&map, &entries[i]->ent);
121 }
122
123 for (j = 0; j < rounds; j++) {
@@ -179,7 +179,7 @@ int cmd__hashmap(int argc, const char **argv)
179 entry = alloc_test_entry(hash, p1, p2);
180
181 /* add to hashmap */
182 - hashmap_add(&map, entry);
182 + hashmap_add(&map, &entry->ent);
183
184 } else if (!strcmp("put", cmd) && p1 && p2) {
185