Skip to content

Commit 077c48d

Browse files
committed
read-cache.c: fix a couple more CE_REMOVE conversion
It is a D/F conflict if you want to add "foo/bar" to the index when "foo" already exists. Also it is a conflict if you want to add a file "foo" when "foo/bar" exists. An exception is when the existing entry is there only to mark "I used to be here but I am being removed". This is needed for operations such as "git read-tree -m -u" that update the index and then reflect the result to the work tree --- we need to remember what to remove somewhere, and we use the index for that. In such a case, an existing file "foo" is being removed and we can create "foo/" directory and hang "bar" underneath it without any conflict. We used to use (ce->ce_mode == 0) to mark an entry that is being removed, but (CE_REMOVE & ce->ce_flags) is used for that purpose these days. An earlier commit forgot to convert the logic in the code that checks D/F conflict condition. The old code knew that "to be removed" entries cannot be at higher stage and actively checked that condition, but it was an unnecessary check. This patch removes the extra check as well. Acked-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 204ce97 commit 077c48d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

read-cache.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ static int has_dir_name(struct index_state *istate,
615615
* it is Ok to have a directory at the same
616616
* path.
617617
*/
618-
if (stage || istate->cache[pos]->ce_mode) {
618+
if (!(istate->cache[pos]->ce_flags & CE_REMOVE)) {
619619
retval = -1;
620620
if (!ok_to_replace)
621621
break;
@@ -637,8 +637,9 @@ static int has_dir_name(struct index_state *istate,
637637
(p->name[len] != '/') ||
638638
memcmp(p->name, name, len))
639639
break; /* not our subdirectory */
640-
if (ce_stage(p) == stage && (stage || p->ce_mode))
641-
/* p is at the same stage as our entry, and
640+
if (ce_stage(p) == stage && !(p->ce_flags & CE_REMOVE))
641+
/*
642+
* p is at the same stage as our entry, and
642643
* is a subdirectory of what we are looking
643644
* at, so we cannot have conflicts at our
644645
* level or anything shorter.

0 commit comments

Comments
 (0)