aboutsummaryrefslogtreecommitdiff
path: root/oidmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'oidmap.c')
-rw-r--r--oidmap.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/oidmap.c b/oidmap.c
index 508d6c7dec..a1ef53577f 100644
--- a/oidmap.c
+++ b/oidmap.c
@@ -24,11 +24,28 @@ void oidmap_init(struct oidmap *map, size_t initial_size)
void oidmap_clear(struct oidmap *map, int free_entries)
{
- if (!map)
+ oidmap_clear_with_free(map,
+ free_entries ? free : NULL);
+}
+
+void oidmap_clear_with_free(struct oidmap *map,
+ oidmap_free_fn free_fn)
+{
+ struct hashmap_iter iter;
+ struct hashmap_entry *e;
+
+ if (!map || !map->map.cmpfn)
return;
- /* TODO: make oidmap itself not depend on struct layouts */
- hashmap_clear_(&map->map, free_entries ? 0 : -1);
+ hashmap_iter_init(&map->map, &iter);
+ while ((e = hashmap_iter_next(&iter))) {
+ struct oidmap_entry *entry =
+ container_of(e, struct oidmap_entry, internal_entry);
+ if (free_fn)
+ free_fn(entry);
+ }
+
+ hashmap_clear(&map->map);
}
void *oidmap_get(const struct oidmap *map, const struct object_id *key)