##// END OF EJS Templates
templatekw: move getrenamedfn() to scmutil (API)...
Martin von Zweigbergk -
r41947:e9b9ee9a default
parent child Browse files
Show More
@@ -159,7 +159,6 b' from mercurial import ('
159 159 scmutil,
160 160 smartset,
161 161 streamclone,
162 templatekw,
163 162 util,
164 163 )
165 164 from . import (
@@ -557,7 +556,7 b' def onetimeclientsetup(ui):'
557 556 extensions.wrapfunction(dispatch, 'runcommand', runcommand)
558 557
559 558 # disappointing hacks below
560 templatekw.getrenamedfn = getrenamedfn
559 scmutil.getrenamedfn = getrenamedfn
561 560 extensions.wrapfunction(revset, 'filelog', filelogrevset)
562 561 revset.symbols['filelog'] = revset.filelog
563 562 extensions.wrapfunction(cmdutil, 'walkfilerevs', walkfilerevs)
@@ -61,7 +61,6 b' from . import ('
61 61 state as statemod,
62 62 streamclone,
63 63 tags as tagsmod,
64 templatekw,
65 64 ui as uimod,
66 65 util,
67 66 wireprotoserver,
@@ -3884,7 +3883,7 b' def log(ui, repo, *pats, **opts):'
3884 3883 endrev = None
3885 3884 if revs:
3886 3885 endrev = revs.max() + 1
3887 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
3886 getrenamed = scmutil.getrenamedfn(repo, endrev=endrev)
3888 3887
3889 3888 ui.pager('log')
3890 3889 displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ,
@@ -1191,6 +1191,37 b' def _markchanges(repo, unknown, deleted,'
1191 1191 for new, old in renames.iteritems():
1192 1192 wctx.copy(old, new)
1193 1193
1194 def getrenamedfn(repo, endrev=None):
1195 rcache = {}
1196 if endrev is None:
1197 endrev = len(repo)
1198
1199 def getrenamed(fn, rev):
1200 '''looks up all renames for a file (up to endrev) the first
1201 time the file is given. It indexes on the changerev and only
1202 parses the manifest if linkrev != changerev.
1203 Returns rename info for fn at changerev rev.'''
1204 if fn not in rcache:
1205 rcache[fn] = {}
1206 fl = repo.file(fn)
1207 for i in fl:
1208 lr = fl.linkrev(i)
1209 renamed = fl.renamed(fl.node(i))
1210 rcache[fn][lr] = renamed and renamed[0]
1211 if lr >= endrev:
1212 break
1213 if rev in rcache[fn]:
1214 return rcache[fn][rev]
1215
1216 # If linkrev != rev (i.e. rev not found in rcache) fallback to
1217 # filectx logic.
1218 try:
1219 return repo[rev][fn].copysource()
1220 except error.LookupError:
1221 return None
1222
1223 return getrenamed
1224
1194 1225 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
1195 1226 """Update the dirstate to reflect the intent of copying src to dst. For
1196 1227 different reasons it might not end with dst being marked as copied from src.
@@ -104,37 +104,6 b' def getlatesttags(context, mapping, patt'
104 104 latesttags[rev] = pdate, pdist + 1, ptag
105 105 return latesttags[rev]
106 106
107 def getrenamedfn(repo, endrev=None):
108 rcache = {}
109 if endrev is None:
110 endrev = len(repo)
111
112 def getrenamed(fn, rev):
113 '''looks up all renames for a file (up to endrev) the first
114 time the file is given. It indexes on the changerev and only
115 parses the manifest if linkrev != changerev.
116 Returns rename info for fn at changerev rev.'''
117 if fn not in rcache:
118 rcache[fn] = {}
119 fl = repo.file(fn)
120 for i in fl:
121 lr = fl.linkrev(i)
122 renamed = fl.renamed(fl.node(i))
123 rcache[fn][lr] = renamed and renamed[0]
124 if lr >= endrev:
125 break
126 if rev in rcache[fn]:
127 return rcache[fn][rev]
128
129 # If linkrev != rev (i.e. rev not found in rcache) fallback to
130 # filectx logic.
131 try:
132 return repo[rev][fn].copysource()
133 except error.LookupError:
134 return None
135
136 return getrenamed
137
138 107 def getlogcolumns():
139 108 """Return a dict of log column labels"""
140 109 _ = pycompat.identity # temporarily disable gettext
@@ -343,7 +312,7 b' def showfilecopies(context, mapping):'
343 312 copies = context.resource(mapping, 'revcache').get('copies')
344 313 if copies is None:
345 314 if 'getrenamed' not in cache:
346 cache['getrenamed'] = getrenamedfn(repo)
315 cache['getrenamed'] = scmutil.getrenamedfn(repo)
347 316 copies = []
348 317 getrenamed = cache['getrenamed']
349 318 for fn in ctx.files():
General Comments 0
You need to be logged in to leave comments. Login now