patch: separate reverse copy data (issue1959) stable
authorWagner Bruna <wbruna@softwareexpress.com.br>
Thu, 11 Feb 2010 11:22:57 -0200
branchstable
changeset 10466 d1f209bb9564
parent 10465 5d7e84e7ac6d
child 10467 16c68fd720ab
patch: separate reverse copy data (issue1959)
mercurial/patch.py
tests/test-rename
tests/test-rename.out
--- a/mercurial/patch.py	Sun Feb 14 15:45:12 2010 +0100
+++ b/mercurial/patch.py	Thu Feb 11 11:22:57 2010 -0200
@@ -1436,8 +1436,6 @@
     if opts.git or opts.upgrade:
         copy = copies.copies(repo, ctx1, ctx2, repo[nullid])[0]
         copy = copy.copy()
-        for k, v in copy.items():
-            copy[v] = k
 
     difffn = lambda opts, losedata: trydiff(repo, revs, ctx1, ctx2,
                  modified, added, removed, copy, getfilectx, opts, losedata)
@@ -1467,6 +1465,8 @@
     gone = set()
     gitmode = {'l': '120000', 'x': '100755', '': '100644'}
 
+    copyto = dict([(v, k) for k, v in copy.items()])
+
     if opts.git:
         revs = None
 
@@ -1483,9 +1483,12 @@
         if opts.git or losedatafn:
             if f in added:
                 mode = gitmode[ctx2.flags(f)]
-                if f in copy:
+                if f in copy or f in copyto:
                     if opts.git:
-                        a = copy[f]
+                        if f in copy:
+                            a = copy[f]
+                        else:
+                            a = copyto[f]
                         omode = gitmode[man1.flags(a)]
                         _addmodehdr(header, omode, mode)
                         if a in removed and a not in gone:
@@ -1514,7 +1517,9 @@
             elif f in removed:
                 if opts.git:
                     # have we already reported a copy above?
-                    if f in copy and copy[f] in added and copy[copy[f]] == f:
+                    if f in copy and copy[f] in added and copyto[copy[f]] == f:
+                        dodiff = False
+                    elif f in copyto and copyto[f] in added and copy[copyto[f]] == f:
                         dodiff = False
                     else:
                         header.append('deleted file mode %s\n' %
--- a/tests/test-rename	Sun Feb 14 15:45:12 2010 +0100
+++ b/tests/test-rename	Thu Feb 11 11:22:57 2010 -0200
@@ -210,6 +210,13 @@
 hg status -C
 hg update -C
 
+echo '# overwriting with renames (issue1959)'
+hg rename d1/a d1/c
+hg rename d1/b d1/a
+hg status -C
+hg diff --git
+hg update -C
+
 echo "# check illegal path components"
 
 hg rename d1/d11/a1 .hg/foo
--- a/tests/test-rename.out	Sun Feb 14 15:45:12 2010 +0100
+++ b/tests/test-rename.out	Thu Feb 11 11:22:57 2010 -0200
@@ -300,6 +300,19 @@
 # idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)
 M d1/b
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+# overwriting with renames (issue1959)
+A d1/a
+  d1/b
+A d1/c
+  d1/a
+R d1/b
+diff --git a/d1/b b/d1/a
+rename from d1/b
+rename to d1/a
+diff --git a/d1/a b/d1/c
+copy from d1/a
+copy to d1/c
+2 files updated, 0 files merged, 1 files removed, 0 files unresolved
 # check illegal path components
 abort: path contains illegal component: .hg/foo
 abort: ../foo not under root