comparison mercurial/scmutil.py @ 41790:e9b9ee9af4a9

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
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 21 Feb 2019 10:54:29 -0800
parents e21183db2259
children 64de5f44eec3
comparison
equal deleted inserted replaced
41789:18f619d3b1bb 41790:e9b9ee9af4a9
1189 wctx.forget(deleted) 1189 wctx.forget(deleted)
1190 wctx.add(unknown) 1190 wctx.add(unknown)
1191 for new, old in renames.iteritems(): 1191 for new, old in renames.iteritems():
1192 wctx.copy(old, new) 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 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): 1225 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
1195 """Update the dirstate to reflect the intent of copying src to dst. For 1226 """Update the dirstate to reflect the intent of copying src to dst. For
1196 different reasons it might not end with dst being marked as copied from src. 1227 different reasons it might not end with dst being marked as copied from src.
1197 """ 1228 """
1198 origsrc = repo.dirstate.copied(src) or src 1229 origsrc = repo.dirstate.copied(src) or src