diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-10-15 13:48:01 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-10-15 13:48:02 +0900 |
commit | 5efabc7ed9e57bb73159d1ad7739c508167ef24a (patch) | |
tree | 9e7de3dfe38dcb92614d11613976d32151925ea2 /ref-filter.c | |
parent | Merge branch 'js/trace2-cap-max-output-files' (diff) | |
parent | hashmap_entry: remove first member requirement from docs (diff) | |
download | tgif-5efabc7ed9e57bb73159d1ad7739c508167ef24a.tar.xz |
Merge branch 'ew/hashmap'
Code clean-up of the hashmap API, both users and implementation.
* ew/hashmap:
hashmap_entry: remove first member requirement from docs
hashmap: remove type arg from hashmap_{get,put,remove}_entry
OFFSETOF_VAR macro to simplify hashmap iterators
hashmap: introduce hashmap_free_entries
hashmap: hashmap_{put,remove} return hashmap_entry *
hashmap: use *_entry APIs for iteration
hashmap_cmp_fn takes hashmap_entry params
hashmap_get{,_from_hash} return "struct hashmap_entry *"
hashmap: use *_entry APIs to wrap container_of
hashmap_get_next returns "struct hashmap_entry *"
introduce container_of macro
hashmap_put takes "struct hashmap_entry *"
hashmap_remove takes "const struct hashmap_entry *"
hashmap_get takes "const struct hashmap_entry *"
hashmap_add takes "struct hashmap_entry *"
hashmap_get_next takes "const struct hashmap_entry *"
hashmap_entry_init takes "struct hashmap_entry *"
packfile: use hashmap_entry in delta_base_cache_entry
coccicheck: detect hashmap_entry.hash assignment
diff: use hashmap_entry_init on moved_entry.ent
Diffstat (limited to 'ref-filter.c')
-rw-r--r-- | ref-filter.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/ref-filter.c b/ref-filter.c index 220e9bd74a..6867e33648 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -79,17 +79,20 @@ static struct expand_data { } oi, oi_deref; struct ref_to_worktree_entry { - struct hashmap_entry ent; /* must be the first member! */ + struct hashmap_entry ent; struct worktree *wt; /* key is wt->head_ref */ }; static int ref_to_worktree_map_cmpfnc(const void *unused_lookupdata, - const void *existing_hashmap_entry_to_test, - const void *key, + const struct hashmap_entry *eptr, + const struct hashmap_entry *kptr, const void *keydata_aka_refname) { - const struct ref_to_worktree_entry *e = existing_hashmap_entry_to_test; - const struct ref_to_worktree_entry *k = key; + const struct ref_to_worktree_entry *e, *k; + + e = container_of(eptr, const struct ref_to_worktree_entry, ent); + k = container_of(kptr, const struct ref_to_worktree_entry, ent); + return strcmp(e->wt->head_ref, keydata_aka_refname ? keydata_aka_refname : k->wt->head_ref); } @@ -1565,9 +1568,10 @@ static void populate_worktree_map(struct hashmap *map, struct worktree **worktre struct ref_to_worktree_entry *entry; entry = xmalloc(sizeof(*entry)); entry->wt = worktrees[i]; - hashmap_entry_init(entry, strhash(worktrees[i]->head_ref)); + hashmap_entry_init(&entry->ent, + strhash(worktrees[i]->head_ref)); - hashmap_add(map, entry); + hashmap_add(map, &entry->ent); } } } @@ -1584,18 +1588,20 @@ static void lazy_init_worktree_map(void) static char *get_worktree_path(const struct used_atom *atom, const struct ref_array_item *ref) { - struct hashmap_entry entry; + struct hashmap_entry entry, *e; struct ref_to_worktree_entry *lookup_result; lazy_init_worktree_map(); hashmap_entry_init(&entry, strhash(ref->refname)); - lookup_result = hashmap_get(&(ref_to_worktree_map.map), &entry, ref->refname); + e = hashmap_get(&(ref_to_worktree_map.map), &entry, ref->refname); - if (lookup_result) - return xstrdup(lookup_result->wt->path); - else + if (!e) return xstrdup(""); + + lookup_result = container_of(e, struct ref_to_worktree_entry, ent); + + return xstrdup(lookup_result->wt->path); } /* @@ -2166,7 +2172,8 @@ void ref_array_clear(struct ref_array *array) used_atom_cnt = 0; if (ref_to_worktree_map.worktrees) { - hashmap_free(&(ref_to_worktree_map.map), 1); + hashmap_free_entries(&(ref_to_worktree_map.map), + struct ref_to_worktree_entry, ent); free_worktrees(ref_to_worktree_map.worktrees); ref_to_worktree_map.worktrees = NULL; } |