Mercurial > hg-stable
changeset 26234:e4609ec959f8
templater: switch ctx of list expression to rev of revset() (BC)
Because revset() function generates a list of revisions, it seems sensible
to switch the ctx as well where a list expression will be evaluated. I think
"{revset(...) % "..."}" expression wasn't considered well when it was
introduced at cda9d2b6beab.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 12 Sep 2015 00:21:41 +0900 |
parents | d3dbb65c8dc6 |
children | 6c962145f523 |
files | mercurial/help/templates.txt mercurial/templatekw.py mercurial/templater.py tests/test-command-template.t |
diffstat | 4 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/help/templates.txt Thu Sep 10 23:32:36 2015 +0900 +++ b/mercurial/help/templates.txt Sat Sep 12 00:21:41 2015 +0900 @@ -106,6 +106,10 @@ $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n" +- Show details of parent revisions:: + + $ hg log --template "{revset('parents(%d)', rev) % '{desc|firstline}\n'}" + - Show only commit descriptions that start with "template":: $ hg log --template "{startswith('template', firstline(desc))}\n"
--- a/mercurial/templatekw.py Thu Sep 10 23:32:36 2015 +0900 +++ b/mercurial/templatekw.py Sat Sep 12 00:21:41 2015 +0900 @@ -409,6 +409,14 @@ """:rev: Integer. The repository-local changeset revision number.""" return scmutil.intrev(ctx.rev()) +def showrevslist(name, revs, **args): + """helper to generate a list of revisions in which a mapped template will + be evaluated""" + repo = args['ctx'].repo() + f = _showlist(name, revs, **args) + return _hybrid(f, revs, + lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}) + def showsubrepos(**args): """:subrepos: List of strings. Updated subrepositories in the changeset.""" ctx = args['ctx']
--- a/mercurial/templater.py Thu Sep 10 23:32:36 2015 +0900 +++ b/mercurial/templater.py Sat Sep 12 00:21:41 2015 +0900 @@ -568,7 +568,7 @@ revs = list([str(r) for r in revs]) revsetcache[raw] = revs - return templatekw.showlist("revision", revs, **mapping) + return templatekw.showrevslist("revision", revs, **mapping) def rstdoc(context, mapping, args): """:rstdoc(text, style): Format ReStructuredText."""
--- a/tests/test-command-template.t Thu Sep 10 23:32:36 2015 +0900 +++ b/tests/test-command-template.t Sat Sep 12 00:21:41 2015 +0900 @@ -3234,6 +3234,23 @@ $ hg log --template '{revset("TIP"|lower)}\n' -l1 2 + a list template is evaluated for each item of revset + + $ hg log -T '{rev} p: {revset("p1(%s)", rev) % "{rev}:{node|short}"}\n' + 2 p: 1:bcc7ff960b8e + 1 p: 0:f7769ec2ab97 + 0 p: + + therefore, 'revcache' should be recreated for each rev + + $ hg log -T '{rev} {file_adds}\np {revset("p1(%s)", rev) % "{file_adds}"}\n' + 2 aa b + p + 1 + p a + 0 a + p + Test active bookmark templating $ hg book foo