templatekw: move getrenamedfn() to scmutil (API)
The function is already used by `hg log` (for following renames, not
for templates), so it seems it does not belong in templatekw.
Differential Revision: https://phab.mercurial-scm.org/D6021
--- a/hgext/remotefilelog/__init__.py Sat Feb 23 09:32:07 2019 -0800
+++ b/hgext/remotefilelog/__init__.py Thu Feb 21 10:54:29 2019 -0800
@@ -159,7 +159,6 @@
scmutil,
smartset,
streamclone,
- templatekw,
util,
)
from . import (
@@ -557,7 +556,7 @@
extensions.wrapfunction(dispatch, 'runcommand', runcommand)
# disappointing hacks below
- templatekw.getrenamedfn = getrenamedfn
+ scmutil.getrenamedfn = getrenamedfn
extensions.wrapfunction(revset, 'filelog', filelogrevset)
revset.symbols['filelog'] = revset.filelog
extensions.wrapfunction(cmdutil, 'walkfilerevs', walkfilerevs)
--- a/mercurial/commands.py Sat Feb 23 09:32:07 2019 -0800
+++ b/mercurial/commands.py Thu Feb 21 10:54:29 2019 -0800
@@ -61,7 +61,6 @@
state as statemod,
streamclone,
tags as tagsmod,
- templatekw,
ui as uimod,
util,
wireprotoserver,
@@ -3884,7 +3883,7 @@
endrev = None
if revs:
endrev = revs.max() + 1
- getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
+ getrenamed = scmutil.getrenamedfn(repo, endrev=endrev)
ui.pager('log')
displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ,
--- a/mercurial/scmutil.py Sat Feb 23 09:32:07 2019 -0800
+++ b/mercurial/scmutil.py Thu Feb 21 10:54:29 2019 -0800
@@ -1191,6 +1191,37 @@
for new, old in renames.iteritems():
wctx.copy(old, new)
+def getrenamedfn(repo, endrev=None):
+ rcache = {}
+ if endrev is None:
+ endrev = len(repo)
+
+ def getrenamed(fn, rev):
+ '''looks up all renames for a file (up to endrev) the first
+ time the file is given. It indexes on the changerev and only
+ parses the manifest if linkrev != changerev.
+ Returns rename info for fn at changerev rev.'''
+ if fn not in rcache:
+ rcache[fn] = {}
+ fl = repo.file(fn)
+ for i in fl:
+ lr = fl.linkrev(i)
+ renamed = fl.renamed(fl.node(i))
+ rcache[fn][lr] = renamed and renamed[0]
+ if lr >= endrev:
+ break
+ if rev in rcache[fn]:
+ return rcache[fn][rev]
+
+ # If linkrev != rev (i.e. rev not found in rcache) fallback to
+ # filectx logic.
+ try:
+ return repo[rev][fn].copysource()
+ except error.LookupError:
+ return None
+
+ return getrenamed
+
def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
"""Update the dirstate to reflect the intent of copying src to dst. For
different reasons it might not end with dst being marked as copied from src.
--- a/mercurial/templatekw.py Sat Feb 23 09:32:07 2019 -0800
+++ b/mercurial/templatekw.py Thu Feb 21 10:54:29 2019 -0800
@@ -104,37 +104,6 @@
latesttags[rev] = pdate, pdist + 1, ptag
return latesttags[rev]
-def getrenamedfn(repo, endrev=None):
- rcache = {}
- if endrev is None:
- endrev = len(repo)
-
- def getrenamed(fn, rev):
- '''looks up all renames for a file (up to endrev) the first
- time the file is given. It indexes on the changerev and only
- parses the manifest if linkrev != changerev.
- Returns rename info for fn at changerev rev.'''
- if fn not in rcache:
- rcache[fn] = {}
- fl = repo.file(fn)
- for i in fl:
- lr = fl.linkrev(i)
- renamed = fl.renamed(fl.node(i))
- rcache[fn][lr] = renamed and renamed[0]
- if lr >= endrev:
- break
- if rev in rcache[fn]:
- return rcache[fn][rev]
-
- # If linkrev != rev (i.e. rev not found in rcache) fallback to
- # filectx logic.
- try:
- return repo[rev][fn].copysource()
- except error.LookupError:
- return None
-
- return getrenamed
-
def getlogcolumns():
"""Return a dict of log column labels"""
_ = pycompat.identity # temporarily disable gettext
@@ -343,7 +312,7 @@
copies = context.resource(mapping, 'revcache').get('copies')
if copies is None:
if 'getrenamed' not in cache:
- cache['getrenamed'] = getrenamedfn(repo)
+ cache['getrenamed'] = scmutil.getrenamedfn(repo)
copies = []
getrenamed = cache['getrenamed']
for fn in ctx.files():