Writing a template which displays only relevant parents

Dr Rainer Woitok rainer.woitok at gmail.com
Fri Feb 5 13:21:02 UTC 2016


Matt,

On Thursday, 2016-02-04 12:06:30 -0600, you wrote:

> ...
> There is in fact a way to "do the math",

Well, I hoped there is ... :-)

>                                          namely by using the revset template
> function together with if.

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})}

but to no avail.  I always got parse errors.   What am I missing regard-
ing the syntay required by the templater?

>                            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.   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}"?

> $ hg log -l15 -T '{rev}: {join(parents % "{rev}", ", ")}\n'
> 34135: 34135, 34135
> ...

And while we are talking about templates:

   - 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?

   - 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 ...}

     Thus there would only be one place where the first line of all oth-
     er personal templates would have to be defined.

   - 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 `"\{"´?

Sincerely,
  Rainer



More information about the Mercurial mailing list