D7070: copies: extract data extraction into a `revinfo` function

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Wed Oct 16 13:02:45 EDT 2019


marmoute updated this revision to Diff 17244.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7070?vs=17242&id=17244

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7070/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7070

AFFECTED FILES
  mercurial/copies.py

CHANGE DETAILS

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -178,12 +178,36 @@
     return cm
 
 
+def _revinfogetter(repo):
+    """return a function that return multiple data given a <rev>"i
+
+    * p1: revision number of first parent
+    * p2: revision number of first parent
+    * p1copies: mapping of copies from p1
+    * p2copies: mapping of copies from p2
+    * removed: a list of removed files
+    """
+    cl = repo.changelog
+    parents = cl.parentrevs
+
+    def revinfo(rev):
+        p1, p2 = parents(rev)
+        ctx = repo[rev]
+        p1copies, p2copies = ctx._copies
+        removed = ctx.filesremoved()
+        return p1, p2, p1copies, p2copies, removed
+
+    return revinfo
+
+
 def _changesetforwardcopies(a, b, match):
     if a.rev() in (node.nullrev, b.rev()):
         return {}
 
     repo = a.repo()
     children = {}
+    revinfo = _revinfogetter(repo)
+
     cl = repo.changelog
     missingrevs = cl.findmissingrevs(common=[a.rev()], heads=[b.rev()])
     for r in missingrevs:
@@ -206,9 +230,7 @@
         if r == b.rev():
             return copies
         for i, c in enumerate(children[r]):
-            childctx = repo[c]
-            p1, p2 = cl.parentrevs(c)
-            p1copies, p2copies = childctx._copies
+            p1, p2, p1copies, p2copies, removed = revinfo(c)
             if r == p1:
                 parent = 1
                 childcopies = p1copies
@@ -227,7 +249,7 @@
                 newcopies = copies
             if childcopies:
                 newcopies = _chain(newcopies, childcopies)
-            for f in childctx.filesremoved():
+            for f in removed:
                 if f in newcopies:
                     del newcopies[f]
             othercopies = all_copies.get(c)



To: marmoute, #hg-reviewers
Cc: martinvonz, mercurial-devel


More information about the Mercurial-devel mailing list