[PATCH 2 of 3] templater: add len template filter

Mads Kiilerich mads at kiilerich.com
Mon Sep 8 21:03:02 CDT 2014


On 09/08/2014 02:04 PM, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <engored at ya.ru>
> # Date 1410176607 -32400
> #      Mon Sep 08 20:43:27 2014 +0900
> # Node ID 82b3cffda4868d23ce436adac8687645f5f7441b
> # Parent  9bb0ab35e90ac9ebf6adbd6e503f3412d9f2adb7
> templater: add len template filter

Most excellent, thanks!

I had thought about implementing something like this and call it "count" 
instead. I am not sure I like that this approach exposes whatever python 
len does ... but I guess it is ok and can be handy.

The combination of log and revset and len is very powerful (and 
potentially slow). I think that combination also should have some test 
coverage. Perhaps by adding root distance: {revset("::%d",rev)|len} .

Personally, I would prefer to have the test in the same changeset as the 
code so it helps documenting why the change is made. That makes history 
digging so much easier.


I like how this feature almost can replace the {latesttag} and 
{latesttagdistance} concepts with something like:
hg log -r 'tagged()' -T '{revset("%d::.",rev)|len}  {tags}\n'

The following idiom for getting the size of a revset can also be handy 
but is a bit ugly:
hg log -r null -T '{revset("::3.1-::3.0")|len}\n'

I guess templatification of "id" will make that a better way to get the 
size of a revset result ... but a dedicated 'count' command could 
perhaps also be handy.

/Mads




More information about the Mercurial-devel mailing list