summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-02-28 16:51:17 +0200
committerVicent Marti <tanoku@gmail.com>2011-03-03 20:23:52 +0200
commit48c27f86bbe9678c7e01a90a2cec7a30327b0e90 (patch)
tree0156ea823de82477792ad4778378200eee28aee3 /src/commit.c
parent86d7e1ca6f54161a9e4d1ebe7a2f8e4802dc9639 (diff)
downloadlibgit2-48c27f86bbe9678c7e01a90a2cec7a30327b0e90.tar.gz
Implement reference counting for git_objects
All `git_object` instances looked up from the repository are reference counted. User is expected to use the new `git_object_close` when an object is no longer needed to force freeing it. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/commit.c b/src/commit.c
index 3eebb927..3edc5733 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -55,6 +55,8 @@ void git_commit__free(git_commit *commit)
git_signature_free(commit->author);
git_signature_free(commit->committer);
+ git_object_close((git_object *)commit->tree);
+
free(commit->message);
free(commit->message_short);
free(commit);
@@ -121,6 +123,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
if ((error = git__parse_oid(&oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS)
return error;
+ git_object_close((git_object *)commit->tree);
if ((error = git_object_lookup((git_object **)&commit->tree, commit->object.repo, &oid, GIT_OBJ_TREE)) < GIT_SUCCESS)
return error;
@@ -232,7 +235,21 @@ int git_commit__parse_full(git_commit *commit)
if (!commit->object.in_memory && !commit->full_parse)\
git_commit__parse_full(commit);
-GIT_COMMIT_GETTER(git_tree *, tree)
+const git_tree *git_commit_tree(git_commit *commit)
+{
+ assert(commit);
+
+ if (!commit->object.in_memory && commit->tree == NULL)
+ git_commit__parse_full(commit);
+
+ if (commit->tree) {
+ GIT_OBJECT_INCREF(commit->tree);
+ return commit->tree;
+ }
+
+ return NULL;
+}
+
GIT_COMMIT_GETTER(git_signature *, author)
GIT_COMMIT_GETTER(git_signature *, committer)
GIT_COMMIT_GETTER(char *, message)
@@ -267,6 +284,9 @@ void git_commit_set_tree(git_commit *commit, git_tree *tree)
assert(commit && tree);
commit->object.modified = 1;
CHECK_FULL_PARSE();
+
+ git_object_close((git_object *)commit->tree);
+ GIT_OBJECT_INCREF(tree);
commit->tree = tree;
}