summaryrefslogtreecommitdiff
path: root/src/tree.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-04-15 00:05:44 -0700
committerVicent Marti <tanoku@gmail.com>2013-04-22 16:51:40 +0200
commit786062639f05e361da977f3f1f6286141fa12fca (patch)
tree5dc63d86657681572376ef2bced9bb2cae8e2213 /src/tree.c
parent917f60c50bce09f789aeb927b45ba3bca5a23877 (diff)
downloadlibgit2-786062639f05e361da977f3f1f6286141fa12fca.tar.gz
Add callback to git_objects_table
This adds create and free callback to the git_objects_table so that more of the creation and destruction of objects can be table driven instead of using switch statements. This also makes the semantics of certain object creation functions consistent so that we can make better use of function pointers. This also fixes a theoretical error case where an object allocation fails and we end up storing NULL into the cache.
Diffstat (limited to 'src/tree.c')
-rw-r--r--src/tree.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/tree.c b/src/tree.c
index cc43b920c..e66fa2370 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -219,15 +219,16 @@ git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry)
return copy;
}
-void git_tree__free(git_tree *tree)
+void git_tree__free(void *tree)
{
+ git_vector *entries = &((git_tree *)tree)->entries;
size_t i;
git_tree_entry *e;
- git_vector_foreach(&tree->entries, i, e)
+ git_vector_foreach(entries, i, e)
git_tree_entry_free(e);
- git_vector_free(&tree->entries);
+ git_vector_free(entries);
git__free(tree);
}
@@ -371,10 +372,11 @@ static int tree_error(const char *str, const char *path)
return -1;
}
-static int tree_parse_buffer(
- git_tree *tree, const char *buffer, const char *buffer_end)
+int git_tree__parse(void *tree, const char *buffer, const char *buffer_end)
{
- if (git_vector_init(&tree->entries, DEFAULT_TREE_SIZE, entry_sort_cmp) < 0)
+ git_vector *tree_entries = &((git_tree *)tree)->entries;
+
+ if (git_vector_init(tree_entries, DEFAULT_TREE_SIZE, entry_sort_cmp) < 0)
return -1;
while (buffer < buffer_end) {
@@ -397,7 +399,7 @@ static int tree_parse_buffer(
entry = alloc_entry(buffer);
GITERR_CHECK_ALLOC(entry);
- if (git_vector_insert(&tree->entries, entry) < 0) {
+ if (git_vector_insert(tree_entries, entry) < 0) {
git__free(entry);
return -1;
}
@@ -417,17 +419,6 @@ static int tree_parse_buffer(
return 0;
}
-int git_tree__parse(git_tree *tree, git_odb_object *obj)
-{
- const char *buf;
-
- assert(tree && obj);
-
- buf = (const char *)git_odb_object_data(obj);
-
- return tree_parse_buffer(tree, buf, buf + git_odb_object_size(obj));
-}
-
static size_t find_next_dir(const char *dirname, git_index *index, size_t start)
{
size_t dirlen, i, entries = git_index_entrycount(index);