Skip to content

Commit 62a2fc0

Browse files
committed
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 parent ace3508 commit 62a2fc0

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

src/diff.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,41 @@ int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
120120
return 0;
121121
}
122122

123+
int git_diff_foreach(
124+
git_diff *diff,
125+
git_diff_file_cb file_cb,
126+
git_diff_binary_cb binary_cb,
127+
git_diff_hunk_cb hunk_cb,
128+
git_diff_line_cb data_cb,
129+
void *payload)
130+
{
131+
int error = 0;
132+
git_diff_delta *delta;
133+
size_t idx;
134+
135+
assert(diff);
136+
137+
git_vector_foreach(&diff->deltas, idx, delta) {
138+
git_patch *patch;
139+
140+
/* check flags against patch status */
141+
if (git_diff_delta__should_skip(&diff->opts, delta))
142+
continue;
143+
144+
if ((error = git_patch_from_diff(&patch, diff, idx)) != 0)
145+
break;
146+
147+
error = git_patch__invoke_callbacks(patch, file_cb, binary_cb,
148+
hunk_cb, data_cb, payload);
149+
git_patch_free(patch);
150+
151+
if (error)
152+
break;
153+
}
154+
155+
return error;
156+
}
157+
123158
int git_diff_format_email__append_header_tobuf(
124159
git_buf *out,
125160
const git_oid *id,

src/patch_generate.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -400,42 +400,6 @@ static int diff_required(git_diff *diff, const char *action)
400400
return -1;
401401
}
402402

403-
int git_diff_foreach(
404-
git_diff *diff,
405-
git_diff_file_cb file_cb,
406-
git_diff_binary_cb binary_cb,
407-
git_diff_hunk_cb hunk_cb,
408-
git_diff_line_cb data_cb,
409-
void *payload)
410-
{
411-
int error = 0;
412-
git_diff_delta *delta;
413-
size_t idx;
414-
415-
if ((error = diff_required(diff, "git_diff_foreach")) < 0)
416-
return error;
417-
418-
git_vector_foreach(&diff->deltas, idx, delta) {
419-
git_patch *patch;
420-
421-
/* check flags against patch status */
422-
if (git_diff_delta__should_skip(&diff->opts, delta))
423-
continue;
424-
425-
if ((error = git_patch_from_diff(&patch, diff, idx)) != 0)
426-
break;
427-
428-
error = git_patch__invoke_callbacks(patch, file_cb, binary_cb,
429-
hunk_cb, data_cb, payload);
430-
git_patch_free(patch);
431-
432-
if (error)
433-
break;
434-
}
435-
436-
return error;
437-
}
438-
439403
typedef struct {
440404
git_patch_generated patch;
441405
git_diff_delta delta;

0 commit comments

Comments
 (0)