Skip to content

Commit 1c8cca1

Browse files
kbleesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e05881a commit 1c8cca1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

name-hash.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ static void add_dir_entry(struct index_state *istate, struct cache_entry *ce)
8686
static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
8787
{
8888
/*
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.
9491
*/
9592
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+
}
9899
}
99100

100101
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)

0 commit comments

Comments
 (0)