From: Karsten Blees <karsten.blees@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Karsten Blees <karsten.blees@gmail.com>
Subject: [PATCH v3 07/11] name-hash.c: remove unreferenced directory entries
Date: Tue, 01 Oct 2013 11:38:26 +0200 [thread overview]
Message-ID: <524A9812.9070101@gmail.com> (raw)
In-Reply-To: <524A96FF.5090604@gmail.com>
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>
---
name-hash.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/name-hash.c b/name-hash.c
index aa57666..ce54fb3 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -85,15 +85,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)
{
/*
- * Release reference to the directory entry (and parents if 0).
- *
- * 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.
+ * Release reference to the directory entry. If 0, remove and continue
+ * with parent directory.
*/
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
- while (dir && dir->nr && !(--dir->nr))
- dir = dir->parent;
+ while (dir && !(--dir->nr)) {
+ 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)
--
1.8.4.11.g4f52745.dirty
next prev parent reply other threads:[~2013-10-01 9:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-01 9:33 [PATCH v3 00/11] New hash table implementation Karsten Blees
2013-10-01 9:34 ` [PATCH v3 01/11] add a hashtable implementation that supports O(1) removal Karsten Blees
2013-10-01 9:35 ` [PATCH v3 02/11] buitin/describe.c: use new hash map implementation Karsten Blees
2013-10-01 9:36 ` [PATCH v3 03/11] diffcore-rename.c: move code around to prepare for the next patch Karsten Blees
2013-10-01 9:36 ` [PATCH v3 04/11] diffcore-rename.c: simplify finding exact renames Karsten Blees
2013-10-01 9:37 ` [PATCH v3 05/11] diffcore-rename.c: use new hash map implementation Karsten Blees
2013-10-01 9:37 ` [PATCH v3 06/11] name-hash.c: use new hash map implementation for directories Karsten Blees
2013-10-01 9:38 ` Karsten Blees [this message]
2013-10-01 9:39 ` [PATCH v3 08/11] name-hash.c: use new hash map implementation for cache entries Karsten Blees
2013-10-01 9:39 ` [PATCH v3 09/11] name-hash.c: remove cache entries instead of marking them CE_UNHASHED Karsten Blees
2013-10-01 9:40 ` [PATCH v3 10/11] read-cache.c: fix memory leaks caused by removed cache entries Karsten Blees
2013-10-19 19:28 ` Thomas Rast
2013-10-22 13:13 ` [PATCH] fixup! read-cache.c: fix memory leaks caused by removed cache, entries Karsten Blees
2013-10-01 9:40 ` [PATCH v3 11/11] remove old hash.[ch] implementation Karsten Blees
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=524A9812.9070101@gmail.com \
--to=karsten.blees@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).