[PATCH] identify: add template support

Yuya Nishihara yuya at tcha.org
Sun Jun 25 20:56:35 EDT 2017


On Sun, 25 Jun 2017 20:47:45 -0400, Matt Harbison wrote:
> On Sun, 25 Jun 2017 20:41:21 -0400, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> > On Sun, 25 Jun 2017 16:20:46 -0400, Matt Harbison wrote:
> >> On Sun, 25 Jun 2017 08:19:29 -0400, Yuya Nishihara <yuya at tcha.org>  
> >> wrote:
> >>
> >> > On Sun, 25 Jun 2017 01:23:41 -0400, Matt Harbison wrote:
> >> >> # HG changeset patch
> >> >> # User Matt Harbison <matt_harbison at yahoo.com>
> >> >> # Date 1498360161 14400
> >> >> #      Sat Jun 24 23:09:21 2017 -0400
> >> >> # Node ID 1e917448c8d5c36f19c41bc83793df3e92477ede
> >> >> # Parent  8299eb9b08c79699f496717d626842b72fa5ca4f
> >> >> identify: add template support
> >> >
> >> ...
> >>
> >> >
> >> >> Yuya mentioned using fm.nested() in that thread, so I did for the
> >> >> parent nodes.
> >> >> I'm not sure if the plan is to fill in all of the context attributes  
> >> in
> >> >> these
> >> >> items, or if these nested items should simply be made {p1node} and
> >> >> {p1rev}.
> >> >
> >> > [...]
> >> >
> >> >> +            for i, p in enumerate(parents):
> >> >> +                fn = fm.nested('p%d' % (i + 1))
> >> >> +                fn.startitem()
> >> >> +                fn.data(rev=p.rev())
> >> >> +                fn.data(node=p.hex())
> >> >> +                fn.end()
> >> >
> >> > I meant this could be a {parents} list, which is
> >> >
> >> >   fn = fm.nested('parents')
> >> >   for ...
> >> >       fn.startitem()
> >> >       ...
> >> >
> >> > Each item could have fn.context(ctx=p) so that all template keywrods  
> >> are
> >> > available.
> >>
> >> I saw that, and tried it, but I didn't think it worked.  I was expecting
> >> lines in the json output I guess.  But after digging in a bit more,  
> >> maybe
> >> it's just a bug in nested formatters?
> >
> > Yeah, it's the bug of formatter. I'll send a fix shortly.
> 
> Actually, it seems to work if fm.context(ctx=ctx) is set too.  But now  
> there's an off by one issue:
> 
> $ ../hg log -r . -T "{latesttag % '{changes}'}
> 913
> $ ../hg id -T "{p1 % '{latesttag() % \'{changes}\'}'}"
> 914
> 
> (Unless the bug is fn is only looking at fm's ctx?)

That depends on how the templater processes nested items. Outer template dict
is just _copied_ and updated by inner items.


More information about the Mercurial-devel mailing list