name-hash.c: remove unreferenced directory entries
The new hashmap implementation supports remove, so remove and free directory entries that are no longer referenced by active cache entries. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karsten Blees committed
Nov 14, 2013 at 20:21 UTC
1c8cca190a1029d16450e61fbc4ce6f85a867f30
1 file changed
+8
-7
name-hash.c
+8
-7
@@ -86,15 +86,16 @@ static void add_dir_entry(struct index_state *istate, struct cache_entry *ce)
86
static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
87
{
88
/*
89
- * Release reference to the directory entry (and parents if 0).
90
- *
91
- * Note: we do not remove / free the entry because there's no
92
- * hash.[ch]::remove_hash and dir->next may point to other entries
93
- * that are still valid, so we must not free the memory.
89
+ * Release reference to the directory entry. If 0, remove and continue
90
+ * with parent directory.
91
*/
92
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
96
- while (dir && dir->nr && !(--dir->nr))
97
- dir = dir->parent;
93
+ while (dir && !(--dir->nr)) {
94
+ struct dir_entry *parent = dir->parent;
95
+ hashmap_remove(&istate->dir_hash, dir, NULL);
96
+ free(dir);
97
+ dir = parent;
98
+ }
99
}
100
101
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)