copies: properly visit file context ancestors on working file contexts stable
authorHenrik Stuart <henrik.stuart@edlund.dk>
Wed, 07 Apr 2010 21:31:47 +0200
branchstable
changeset 10874 4f11978ae45d
parent 10872 9606edb8777e
child 10875 a9702c47a19f
copies: properly visit file context ancestors on working file contexts
mercurial/copies.py
tests/test-update-renames
tests/test-update-renames.out
--- a/mercurial/copies.py	Wed Apr 07 16:55:01 2010 +0200
+++ b/mercurial/copies.py	Wed Apr 07 21:31:47 2010 +0200
@@ -117,8 +117,23 @@
     diverge = {}
 
     def related(f1, f2, limit):
+        # Walk back to common ancestor to see if the two files originate
+        # from the same file. Since workingfilectx's rev() is None it messes
+        # up the integer comparison logic, hence the pre-step check for
+        # None (f1 and f2 can only be workingfilectx's initially).
+
+        if f1 == f2:
+            return f1 # a match
+
         g1, g2 = f1.ancestors(), f2.ancestors()
         try:
+            f1r, f2r = f1.rev(), f2.rev()
+
+            if f1r is None:
+                f1 = g1.next()
+            if f2r is None:
+                f2 = g2.next()
+
             while 1:
                 f1r, f2r = f1.rev(), f2.rev()
                 if f1r > f2r:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-update-renames	Wed Apr 07 21:31:47 2010 +0200
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# test update logic when there are renames
+
+
+# update with local changes across a file rename
+hg init a
+cd a
+echo a > a
+hg add a
+hg ci -m a
+hg mv a b
+hg ci -m rename
+echo b > b
+hg ci -m change
+hg up -q 0
+echo c > a
+hg up
+cd ..
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-update-renames.out	Wed Apr 07 21:31:47 2010 +0200
@@ -0,0 +1,5 @@
+merging a and b to b
+warning: conflicts during merge.
+merging b failed!
+0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+use 'hg resolve' to retry unresolved file merges