diff options
| author | Patrick Steinhardt <ps@pks.im> | 2017-03-14 13:06:25 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-03-14 13:08:51 +0100 |
| commit | 62a2fc06d4af781c456bf753d6ada16df682df55 (patch) | |
| tree | d5b9f617ecb11470462c584c6e7efb211491e09d /src/diff.c | |
| parent | ace3508f4c2ad7f821bc79d0b34e7ac55fac4d12 (diff) | |
| download | libgit2-62a2fc06d4af781c456bf753d6ada16df682df55.tar.gz | |
patch_generate: move `git_diff_foreach` to diff.c
Now that the `git_diff_foreach` function does not depend on internals of
the `git_patch_generated` structure anymore, we can easily move it to
the actual diff code.
Diffstat (limited to 'src/diff.c')
| -rw-r--r-- | src/diff.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/diff.c b/src/diff.c index 317d49597..a93bd4cd0 100644 --- a/src/diff.c +++ b/src/diff.c @@ -120,6 +120,41 @@ int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff) return 0; } +int git_diff_foreach( + git_diff *diff, + git_diff_file_cb file_cb, + git_diff_binary_cb binary_cb, + git_diff_hunk_cb hunk_cb, + git_diff_line_cb data_cb, + void *payload) +{ + int error = 0; + git_diff_delta *delta; + size_t idx; + + assert(diff); + + git_vector_foreach(&diff->deltas, idx, delta) { + git_patch *patch; + + /* check flags against patch status */ + if (git_diff_delta__should_skip(&diff->opts, delta)) + continue; + + if ((error = git_patch_from_diff(&patch, diff, idx)) != 0) + break; + + error = git_patch__invoke_callbacks(patch, file_cb, binary_cb, + hunk_cb, data_cb, payload); + git_patch_free(patch); + + if (error) + break; + } + + return error; +} + int git_diff_format_email__append_header_tobuf( git_buf *out, const git_oid *id, |
