[PATCH 1 of 3 STABLE v2] diff: move status fixup earlier, out of _filepairs()

Martin von Zweigbergk martinvonz at google.com
Fri Jan 15 05:32:13 UTC 2016


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1452794554 28800
#      Thu Jan 14 10:02:34 2016 -0800
# Branch stable
# Node ID 10bed95d5683a30cef73e6313eea3106e8931c79
# Parent  bf86e3e87123a397f75733bc2a7f033d7a0b035a
diff: move status fixup earlier, out of _filepairs()

This prepares for future patches, and it also lets us remove the ugly
"ctx1" argument to _filepairs() (ugly because of its assymmetry --
there's no "ctx2" argument).

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2238,6 +2238,17 @@
                      if dst.startswith(relroot)
                      and src.startswith(relroot)))
 
+    modifiedset = set(modified)
+    addedset = set(added)
+    for f in modified:
+        if f not in ctx1:
+            # Fix up added, since merged-in additions appear as
+            # modifications during merges
+            modifiedset.remove(f)
+            addedset.add(f)
+    modified = sorted(modifiedset)
+    added = sorted(addedset)
+
     def difffn(opts, losedata):
         return trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
                        copy, getfilectx, opts, losedata, prefix, relroot)
@@ -2309,7 +2320,7 @@
     '''like diff(), but yields 2-tuples of (output, label) for ui.write()'''
     return difflabel(diff, *args, **kw)
 
-def _filepairs(ctx1, modified, added, removed, copy, opts):
+def _filepairs(modified, added, removed, copy, opts):
     '''generates tuples (f1, f2, copyop), where f1 is the name of the file
     before and f2 is the the name after. For added files, f1 will be None,
     and for removed files, f2 will be None. copyop may be set to None, 'copy'
@@ -2319,11 +2330,6 @@
     copyto = dict([(v, k) for k, v in copy.items()])
 
     addedset, removedset = set(added), set(removed)
-    # Fix up  added, since merged-in additions appear as
-    # modifications during merges
-    for f in modified:
-        if f not in ctx1:
-            addedset.add(f)
 
     for f in sorted(modified + added + removed):
         copyop = None
@@ -2389,8 +2395,7 @@
                 raise AssertionError(
                     "file %s doesn't start with relroot %s" % (f, relroot))
 
-    for f1, f2, copyop in _filepairs(
-            ctx1, modified, added, removed, copy, opts):
+    for f1, f2, copyop in _filepairs(modified, added, removed, copy, opts):
         content1 = None
         content2 = None
         flag1 = None


More information about the Mercurial-devel mailing list