Mercurial > hg-stable
changeset 42518: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 | c929f612afac |
children | a68350a7fc55 |
files | mercurial/scmutil.py mercurial/templatekw.py |
diffstat | 2 files changed, 26 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/scmutil.py Tue Jun 18 23:19:24 2019 -0700 +++ b/mercurial/scmutil.py Wed Jun 19 09:59:45 2019 -0700 @@ -1247,6 +1247,28 @@ return getrenamed +def getcopiesfn(repo, endrev=None): + if copiesmod.usechangesetcentricalgo(repo): + def copiesfn(ctx): + if ctx.p2copies(): + allcopies = ctx.p1copies().copy() + # There should be no overlap + allcopies.update(ctx.p2copies()) + return sorted(allcopies.items()) + else: + return sorted(ctx.p1copies().items()) + else: + getrenamed = getrenamedfn(repo, endrev) + def copiesfn(ctx): + copies = [] + for fn in ctx.files(): + rename = getrenamed(fn, ctx.rev()) + if rename: + copies.append((fn, rename)) + return copies + + return copiesfn + 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 Tue Jun 18 23:19:24 2019 -0700 +++ b/mercurial/templatekw.py Wed Jun 19 09:59:45 2019 -0700 @@ -301,14 +301,10 @@ cache = context.resource(mapping, 'cache') copies = context.resource(mapping, 'revcache').get('copies') if copies is None: - if 'getrenamed' not in cache: - cache['getrenamed'] = scmutil.getrenamedfn(repo) - copies = [] - getrenamed = cache['getrenamed'] - for fn in ctx.files(): - rename = getrenamed(fn, ctx.rev()) - if rename: - copies.append((fn, rename)) + if 'getcopies' not in cache: + cache['getcopies'] = scmutil.getcopiesfn(repo) + getcopies = cache['getcopies'] + copies = getcopies(ctx) return templateutil.compatfilecopiesdict(context, mapping, 'file_copy', copies)