read-cache.c: fix a couple more CE_REMOVE conversion
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Jan 2008 05:24:21 +0000 (21:24 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Jan 2008 05:24:21 +0000 (21:24 -0800)
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 <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c
index 8ba8f0f88f6164a9d79644fef90c86ef1de8c45d..8f5d02afaa1265205db5d1ad2a5d5ed3232cce5b 100644 (file)
@@ -615,7 +615,7 @@ static int has_dir_name(struct index_state *istate,
                         * it is Ok to have a directory at the same
                         * path.
                         */
                         * it is Ok to have a directory at the same
                         * path.
                         */
-                       if (stage || istate->cache[pos]->ce_mode) {
+                       if (!(istate->cache[pos]->ce_flags & CE_REMOVE)) {
                                retval = -1;
                                if (!ok_to_replace)
                                        break;
                                retval = -1;
                                if (!ok_to_replace)
                                        break;
@@ -637,8 +637,9 @@ static int has_dir_name(struct index_state *istate,
                            (p->name[len] != '/') ||
                            memcmp(p->name, name, len))
                                break; /* not our subdirectory */
                            (p->name[len] != '/') ||
                            memcmp(p->name, name, len))
                                break; /* not our subdirectory */
-                       if (ce_stage(p) == stage && (stage || p->ce_mode))
-                               /* p is at the same stage as our entry, and
+                       if (ce_stage(p) == stage && !(p->ce_flags & CE_REMOVE))
+                               /*
+                                * p is at the same stage as our entry, and
                                 * is a subdirectory of what we are looking
                                 * at, so we cannot have conflicts at our
                                 * level or anything shorter.
                                 * is a subdirectory of what we are looking
                                 * at, so we cannot have conflicts at our
                                 * level or anything shorter.