icasefs: make case-folding collision detection as deletion aware (issue3648) stable
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 31 Oct 2012 16:50:22 +0900
branchstable
changeset 17889 ce7bc04d863b
parent 17888 39b7052b217b
child 17890 ca6850b9dd9e
icasefs: make case-folding collision detection as deletion aware (issue3648) Before this patch, case-folding collision is checked simply between manifests of each merged revisions. So, files may be considered as colliding each other, even though one of them is already deleted on one of merged branches: in such case, merge causes deleting it, so case-folding collision doesn't occur. This patch checks whether both of files colliding each other still remain after merge or not, and ignores collision if at least one of them is deleted by merge. In the case that one of colliding files is deleted on one of merged branches and changed on another, file is considered to still remain after merge, even though it may be deleted by merge, if "deleting" of it is chosen in "manifestmerge()". This avoids fail to merge by case-folding collisions after choices from "changing" and "deleting" of files. This patch adds only tests for "removed remotely" code paths in "_remains()", because other ones are tested by existing tests in "test-casecollision-merge.t".
mercurial/merge.py
tests/test-casecollision-merge.t
--- a/mercurial/merge.py	Tue Oct 30 13:19:06 2012 -0700
+++ b/mercurial/merge.py	Wed Oct 31 16:50:22 2012 +0900
@@ -99,7 +99,26 @@
         raise util.Abort(_("untracked files in working directory differ "
                            "from files in requested revision"))
 
-def _checkcollision(mctx, wctx):
+def _remains(f, m, ma, workingctx=False):
+    """check whether specified file remains after merge.
+
+    It is assumed that specified file is not contained in the manifest
+    of the other context.
+    """
+    if f in ma:
+        n = m[f]
+        if n != ma[f]:
+            return True # because it is changed locally
+            # even though it doesn't remain, if "remote deleted" is
+            # chosen in manifestmerge()
+        elif workingctx and n[20:] == "a":
+            return True # because it is added locally (linear merge specific)
+        else:
+            return False # because it is removed remotely
+    else:
+        return True # because it is added locally
+
+def _checkcollision(mctx, extractxs):
     "check for case folding collisions in the destination context"
     folded = {}
     for fn in mctx:
@@ -109,7 +128,8 @@
                              % (fn, folded[fold]))
         folded[fold] = fn
 
-    if wctx:
+    if extractxs:
+        wctx, actx = extractxs
         # class to delay looking up copy mapping
         class pathcopies(object):
             @util.propertycache
@@ -121,7 +141,9 @@
         for fn in wctx:
             fold = util.normcase(fn)
             mfn = folded.get(fold, None)
-            if mfn and mfn != fn and pc.map.get(mfn) != fn:
+            if (mfn and mfn != fn and pc.map.get(mfn) != fn and
+                _remains(fn, wctx.manifest(), actx.manifest(), True) and
+                _remains(mfn, mctx.manifest(), actx.manifest())):
                 raise util.Abort(_("case-folding collision between %s and %s")
                                  % (mfn, fn))
 
@@ -595,7 +617,7 @@
                 (force or not wc.dirty(missing=True, branch=False))):
                 _checkcollision(p2, None)
             else:
-                _checkcollision(p2, wc)
+                _checkcollision(p2, (wc, pa))
         if not force:
             _checkunknown(repo, wc, p2)
         action += _forgetremoved(wc, p2, branchmerge)
--- a/tests/test-casecollision-merge.t	Tue Oct 30 13:19:06 2012 -0700
+++ b/tests/test-casecollision-merge.t	Wed Oct 31 16:50:22 2012 +0900
@@ -11,8 +11,8 @@
 (1) colliding file is one renamed from collided file:
 this is also case for issue3370.
 
-  $ hg init merge_renameaware_1
-  $ cd merge_renameaware_1
+  $ hg init branch_merge_renaming
+  $ cd branch_merge_renaming
 
   $ echo a > a
   $ hg add a
@@ -53,8 +53,8 @@
 
 (2) colliding file is not related to collided file
 
-  $ hg init merge_renameaware_2
-  $ cd merge_renameaware_2
+  $ hg init branch_merge_collding
+  $ cd branch_merge_collding
 
   $ echo a > a
   $ hg add a
@@ -66,22 +66,26 @@
   $ hg commit -m '#2'
   $ hg update --clean 0
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  $ echo 'modified at #3' > a
+  $ echo x > x
+  $ hg add x
   $ hg commit -m '#3'
   created new head
+  $ echo 'modified at #4' > a
+  $ hg commit -m '#4'
 
   $ hg merge
   abort: case-folding collision between A and a
   [255]
   $ hg parents --template '{rev}\n'
-  3
+  4
   $ hg status -A
   C a
+  C x
   $ cat a
-  modified at #3
+  modified at #4
 
   $ hg update --clean 2
-  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
   $ hg merge
   abort: case-folding collision between a and A
   [255]
@@ -92,6 +96,29 @@
   $ cat A
   A
 
+test for deletion awareness of case-folding collision check (issue3648):
+revision '#3' doesn't change 'a', so 'a' should be recognized as
+safely removed in merging between #2 and #3.
+
+  $ hg update --clean 3
+  2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg merge 2
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg status -A
+  M A
+  R a
+  C x
+
+  $ hg update --clean 2
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg merge 3
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg status -A
+  M x
+  C A
+
   $ cd ..