Mercurial > hg-stable
changeset 43255:b8d60845fa5d
copies: extract data extraction into a `revinfo` function
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.
Differential Revision: https://phab.mercurial-scm.org/D7070
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 02 Oct 2019 17:42:01 -0400 |
parents | 181d28ba05da |
children | 00de32aa834e |
files | mercurial/copies.py |
diffstat | 1 files changed, 26 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/copies.py Wed Oct 16 17:49:30 2019 +0200 +++ b/mercurial/copies.py Wed Oct 02 17:42:01 2019 -0400 @@ -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)