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

Function check_patch

apply.c:4058–4162  ·  view source on GitHub ↗

* Check and apply the patch in-core; leave the result in patch->result * for the caller to write it out to the final destination. */

Source from the content-addressed store, hash-verified

4056 * for the caller to write it out to the final destination.
4057 */
4058static int check_patch(struct apply_state *state, struct patch *patch)
4059{
4060 struct stat st;
4061 const char *old_name = patch->old_name;
4062 const char *new_name = patch->new_name;
4063 const char *name = old_name ? old_name : new_name;
4064 struct cache_entry *ce = NULL;
4065 struct patch *tpatch;
4066 int ok_if_exists;
4067 int status;
4068
4069 patch->rejected = 1; /* we will drop this after we succeed */
4070
4071 status = check_preimage(state, patch, &ce, &st);
4072 if (status)
4073 return status;
4074 old_name = patch->old_name;
4075
4076 /*
4077 * A type-change diff is always split into a patch to delete
4078 * old, immediately followed by a patch to create new (see
4079 * diff.c::run_diff()); in such a case it is Ok that the entry
4080 * to be deleted by the previous patch is still in the working
4081 * tree and in the index.
4082 *
4083 * A patch to swap-rename between A and B would first rename A
4084 * to B and then rename B to A. While applying the first one,
4085 * the presence of B should not stop A from getting renamed to
4086 * B; ask to_be_deleted() about the later rename. Removal of
4087 * B and rename from A to B is handled the same way by asking
4088 * was_deleted().
4089 */
4090 if ((tpatch = in_fn_table(state, new_name)) &&
4091 (was_deleted(tpatch) || to_be_deleted(tpatch)))
4092 ok_if_exists = 1;
4093 else
4094 ok_if_exists = 0;
4095
4096 if (new_name &&
4097 ((0 < patch->is_new) || patch->is_rename || patch->is_copy)) {
4098 int err = check_to_create(state, new_name, ok_if_exists);
4099
4100 if (err && state->threeway) {
4101 patch->direct_to_threeway = 1;
4102 } else switch (err) {
4103 case 0:
4104 break; /* happy */
4105 case EXISTS_IN_INDEX:
4106 return error(_("%s: already exists in index"), new_name);
4107 case EXISTS_IN_INDEX_AS_ITA:
4108 return error(_("%s: does not match index"), new_name);
4109 case EXISTS_IN_WORKTREE:
4110 return error(_("%s: already exists in working directory"),
4111 new_name);
4112 default:
4113 return err;
4114 }
4115

Callers 1

check_patch_listFunction · 0.85

Calls 9

check_preimageFunction · 0.85
in_fn_tableFunction · 0.85
was_deletedFunction · 0.85
to_be_deletedFunction · 0.85
check_to_createFunction · 0.85
errorFunction · 0.85
check_unsafe_pathFunction · 0.85
path_is_beyond_symlinkFunction · 0.85
apply_dataFunction · 0.85

Tested by

no test coverage detected