changeset 23663:a9853fc172d2

trydiff: simplify checking for additions In the body of the loop in trydiff(), there are conditions like: addedset or (f in modifiedset and to is None) The second half of that expression is to account for the fact that merge-in additions appear as additions. By instead fixing up the sets of modified and added files to compensate for this fact, we can simplify the body of the loop. It also fixes one case where the addedset was checked without the additional check (the "have we already reported a copy above?" case in the code, also see fixed test case). The similar condition with 'removedset' in it seems to have served no purpose even before this change, so it could have been simplified even before.
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 23 Dec 2014 16:12:54 -0800
parents bc7d90c966d2
children 377124ba6b10
files mercurial/patch.py tests/test-shelve.t
diffstat 2 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Tue Dec 23 14:56:30 2014 -0800
+++ b/mercurial/patch.py	Tue Dec 23 16:12:54 2014 -0800
@@ -1796,6 +1796,12 @@
         revs = None
 
     modifiedset, addedset, removedset = set(modified), set(added), set(removed)
+    # Fix up modified and added, since merged-in additions appear as
+    # modifications during merges
+    for f in modifiedset.copy():
+        if f not in ctx1:
+            addedset.add(f)
+            modifiedset.remove(f)
     for f in sorted(modified + added + removed):
         to = None
         tn = None
@@ -1807,7 +1813,7 @@
             tn = getfilectx(f, ctx2).data()
         a, b = f, f
         if opts.git or losedatafn:
-            if f in addedset or (f in modifiedset and to is None):
+            if f in addedset:
                 mode = gitmode[ctx2.flags(f)]
                 if f in copy or f in copyto:
                     if opts.git:
@@ -1843,7 +1849,7 @@
                 if not opts.git and not tn:
                     # regular diffs cannot represent new empty file
                     losedatafn(f)
-            elif f in removedset or (f in modifiedset and tn is None):
+            elif f in removedset:
                 if opts.git:
                     # have we already reported a copy above?
                     if ((f in copy and copy[f] in addedset
--- a/tests/test-shelve.t	Tue Dec 23 14:56:30 2014 -0800
+++ b/tests/test-shelve.t	Tue Dec 23 16:12:54 2014 -0800
@@ -238,12 +238,6 @@
   diff --git a/b/b b/b.rename/b
   rename from b/b
   rename to b.rename/b
-  diff --git a/b/b b/b/b
-  deleted file mode 100644
-  --- a/b/b
-  +++ /dev/null
-  @@ -1,1 +0,0 @@
-  -b
   diff --git a/c b/c.copy
   copy from c
   copy to c.copy