MCPcopy Create free account
hub / github.com/git/git / check_file_directory_conflict

Function check_file_directory_conflict

read-cache.c:1211–1235  ·  view source on GitHub ↗

We may be in a situation where we already have path/file and path * is being added, or we already have path and path/file is being * added. Either one would result in a nonsense tree that has path * twice when git-write-tree tries to write it out. Prevent it. * * If ok-to-replace is specified, we remove the conflicting entries * from the cache so the caller should recompute the insert posi

Source from the content-addressed store, hash-verified

1209 * When this happens, we return non-zero.
1210 */
1211static int check_file_directory_conflict(struct index_state *istate,
1212 const struct cache_entry *ce,
1213 int pos, int ok_to_replace)
1214{
1215 int retval;
1216
1217 /*
1218 * When ce is an "I am going away" entry, we allow it to be added
1219 */
1220 if (ce->ce_flags & CE_REMOVE)
1221 return 0;
1222
1223 /*
1224 * We check if the path is a sub-path of a subsequent pathname
1225 * first, since removing those will not change the position
1226 * in the array.
1227 */
1228 retval = has_file_name(istate, ce, pos, ok_to_replace);
1229
1230 /*
1231 * Then check if the path might have a clashing sub-directory
1232 * before it.
1233 */
1234 return retval + has_dir_name(istate, ce, pos, ok_to_replace);
1235}
1236
1237static int add_index_entry_with_check(struct index_state *istate, struct cache_entry *ce, int option)
1238{

Callers 1

Calls 2

has_file_nameFunction · 0.85
has_dir_nameFunction · 0.85

Tested by

no test coverage detected