diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2018-07-10 16:10:03 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-11-05 15:53:59 +0000 |
| commit | af33210b735b760debc03ce558ff62c3834f0a5b (patch) | |
| tree | 23095c9cb3e6024f9dd6c7e939187af187940377 /src/apply.c | |
| parent | 37b25ac57f78dc72e6bf4e516e24dc5010098cee (diff) | |
| download | libgit2-af33210b735b760debc03ce558ff62c3834f0a5b.tar.gz | |
apply: introduce a delta callback
Introduce a callback to the application options that allow callers to
add a per-delta callback. The callback can return an error code to stop
patch application, or can return a value to skip the application of a
particular delta.
Diffstat (limited to 'src/apply.c')
| -rw-r--r-- | src/apply.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/apply.c b/src/apply.c index e6c2ae15b..95342676c 100644 --- a/src/apply.c +++ b/src/apply.c @@ -390,7 +390,8 @@ static int apply_one( git_index *preimage, git_index *postimage, git_diff *diff, - size_t i) + size_t i, + const git_apply_options *opts) { git_patch *patch = NULL; git_buf pre_contents = GIT_BUF_INIT, post_contents = GIT_BUF_INIT; @@ -406,6 +407,17 @@ static int apply_one( delta = git_patch_get_delta(patch); + if (opts->delta_cb) { + error = opts->delta_cb(delta, opts->payload); + + if (error) { + if (error > 0) + error = 0; + + goto done; + } + } + if (delta->status != GIT_DELTA_ADDED) { error = git_reader_read(&pre_contents, &pre_id, preimage_reader, delta->old_file.path); @@ -514,7 +526,7 @@ int git_apply_to_tree( } for (i = 0; i < git_diff_num_deltas(diff); i++) { - if ((error = apply_one(repo, pre_reader, NULL, postimage, diff, i)) < 0) + if ((error = apply_one(repo, pre_reader, NULL, postimage, diff, i, &opts)) < 0) goto done; } @@ -700,7 +712,7 @@ int git_apply( goto done; for (i = 0; i < git_diff_num_deltas(diff); i++) { - if ((error = apply_one(repo, pre_reader, preimage, postimage, diff, i)) < 0) + if ((error = apply_one(repo, pre_reader, preimage, postimage, diff, i, &opts)) < 0) goto done; } |
