summaryrefslogtreecommitdiff
path: root/src/diff.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-08-30 14:24:16 -0700
committerRussell Belfer <rb@github.com>2012-09-05 15:17:24 -0700
commitf335ecd6e126aa9dea28786522c0e6ce71596e91 (patch)
tree3393df3457e423ddc1aaad4d89fb29184246f3a8 /src/diff.c
parent4d3834038bd0aaef63d62c54900f6ddafec09515 (diff)
downloadlibgit2-f335ecd6e126aa9dea28786522c0e6ce71596e91.tar.gz
Diff iterators
This refactors the diff output code so that an iterator object can be used to traverse and generate the diffs, instead of just the `foreach()` style with callbacks. The code has been rearranged so that the two styles can still share most functions. This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses that as a common error code for marking the end of iteration when using a iterator style of object.
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/diff.c b/src/diff.c
index 430f52e0..f8a01086 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -316,6 +316,7 @@ static git_diff_list *git_diff_list_alloc(
if (diff == NULL)
return NULL;
+ GIT_REFCOUNT_INC(diff);
diff->repo = repo;
if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < 0 ||
@@ -391,15 +392,12 @@ fail:
return NULL;
}
-void git_diff_list_free(git_diff_list *diff)
+static void diff_list_free(git_diff_list *diff)
{
git_diff_delta *delta;
git_attr_fnmatch *match;
unsigned int i;
- if (!diff)
- return;
-
git_vector_foreach(&diff->deltas, i, delta) {
git__free(delta);
diff->deltas.contents[i] = NULL;
@@ -416,6 +414,14 @@ void git_diff_list_free(git_diff_list *diff)
git__free(diff);
}
+void git_diff_list_free(git_diff_list *diff)
+{
+ if (!diff)
+ return;
+
+ GIT_REFCOUNT_DEC(diff, diff_list_free);
+}
+
static int oid_for_workdir_item(
git_repository *repo,
const git_index_entry *item,