Mercurial > hg
comparison mercurial/scmutil.py @ 42503:88ba0ff94605
copies: create helper for getting all copies for changeset
There are a few places where we get all the copies for a changeset (at
least the {file_copies} template and in two places in `hg log
--copies` code). These places currently call scmutil.getrenamedfn() to
get a caching "getrenamed" function. They all use it in a similar
way. We will be able to reuse more code by having a function for
getting all the copies for a changeset. This patch introduces such a
function. It uses it in the {file_copies} template to show that it
works. It relies on the existing scmutil.getrenamedfn() for caching in
the filelog-centric case.
Differential Revision: https://phab.mercurial-scm.org/D6545
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 19 Jun 2019 09:59:45 -0700 |
parents | 27475ae67676 |
children | ea6558db1011 |
comparison
equal
deleted
inserted
replaced
42502:c929f612afac | 42503:88ba0ff94605 |
---|---|
1245 except error.LookupError: | 1245 except error.LookupError: |
1246 return None | 1246 return None |
1247 | 1247 |
1248 return getrenamed | 1248 return getrenamed |
1249 | 1249 |
1250 def getcopiesfn(repo, endrev=None): | |
1251 if copiesmod.usechangesetcentricalgo(repo): | |
1252 def copiesfn(ctx): | |
1253 if ctx.p2copies(): | |
1254 allcopies = ctx.p1copies().copy() | |
1255 # There should be no overlap | |
1256 allcopies.update(ctx.p2copies()) | |
1257 return sorted(allcopies.items()) | |
1258 else: | |
1259 return sorted(ctx.p1copies().items()) | |
1260 else: | |
1261 getrenamed = getrenamedfn(repo, endrev) | |
1262 def copiesfn(ctx): | |
1263 copies = [] | |
1264 for fn in ctx.files(): | |
1265 rename = getrenamed(fn, ctx.rev()) | |
1266 if rename: | |
1267 copies.append((fn, rename)) | |
1268 return copies | |
1269 | |
1270 return copiesfn | |
1271 | |
1250 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): | 1272 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
1251 """Update the dirstate to reflect the intent of copying src to dst. For | 1273 """Update the dirstate to reflect the intent of copying src to dst. For |
1252 different reasons it might not end with dst being marked as copied from src. | 1274 different reasons it might not end with dst being marked as copied from src. |
1253 """ | 1275 """ |
1254 origsrc = repo.dirstate.copied(src) or src | 1276 origsrc = repo.dirstate.copied(src) or src |