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

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sat Oct 12 12:46:24 EDT 2019


marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The function is build once at the beginning of the algorithm and used fetch
  appropriate information for each revision.
  
  This abstracts some implementation details from the main algorithm and will help
  us to access the data more efficiently in future changesets.

REPOSITORY
  rHG Mercurial

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
@@ -264,12 +264,35 @@
     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
+
+    def revinfo(rev):
+        p1, p2 = cl.parentrevs(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:
@@ -292,14 +315,14 @@
         if r == b.rev():
             return copies
         for i, c in enumerate(children[r]):
-            childctx = repo[c]
-            if r == childctx.p1().rev():
+            p1, p2, p1copies, p2copies, removed = revinfo(c)
+            if r == p1:
                 parent = 1
-                childcopies = childctx.p1copies()
+                childcopies = p1copies
             else:
-                assert r == childctx.p2().rev()
+                assert r == p2
                 parent = 2
-                childcopies = childctx.p2copies()
+                childcopies = p2copies
             if not alwaysmatch:
                 childcopies = {
                     dst: src for dst, src in childcopies.items() if match(dst)
@@ -311,7 +334,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: mercurial-devel


More information about the Mercurial-devel mailing list