From patchwork Sat Oct 12 16:46:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7070: copies: extract data extraction into a `revinfo` function From: phabricator X-Patchwork-Id: 42270 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Sat, 12 Oct 2019 16:46:24 +0000 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 To: marmoute, #hg-reviewers Cc: mercurial-devel 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 "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)