[PATCH] Add splitlines, wordN, and startswith to templates

Durham Goode durham at fb.com
Mon Apr 14 16:49:22 CDT 2014


On 4/11/14, 11:54 PM, Siddharth Agarwal wrote:
> On 04/11/2014 11:45 PM, Ryan McElroy wrote:
>> # HG changeset patch
>> # User Ryan McElroy <ryanmce at gmail.com <mailto:ryanmce at gmail.com>>
>> # Date 1397283707 25200
>> #      Fri Apr 11 23:21:47 2014 -0700
>> # Node ID 5701aea429330d7499f2f3de6fd633559b5dfbf3
>> # Parent  40800668e01921e41db1eb97d19e473971e93f5e
>> Add splitlines, wordN, and startswith to templates
>
> Please see http://mercurial.selenic.com/wiki/ContributingChanges. In 
> particular, this should be split up into multiple patches, each 
> introducing a keyword/function, and each with corresponding tests.
>
>> @@ -384,6 +393,7 @@
>>      "short": short,
>>      "shortbisect": shortbisect,
>>      "shortdate": shortdate,
>> +    "splitlines": splitlines,
>>      "stringescape": stringescape,
>>      "stringify": stringify,
>>      "strip": strip,
>> @@ -392,6 +402,9 @@
>>      "urlescape": urlescape,
>>      "user": userfilter,
>>      "emailuser": emailuser,
>> +    "word1": takeword(0),
>> +    "word2": takeword(1),
>> +    "word3": takeword(2),
>
> This isn't great. What about words beyond the third one?
>
> FWIW, if there's a need for something specifically like this, we can 
> implement and distribute it within FB as an extension.

split() and atindex() functions might be a more generic way to do this 
kind of stuff. 'split({desc}, '\n')' would give you lines, and 
'split({line}, ' ')' would give you words.  atindex(3, split({line}, ' 
')) would give you the third word (and you could do the same to get the 
3rd line).  splitting over words would also allow you to iterate over 
the words, looking for the D#### formatted word (instead of hard coding 
it as the 3rd word).


More information about the Mercurial-devel mailing list