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

Function check_to_create

apply.c:3929–3973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3927#define EXISTS_IN_INDEX_AS_ITA 3
3928
3929static int check_to_create(struct apply_state *state,
3930 const char *new_name,
3931 int ok_if_exists)
3932{
3933 struct stat nst;
3934
3935 if (state->check_index && (!ok_if_exists || !state->cached)) {
3936 int pos;
3937
3938 pos = index_name_pos(state->repo->index, new_name, strlen(new_name));
3939 if (pos >= 0) {
3940 struct cache_entry *ce = state->repo->index->cache[pos];
3941
3942 /* allow ITA, as they do not yet exist in the index */
3943 if (!ok_if_exists && !(ce->ce_flags & CE_INTENT_TO_ADD))
3944 return EXISTS_IN_INDEX;
3945
3946 /* ITA entries can never match working tree files */
3947 if (!state->cached && (ce->ce_flags & CE_INTENT_TO_ADD))
3948 return EXISTS_IN_INDEX_AS_ITA;
3949 }
3950 }
3951
3952 if (state->cached)
3953 return 0;
3954
3955 if (!lstat(new_name, &nst)) {
3956 if (S_ISDIR(nst.st_mode) || ok_if_exists)
3957 return 0;
3958 /*
3959 * A leading component of new_name might be a symlink
3960 * that is going to be removed with this patch, but
3961 * still pointing at somewhere that has the path.
3962 * In such a case, path "new_name" does not exist as
3963 * far as git is concerned.
3964 */
3965 if (has_symlink_leading_path(new_name, strlen(new_name)))
3966 return 0;
3967
3968 return EXISTS_IN_WORKTREE;
3969 } else if (!is_missing_file_error(errno)) {
3970 return error_errno("%s", new_name);
3971 }
3972 return 0;
3973}
3974
3975static void prepare_symlink_changes(struct apply_state *state, struct patch *patch)
3976{

Callers 1

check_patchFunction · 0.85

Calls 4

index_name_posFunction · 0.85
has_symlink_leading_pathFunction · 0.85
is_missing_file_errorFunction · 0.85
error_errnoFunction · 0.85

Tested by

no test coverage detected