Writing a template which displays only relevant parents
Yuya Nishihara
yuya at tcha.org
Fri Feb 5 14:04:14 UTC 2016
On Fri, 5 Feb 2016 14:21:02 +0100, Dr Rainer Woitok wrote:
> I have already found the "revset" template function in "man/man1/hg.1"
> but the description is rather terse and in particular it does not at all
> explain the second argument (if that matters at all for the case at
> hand):
>
> revset(query[, formatargs...])
> Execute a revision set query. See hg help revset.
>
> Among several others I tried the following variants
>
> {ifeq(count(revset(p1rev:rev)),2),'*',{p1rev}:{p1node|short})}
> {ifeq(revset(p1rev:rev),revset(last(p1rev:rev,2)),'*',{p1rev}:{p1node|short})}
You need to pass a string query. "hg help template" has some examples.
{ifeq(count(revset('{p1rev}:{rev}')), 2, '*', '{p1rev}:{p1node|short}')}
or
{ifeq(count(revset('%d:%d', p1rev, rev)), 2, '*', '{p1rev}:{p1node|short}')}
The latter isn't documented well.
> > But the smarts you want are already built into
> > "parents":
>
> I assume, with "smarts" you refer to splitting "parents" into a comma
> separated list rather than to my real problem of replacing the trivial
> parent with an asterisk.
You could do
{if(parents, parents, '*')}
> Anyway, as you can see from the output prod-
> uced by your template, "{rev}" always refers to the revision number of
> the changeset being logged rather than to the revision numbers included
> in "parents". That's exactly what originally caused me to spell it out
> in my template using "{p[12]rev}" and "{p[12]node}". Is there something
> like "{parent.rev}"?
It seems "parents" isn't ported to new-style template yet. {parents % "{rev}"}
should work, but it doesn't now.
> - Currently, my log template sums up to almost 400 characters in a
> single line. Attempts to split it into several lines by escaping
> the lineend with a backslash in the usual manner were not under-
> stood by the templater. Is there a way to split templates into
> several lines?
You can insert whitespaces in non-string part.
x = blah blah{
func(x,
y)}
> - Is there a way to "call" a user defined template from within anoth-
> er user defined template? As in:
>
> [templates]
> log = {headline}{... remaining "log" template ...}
> tip = {headline}{... remaining "tip" template ...}
> heads = {headline}{... remaining "heads" template ...}
> headline = {... common sub-template for all other templates ...}
Not yet, but I'm thinking of it.
> - In "man/man1/hg.1" I simply did not understand the following pass-
> age:
>
> · expr % "{template}"
>
> As seen in the above example, "{template}" is interpreted as a tem‐
> plate. To prevent it from being interpreted, you can use an escape
> character "{" or a raw string prefix, "r'...'".
>
> Is this just a typo and `"{"´ should be replaced with `"\{"´?
Yep. It looks like '\' is processed as an escape character of reStructuredText.
More information about the Mercurial
mailing list