apply: fix an incomplete comment in check_patch()
authorJunio C Hamano <gitster@pobox.com>
Wed, 16 May 2012 22:31:18 +0000 (15:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Jul 2012 21:36:26 +0000 (14:36 -0700)
This check is not only about type-change (for which it would be
sufficient to check only was_deleted()) but is also about a swap
rename.  Otherwise to_be_deleted() check is not justified.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/apply.c

index 725712d7888c1a5503c2249c6dbd50ee796c2851..44f6de903a73ccb29c102159bd2efb7f753b9348 100644 (file)
@@ -3218,16 +3218,22 @@ static int check_patch(struct patch *patch)
                return status;
        old_name = patch->old_name;
 
+       /*
+        * A type-change diff is always split into a patch to delete
+        * old, immediately followed by a patch to create new (see
+        * diff.c::run_diff()); in such a case it is Ok that the entry
+        * to be deleted by the previous patch is still in the working
+        * tree and in the index.
+        *
+        * A patch to swap-rename between A and B would first rename A
+        * to B and then rename B to A.  While applying the first one,
+        * the presense of B should not stop A from getting renamed to
+        * B; ask to_be_deleted() about the later rename.  Removal of
+        * B and rename from A to B is handled the same way by asking
+        * was_deleted().
+        */
        if ((tpatch = in_fn_table(new_name)) &&
-                       (was_deleted(tpatch) || to_be_deleted(tpatch)))
-               /*
-                * A type-change diff is always split into a patch to
-                * delete old, immediately followed by a patch to
-                * create new (see diff.c::run_diff()); in such a case
-                * it is Ok that the entry to be deleted by the
-                * previous patch is still in the working tree and in
-                * the index.
-                */
+           (was_deleted(tpatch) || to_be_deleted(tpatch)))
                ok_if_exists = 1;
        else
                ok_if_exists = 0;