[PATCH] patch: separate reverse copy data (issue1959)

Wagner Bruna wagner.bruna+mercurial at gmail.com
Thu Feb 11 07:23:30 CST 2010


# HG changeset patch
# User Wagner Bruna <wbruna at softwareexpress.com.br>
# Date 1265894577 7200
# Node ID aefb23a0a0bfa0d0aef3ea75d7842ecc4ccf9b03
# Parent  f163775e36e08c89802734cfa0f0e50606203126
patch: separate reverse copy data (issue1959)

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -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' %
diff --git a/tests/test-rename b/tests/test-rename
--- a/tests/test-rename
+++ b/tests/test-rename
@@ -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
diff --git a/tests/test-rename.out b/tests/test-rename.out
--- a/tests/test-rename.out
+++ b/tests/test-rename.out
@@ -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


More information about the Mercurial-devel mailing list