diff options
author | Russell Belfer <rb@github.com> | 2012-08-30 14:24:16 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-09-05 15:17:24 -0700 |
commit | f335ecd6e126aa9dea28786522c0e6ce71596e91 (patch) | |
tree | 3393df3457e423ddc1aaad4d89fb29184246f3a8 /src/diff.c | |
parent | 4d3834038bd0aaef63d62c54900f6ddafec09515 (diff) | |
download | libgit2-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.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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, |