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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
diff --git a/src/diff.c b/src/diff.c
index 317d495..a93bd4c 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,
diff --git a/src/patch_generate.c b/src/patch_generate.c
index bba1162..804fc0e 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -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;