diff mercurial/merge.py @ 17889:ce7bc04d863b stable

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".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 31 Oct 2012 16:50:22 +0900
parents 98687cdddcb1
children 5881d5b7552f
line wrap: on
line diff
--- 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)