mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 10:52:22 +00:00
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.
This commit is contained in:
parent
ace3508f4c
commit
62a2fc06d4
35
src/diff.c
35
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,
|
||||
|
@ -400,42 +400,6 @@ static int diff_required(git_diff *diff, const char *action)
|
||||
return -1;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if ((error = diff_required(diff, "git_diff_foreach")) < 0)
|
||||
return error;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
git_patch_generated patch;
|
||||
git_diff_delta delta;
|
||||
|
Loading…
Reference in New Issue
Block a user