[PATCH 3 of 3 STABLE v2] diff: don't crash when merged-in addition is copied

Martin von Zweigbergk martinvonz at google.com
Thu Jan 14 23:32:15 CST 2016


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1452795775 28800
#      Thu Jan 14 10:22:55 2016 -0800
# Branch stable
# Node ID 7aba79de9fcd2acb7d08ac54b7b5e63712b73f1f
# Parent  a657467d5c5401138b0280d7ec2e7f988c4b12dd
diff: don't crash when merged-in addition is copied

Similar to what was explained in the previous commit, the diff code
expected copy source to be in "ctx1", which is not always the case
during a merge. This has been broken since before hg 2.0.

Also similar to the previous commit, we fix the problem by fixing up
the copy dict.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2255,6 +2255,11 @@
     modified = sorted(modifiedset)
     added = sorted(addedset)
     removed = sorted(removedset)
+    for dst, src in copy.items():
+        if src not in ctx1:
+            # Files merged in during a merge and then copied/renamed are
+            # reported as copies. We want to show them in the diff as additions.
+            del copy[dst]
 
     def difffn(opts, losedata):
         return trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
diff --git a/tests/test-diffdir.t b/tests/test-diffdir.t
--- a/tests/test-diffdir.t
+++ b/tests/test-diffdir.t
@@ -68,3 +68,10 @@
   +++ b/a2
   @@ -0,0 +1,1 @@
   +foo
+  $ hg diff --nodates --git
+  diff --git a/a2 b/a2
+  new file mode 100644
+  --- /dev/null
+  +++ b/a2
+  @@ -0,0 +1,1 @@
+  +foo


More information about the Mercurial-devel mailing list