summaryrefslogtreecommitdiff
path: root/src/annotated_commit.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-11-10 21:21:26 -0800
committerEdward Thomson <ethomson@microsoft.com>2015-11-25 15:38:16 -0500
commit76ade3a0b87e279935eba54be2485105396edb7f (patch)
tree9a8310a2645ccca8074d2357ab07baf1bb9ffb87 /src/annotated_commit.c
parent7730fe8e9cda1e160bff1e78dfa2a898799d4365 (diff)
downloadlibgit2-76ade3a0b87e279935eba54be2485105396edb7f.tar.gz
merge: use annotated commits for recursion
Use annotated commits to act as our virtual bases, instead of regular commits, to avoid polluting the odb with virtual base commits and trees. Instead, build an annotated commit with an index and pointers to the commits that it was merged from.
Diffstat (limited to 'src/annotated_commit.c')
-rw-r--r--src/annotated_commit.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/annotated_commit.c b/src/annotated_commit.c
index 3998a1af1..e53b95dee 100644
--- a/src/annotated_commit.c
+++ b/src/annotated_commit.c
@@ -15,6 +15,8 @@
#include "git2/repository.h"
#include "git2/annotated_commit.h"
#include "git2/revparse.h"
+#include "git2/tree.h"
+#include "git2/index.h"
static int annotated_commit_init(
git_annotated_commit **out,
@@ -108,6 +110,8 @@ int git_annotated_commit_from_commit(
annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
GITERR_CHECK_ALLOC(annotated_commit);
+ annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL;
+
git_cached_obj_incref(commit);
annotated_commit->commit = commit;
@@ -179,14 +183,20 @@ void git_annotated_commit_free(git_annotated_commit *annotated_commit)
if (annotated_commit == NULL)
return;
- if (annotated_commit->commit != NULL)
- git_commit_free(annotated_commit->commit);
-
- if (annotated_commit->ref_name != NULL)
- git__free(annotated_commit->ref_name);
-
- if (annotated_commit->remote_url != NULL)
- git__free(annotated_commit->remote_url);
+ switch (annotated_commit->type) {
+ case GIT_ANNOTATED_COMMIT_REAL:
+ git_commit_free(annotated_commit->commit);
+ git_tree_free(annotated_commit->tree);
+ git__free(annotated_commit->ref_name);
+ git__free(annotated_commit->remote_url);
+ break;
+ case GIT_ANNOTATED_COMMIT_VIRTUAL:
+ git_index_free(annotated_commit->index);
+ git_array_clear(annotated_commit->parents);
+ break;
+ default:
+ abort();
+ }
git__free(annotated_commit);
}