diff: better detection of renames when comparing with the working dir.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 20 Nov 2006 19:32:38 -0200
changeset 3696 562a65635bcb
parent 3695 3a2fc90d27d6
child 3697 da262f35fbc8
diff: better detection of renames when comparing with the working dir.
mercurial/patch.py
tests/test-git-export
tests/test-git-export.out
--- a/mercurial/patch.py	Mon Nov 20 19:32:37 2006 -0200
+++ b/mercurial/patch.py	Mon Nov 20 19:32:38 2006 -0200
@@ -467,6 +467,9 @@
     if not modified and not added and not removed:
         return
 
+    # returns False if there was no rename between n1 and n2
+    # returns None if the file was created between n1 and n2
+    # returns the (file, node) present in n1 that was renamed to f in n2
     def renamedbetween(f, n1, n2):
         r1, r2 = map(repo.changelog.rev, (n1, n2))
         orig = f
@@ -483,12 +486,12 @@
                     f = src[0]
             n2 = repo.changelog.parents(n2)[0]
             r2 = repo.changelog.rev(n2)
-        if orig == f:
-            return None
         cl = getchangelog(n1)
         m = getmanifest(cl[0])
         if f not in m:
             return None
+        if f == orig:
+            return False
         return f, m[f]
 
     if node2:
@@ -518,7 +521,7 @@
             if src:
                 f = src
             of = renamedbetween(f, node1, parent)
-            if of:
+            if of or of is None:
                 return of
             elif src:
                 cl = getchangelog(parent)[0]
--- a/tests/test-git-export	Mon Nov 20 19:32:37 2006 -0200
+++ b/tests/test-git-export	Mon Nov 20 19:32:38 2006 -0200
@@ -112,3 +112,18 @@
 echo
 echo "% ...but there's another copy between the original rev and the wd"
 hg diff --git -r -2
+echo
+echo "% ...but the source of the copy was created after the original rev"
+hg diff --git -r -3
+hg ci -m 'mv created2 created3'
+
+echo > brand-new
+hg add brand-new
+hg ci -m 'add brand-new'
+hg mv brand-new brand-new2
+echo '% created in parent of wd; renamed in the wd'
+hg diff --git
+
+echo
+echo '% created between r1 and parent of wd; renamed in the wd'
+hg diff --git -r -2
--- a/tests/test-git-export.out	Mon Nov 20 19:32:37 2006 -0200
+++ b/tests/test-git-export.out	Mon Nov 20 19:32:38 2006 -0200
@@ -113,3 +113,23 @@
 diff --git a/created b/created3
 rename from created
 rename to created3
+
+% ...but the source of the copy was created after the original rev
+diff --git a/created3 b/created3
+new file mode 100644
+--- /dev/null
++++ b/created3
+@@ -0,0 +1,1 @@
++
+% created in parent of wd; renamed in the wd
+diff --git a/brand-new b/brand-new2
+rename from brand-new
+rename to brand-new2
+
+% created between r1 and parent of wd; renamed in the wd
+diff --git a/brand-new2 b/brand-new2
+new file mode 100644
+--- /dev/null
++++ b/brand-new2
+@@ -0,0 +1,1 @@
++