Submitter | Yuya Nishihara |
---|---|
Date | Sept. 12, 2015, 3:07 p.m. |
Message ID | <c84a1730514ee1905269.1442070438@mimosa> |
Download | mbox | patch |
Permalink | /patch/10488/ |
State | Accepted |
Headers | show |
Comments
On Sun, 2015-09-13 at 00:07 +0900, Yuya Nishihara wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1441984901 -32400 > # Sat Sep 12 00:21:41 2015 +0900 > # Node ID c84a1730514ee190526966250110fe4cf740d8d1 > # Parent efebefe162e98aa79438daaea9aaee47c7de33bb > 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. Looks good to me, queued for default.
On 09/12/2015 08:07 AM, Yuya Nishihara wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1441984901 -32400 > # Sat Sep 12 00:21:41 2015 +0900 > # Node ID c84a1730514ee190526966250110fe4cf740d8d1 > # Parent efebefe162e98aa79438daaea9aaee47c7de33bb > 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. Do we have user facing documentation explaining the meaning of %d and %s here?
On Mon, 14 Sep 2015 10:05:47 -0700, Pierre-Yves David wrote: > On 09/12/2015 08:07 AM, Yuya Nishihara wrote: > > # HG changeset patch > > # User Yuya Nishihara <yuya@tcha.org> > > # Date 1441984901 -32400 > > # Sat Sep 12 00:21:41 2015 +0900 > > # Node ID c84a1730514ee190526966250110fe4cf740d8d1 > > # Parent efebefe162e98aa79438daaea9aaee47c7de33bb > > 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. > > Do we have user facing documentation explaining the meaning of %d and %s > here? I think no. It also lacks error handling as revset.formatspec() is internal function.
Patch
diff --git a/mercurial/help/templates.txt b/mercurial/help/templates.txt --- a/mercurial/help/templates.txt +++ b/mercurial/help/templates.txt @@ -106,6 +106,10 @@ Some sample command line templates: $ 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" diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -409,6 +409,14 @@ def showrev(repo, ctx, templ, **args): """: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'] diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -575,7 +575,7 @@ def revset(context, mapping, args): 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.""" diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -3234,6 +3234,23 @@ Test revset function $ 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