[PATCH 13 of 13 STABLE V4] merge: check filename case collision between changesets for branch merging

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Dec 16 06:27:21 CST 2011


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1324038087 -32400
# Branch stable
# Node ID ccc9aa6a0b1bf1d7def794aabcd09cb258001991
# Parent  08fc03db973623b6fd176f810f20f35851b55918
merge: check filename case collision between changesets for branch merging

this patch makes branch merging abort when merged changesets have same
file in different case on case insensitive filesystem.

this patch does not prevent linear update which merges between target
and working contexts, because 'branchmerge' is False in such case.

diff -r 08fc03db9736 -r ccc9aa6a0b1b mercurial/merge.py
--- a/mercurial/merge.py	Fri Dec 16 21:21:08 2011 +0900
+++ b/mercurial/merge.py	Fri Dec 16 21:21:27 2011 +0900
@@ -96,7 +96,7 @@
             raise util.Abort(_("untracked file in working directory differs"
                                " from file in requested revision: '%s'") % fn)
 
-def _checkcollision(mctx):
+def _checkcollision(mctx, wctx):
     "check for case folding collisions in the destination context"
     folded = {}
     for fn in mctx:
@@ -106,6 +106,14 @@
                              % (fn, folded[fold]))
         folded[fold] = fn
 
+    if wctx:
+        for fn in wctx:
+            fold = util.normcase(fn)
+            mfn = folded.get(fold, None)
+            if mfn and (mfn != fn):
+                raise util.Abort(_("case-folding collision between %s and %s")
+                                 % (mfn, fn))
+
 def _forgetremoved(wctx, mctx, branchmerge):
     """
     Forget removed files
@@ -549,7 +557,7 @@
         if not force:
             _checkunknown(wc, p2, folding)
         if folding:
-            _checkcollision(p2)
+            _checkcollision(p2, branchmerge and p1)
         action += _forgetremoved(wc, p2, branchmerge)
         action += manifestmerge(repo, wc, p2, pa, overwrite, partial)
 
diff -r 08fc03db9736 -r ccc9aa6a0b1b tests/test-casecollision-merge.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-casecollision-merge.t	Fri Dec 16 21:21:27 2011 +0900
@@ -0,0 +1,109 @@
+run only on case-insensitive filesystems
+
+  $ "$TESTDIR/hghave" icasefs || exit 80
+
+################################
+test for branch merging
+################################
+
+  $ hg init repo1
+  $ cd repo1
+
+create base revision
+
+  $ echo base > base.txt
+  $ hg add base.txt
+  $ hg commit -m 'base'
+
+add same file in different case on both heads
+
+  $ echo a > a.txt
+  $ hg add a.txt
+  $ hg commit -m 'add a.txt'
+
+  $ hg update 0
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+  $ echo A > A.TXT
+  $ hg add A.TXT
+  $ hg commit -m 'add A.TXT'
+  created new head
+
+merge another, and fail with case-folding collision
+
+  $ hg merge
+  abort: case-folding collision between a.txt and A.TXT
+  [255]
+
+check clean-ness of working directory
+
+  $ hg status
+  $ hg parents --template '{rev}\n'
+  2
+  $ cd ..
+
+################################
+test for linear updates
+################################
+
+  $ hg init repo2
+  $ cd repo2
+
+create base revision (rev:0)
+
+  $ hg import --bypass --exact - <<EOF
+  > # HG changeset patch
+  > # User null
+  > # Date 1 0
+  > # Node ID e1bdf414b0ea9c831fd3a14e94a0a18e1410f98b
+  > # Parent  0000000000000000000000000000000000000000
+  > add a
+  > 
+  > diff --git a/a b/a
+  > new file mode 100644
+  > --- /dev/null
+  > +++ b/a
+  > @@ -0,0 +1,3 @@
+  > +this is line 1
+  > +this is line 2
+  > +this is line 3
+  > EOF
+  applying patch from stdin
+
+create rename revision (rev:1)
+
+  $ hg import --bypass --exact - <<EOF
+  > # HG changeset patch
+  > # User null
+  > # Date 1 0
+  > # Node ID 9dca9f19bb91851bc693544b598b0740629edfad
+  > # Parent  e1bdf414b0ea9c831fd3a14e94a0a18e1410f98b
+  > rename a to A
+  > 
+  > diff --git a/a b/A
+  > rename from a
+  > rename to A
+  > EOF
+  applying patch from stdin
+
+update to base revision, and modify 'a'
+
+  $ hg update 0
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo 'this is added line' >> a
+
+update to current tip linearly
+
+  $ hg update 1
+  merging a and A to A
+  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+
+check status and contents of file
+
+  $ hg status -A
+  M A
+  $ cat A
+  this is line 1
+  this is line 2
+  this is line 3
+  this is added line


More information about the Mercurial-devel mailing list