| 3801 | } |
| 3802 | |
| 3803 | static int apply_data(struct apply_state *state, struct patch *patch, |
| 3804 | struct stat *st, const struct cache_entry *ce) |
| 3805 | { |
| 3806 | struct image image = IMAGE_INIT; |
| 3807 | |
| 3808 | if (load_preimage(state, &image, patch, st, ce) < 0) |
| 3809 | return -1; |
| 3810 | |
| 3811 | if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) { |
| 3812 | if (state->apply_verbosity > verbosity_silent && |
| 3813 | state->threeway && !patch->direct_to_threeway) |
| 3814 | fprintf(stderr, _("Falling back to direct application...\n")); |
| 3815 | |
| 3816 | /* Note: with --reject, apply_fragments() returns 0 */ |
| 3817 | if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) { |
| 3818 | image_clear(&image); |
| 3819 | return -1; |
| 3820 | } |
| 3821 | } |
| 3822 | patch->result = strbuf_detach(&image.buf, &patch->resultsize); |
| 3823 | add_to_fn_table(state, patch); |
| 3824 | free(image.line); |
| 3825 | |
| 3826 | if (0 < patch->is_delete && patch->resultsize) |
| 3827 | return error(_("removal patch leaves file contents")); |
| 3828 | |
| 3829 | return 0; |
| 3830 | } |
| 3831 | |
| 3832 | /* |
| 3833 | * If "patch" that we are looking at modifies or deletes what we have, |
no test coverage detected