MCPcopy Index your code
hub / github.com/git/git / try_threeway

Function try_threeway

apply.c:3716–3801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3714}
3715
3716static int try_threeway(struct apply_state *state,
3717 struct image *image,
3718 struct patch *patch,
3719 struct stat *st,
3720 const struct cache_entry *ce)
3721{
3722 struct object_id pre_oid, post_oid, our_oid;
3723 struct strbuf buf = STRBUF_INIT;
3724 size_t len;
3725 int status;
3726 char *img;
3727 struct image tmp_image = IMAGE_INIT;
3728
3729 /* No point falling back to 3-way merge in these cases */
3730 if (patch->is_delete ||
3731 S_ISGITLINK(patch->old_mode) || S_ISGITLINK(patch->new_mode) ||
3732 (patch->is_new && !patch->direct_to_threeway) ||
3733 (patch->is_rename && !patch->lines_added && !patch->lines_deleted))
3734 return -1;
3735
3736 /* Preimage the patch was prepared for */
3737 if (patch->is_new)
3738 odb_write_object(the_repository->objects, "", 0, OBJ_BLOB, &pre_oid);
3739 else if (repo_get_oid(the_repository, patch->old_oid_prefix, &pre_oid) ||
3740 read_blob_object(&buf, &pre_oid, patch->old_mode))
3741 return error(_("repository lacks the necessary blob to perform 3-way merge."));
3742
3743 if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
3744 fprintf(stderr, _("Performing three-way merge...\n"));
3745
3746 img = strbuf_detach(&buf, &len);
3747 image_prepare(&tmp_image, img, len, 1);
3748 /* Apply the patch to get the post image */
3749 if (apply_fragments(state, &tmp_image, patch) < 0) {
3750 image_clear(&tmp_image);
3751 return -1;
3752 }
3753 /* post_oid is theirs */
3754 odb_write_object(the_repository->objects, tmp_image.buf.buf,
3755 tmp_image.buf.len, OBJ_BLOB, &post_oid);
3756 image_clear(&tmp_image);
3757
3758 /* our_oid is ours */
3759 if (patch->is_new) {
3760 if (load_current(state, &tmp_image, patch))
3761 return error(_("cannot read the current contents of '%s'"),
3762 patch->new_name);
3763 } else {
3764 if (load_preimage(state, &tmp_image, patch, st, ce))
3765 return error(_("cannot read the current contents of '%s'"),
3766 patch->old_name);
3767 }
3768 odb_write_object(the_repository->objects, tmp_image.buf.buf,
3769 tmp_image.buf.len, OBJ_BLOB, &our_oid);
3770 image_clear(&tmp_image);
3771
3772 /* in-core three-way merge between post and our using pre as base */
3773 status = three_way_merge(state, image, patch->new_name,

Callers 1

apply_dataFunction · 0.85

Calls 13

odb_write_objectFunction · 0.85
repo_get_oidFunction · 0.85
read_blob_objectFunction · 0.85
errorFunction · 0.85
strbuf_detachFunction · 0.85
image_prepareFunction · 0.85
apply_fragmentsFunction · 0.85
image_clearFunction · 0.85
load_currentFunction · 0.85
load_preimageFunction · 0.85
three_way_mergeFunction · 0.85
oidclrFunction · 0.85

Tested by

no test coverage detected