diff options
author | Vicent Marti <tanoku@gmail.com> | 2010-08-12 23:40:54 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2010-08-12 23:40:54 +0200 |
commit | 9c9f4fc11c85d621dc5fdcf46bbcb5b5da9ed73f (patch) | |
tree | b74a41b8df31f0fc88809d1d479742b3f5b3c192 /src/hashtable.c | |
parent | f2408cc2efc1752bb34011a655f6acdab4e9e602 (diff) | |
download | libgit2-9c9f4fc11c85d621dc5fdcf46bbcb5b5da9ed73f.tar.gz |
Add support for manually freeing repo objects
A new method 'git_repository_object_free' allows to manually force the
freeing of a repository object, even though they are still automatically
managed by the repository and don't need to be freed by the user.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/hashtable.c')
-rw-r--r-- | src/hashtable.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/hashtable.c b/src/hashtable.c index 4006a8714..242a6fa1d 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -183,6 +183,37 @@ void *git_hashtable_lookup(git_hashtable *table, const void *key) return NULL; } +int git_hashtable_remove(git_hashtable *table, const void *key) +{ + git_hashtable_node *node, *prev_node; + uint32_t index, hash; + + assert(table); + + hash = table->hash(key); + index = (hash & table->size_mask); + node = table->nodes[index]; + + prev_node = NULL; + + while (node != NULL) { + if (node->hash == hash && table->key_equal(node->object, key)) { + if (prev_node == NULL) + table->nodes[index] = node->next; + else + prev_node->next = node->next; + + free(node); + return GIT_SUCCESS; + } + + prev_node = node; + node = node->next; + } + + return GIT_ENOTFOUND; +} + void git_hashtable_iterator_init(git_hashtable *table, git_hashtable_iterator *it) |