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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Sep 9 04:10:56 CDT 2014



On 09/09/2014 03:03 AM, Mads Kiilerich wrote:
> 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'

Note that you can now use:  only("3.1", "3.0") instead of ::"3.1" - :: 
"3.0".

(I also agree with the mads review here, no strong opinion about len vs 
length vs count. Small preference for count.)

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list