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

Function check_preimage

apply.c:3843–3922  ·  view source on GitHub ↗

* If "patch" that we are looking at modifies or deletes what we have, * we would want it not to lose any local modification we have, either * in the working tree or in the index. * * This also decides if a non-git patch is a creation patch or a * modification to an existing empty file. We do not check the state * of the current tree for a creation patch in this function; the caller * check

Source from the content-addressed store, hash-verified

3841 * the path the patch creates does not exist in the current tree.
3842 */
3843static int check_preimage(struct apply_state *state,
3844 struct patch *patch,
3845 struct cache_entry **ce,
3846 struct stat *st)
3847{
3848 const char *old_name = patch->old_name;
3849 struct patch *previous = NULL;
3850 int stat_ret = 0, status;
3851 unsigned st_mode = 0;
3852
3853 if (!old_name)
3854 return 0;
3855
3856 assert(patch->is_new <= 0);
3857 previous = previous_patch(state, patch, &status);
3858
3859 if (status)
3860 return error(_("path %s has been renamed/deleted"), old_name);
3861 if (previous) {
3862 st_mode = previous->new_mode;
3863 } else if (!state->cached) {
3864 stat_ret = lstat(old_name, st);
3865 if (stat_ret && errno != ENOENT)
3866 return error_errno("%s", old_name);
3867 }
3868
3869 if (state->check_index && !previous) {
3870 int pos = index_name_pos(state->repo->index, old_name,
3871 strlen(old_name));
3872 if (pos < 0) {
3873 if (patch->is_new < 0)
3874 goto is_new;
3875 return error(_("%s: does not exist in index"), old_name);
3876 }
3877 *ce = state->repo->index->cache[pos];
3878 if (stat_ret < 0) {
3879 if (checkout_target(state->repo->index, *ce, st))
3880 return -1;
3881 }
3882 if (!state->cached && verify_index_match(state, *ce, st))
3883 return error(_("%s: does not match index"), old_name);
3884 if (state->cached)
3885 st_mode = (*ce)->ce_mode;
3886 } else if (stat_ret < 0) {
3887 if (patch->is_new < 0)
3888 goto is_new;
3889 return error_errno("%s", old_name);
3890 }
3891
3892 if (!state->cached && !previous) {
3893 if (*ce && !(*ce)->ce_mode)
3894 BUG("ce_mode == 0 for path '%s'", old_name);
3895
3896 if (trust_executable_bit || !S_ISREG(st->st_mode))
3897 st_mode = ce_mode_from_stat(*ce, st->st_mode);
3898 else if (*ce)
3899 st_mode = (*ce)->ce_mode;
3900 else

Callers 1

check_patchFunction · 0.85

Calls 8

previous_patchFunction · 0.85
errorFunction · 0.85
error_errnoFunction · 0.85
index_name_posFunction · 0.85
checkout_targetFunction · 0.85
verify_index_matchFunction · 0.85
ce_mode_from_statFunction · 0.85
warningFunction · 0.85

Tested by

no test coverage detected