Writing a template which displays only relevant parents
Yuya Nishihara
yuya at tcha.org
Mon Feb 8 15:32:27 UTC 2016
On Sun, 7 Feb 2016 16:38:06 +0100, Dr Rainer Woitok wrote:
> On Friday, 2016-02-05 23:04:14 +0900, you wrote:
> > {ifeq(count(revset('%d:%d', p1rev, rev)), 2, '*', '{p1rev}:{p1node|short}')}
>
> Thanks for pointing this out. I missed these two examples in "hg help
> template". Works like a charm now :-) at least result-wise. But effic-
> iency-wise? Consider what we are doing here: we first compute a revset
> (which might be huge) and then we count its members (which might take
> some time, because the revset might be huge) just to finally compare
> this count to 2.
revset computation can be lazy, but in this case, it will create a list of
all matches. It might be slow.
> What about a template specific function "py(expr)" which returns the re-
> sult of an arbitrary Python expression?
I generally don't like an idea that allows code injection. It isn't a template
library to be embedded in a web application.
FWIW, it will be easy to write an extension that adds a thin wrapper for
eval(expr).
> > ...
> > You can insert whitespaces in non-string part.
> >
> > x = blah blah{
> > func(x,
> > y)}
>
> Did you test this with a real template?
It worked for me:
[ui]
logtemplate = rev: {
rev
} node: {short(
node)}\n
> I'm on Mercurial 3.7-rc+epsilon
> and I didn't get this to work. What did work, however, was
>
> x = 'blah blah{
> func(x,
> y)}'
>
> that is, to quote the whole template. But since template syntax requir-
> es quoted strings embedded in quoted strings embedded in quoted strings
> embedded ... and so on, and since there are only two types of string
> quotes, this now requires still more backslashes :-(
{"{"{rev}"}"} is fully valid since Mercurial 3.5. It's handled just like a
shell command expansion or string interpolation of Ruby. But if a string is
escaped, e.g. \"...\", it is pre-parsed as a string. This hack exists for
backward compatibility as there were two conflicting syntax rules before 3.5.
> > > - Is there a way to "call" a user defined template from within anoth-
> > > er user defined template?
> > > ...
> >
> > Not yet, but I'm thinking of it.
>
> Is there already some time-line or version-line for this new feature?
No. Please watch the issue if you're interested in.
https://bz.mercurial-scm.org/show_bug.cgi?id=4842
More information about the Mercurial
mailing list