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
This commit is contained in:
@ -63,19 +63,22 @@ static const char *prio_names[] = {
|
||||
};
|
||||
|
||||
static int commit_name_neq(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 *peeled)
|
||||
{
|
||||
const struct commit_name *cn1 = entry;
|
||||
const struct commit_name *cn2 = entry_or_key;
|
||||
const struct commit_name *cn1, *cn2;
|
||||
|
||||
cn1 = container_of(eptr, const struct commit_name, entry);
|
||||
cn2 = container_of(entry_or_key, const struct commit_name, entry);
|
||||
|
||||
return !oideq(&cn1->peeled, peeled ? peeled : &cn2->peeled);
|
||||
}
|
||||
|
||||
static inline struct commit_name *find_commit_name(const struct object_id *peeled)
|
||||
{
|
||||
return hashmap_get_from_hash(&names, oidhash(peeled), peeled);
|
||||
return hashmap_get_entry_from_hash(&names, oidhash(peeled), peeled,
|
||||
struct commit_name, entry);
|
||||
}
|
||||
|
||||
static int replace_name(struct commit_name *e,
|
||||
@ -122,8 +125,8 @@ static void add_to_known_names(const char *path,
|
||||
if (!e) {
|
||||
e = xmalloc(sizeof(struct commit_name));
|
||||
oidcpy(&e->peeled, peeled);
|
||||
hashmap_entry_init(e, oidhash(peeled));
|
||||
hashmap_add(&names, e);
|
||||
hashmap_entry_init(&e->entry, oidhash(peeled));
|
||||
hashmap_add(&names, &e->entry);
|
||||
e->path = NULL;
|
||||
}
|
||||
e->tag = tag;
|
||||
@ -329,8 +332,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
|
||||
struct commit_name *n;
|
||||
|
||||
init_commit_names(&commit_names);
|
||||
n = hashmap_iter_first(&names, &iter);
|
||||
for (; n; n = hashmap_iter_next(&iter)) {
|
||||
hashmap_for_each_entry(&names, &iter, n,
|
||||
entry /* member name */) {
|
||||
c = lookup_commit_reference_gently(the_repository,
|
||||
&n->peeled, 1);
|
||||
if (c)
|
||||
|
||||
Reference in New Issue
Block a user