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>
This commit is contained in:
parent
e05881a457
commit
1c8cca190a
15
name-hash.c
15
name-hash.c
@ -86,15 +86,16 @@ static void add_dir_entry(struct index_state *istate, struct cache_entry *ce)
|
|||||||
static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
|
static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Release reference to the directory entry (and parents if 0).
|
* Release reference to the directory entry. If 0, remove and continue
|
||||||
*
|
* with parent directory.
|
||||||
* Note: we do not remove / free the entry because there's no
|
|
||||||
* hash.[ch]::remove_hash and dir->next may point to other entries
|
|
||||||
* that are still valid, so we must not free the memory.
|
|
||||||
*/
|
*/
|
||||||
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
|
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
|
||||||
while (dir && dir->nr && !(--dir->nr))
|
while (dir && !(--dir->nr)) {
|
||||||
dir = dir->parent;
|
struct dir_entry *parent = dir->parent;
|
||||||
|
hashmap_remove(&istate->dir_hash, dir, NULL);
|
||||||
|
free(dir);
|
||||||
|
dir = parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
|
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
|
||||||
|
Loading…
Reference in New Issue
Block a user