##// END OF EJS Templates
templatefilters: handle TypeError by count()...
Yuya Nishihara -
r37246:05db4273 default
parent child Browse files
Show More
@@ -11,6 +11,7 b' import os'
11 import re
11 import re
12 import time
12 import time
13
13
14 from .i18n import _
14 from . import (
15 from . import (
15 encoding,
16 encoding,
16 error,
17 error,
@@ -101,7 +102,10 b' def basename(path):'
101 @templatefilter('count')
102 @templatefilter('count')
102 def count(i):
103 def count(i):
103 """List or text. Returns the length as an integer."""
104 """List or text. Returns the length as an integer."""
105 try:
104 return len(i)
106 return len(i)
107 except TypeError:
108 raise error.ParseError(_('not countable'))
105
109
106 @templatefilter('dirname', intype=bytes)
110 @templatefilter('dirname', intype=bytes)
107 def dirname(path):
111 def dirname(path):
@@ -2277,6 +2277,11 b' Count filter:'
2277 o 0: children: 1, tags: 0, file_adds: 1, ancestors: 1
2277 o 0: children: 1, tags: 0, file_adds: 1, ancestors: 1
2278
2278
2279
2279
2280 $ hg log -l1 -T '{termwidth|count}\n'
2281 hg: parse error: not countable
2282 (template filter 'count' is not compatible with keyword 'termwidth')
2283 [255]
2284
2280 Upper/lower filters:
2285 Upper/lower filters:
2281
2286
2282 $ hg log -r0 --template '{branch|upper}\n'
2287 $ hg log -r0 --template '{branch|upper}\n'
@@ -3266,7 +3271,8 b' Test min/max of if() result'
3266 Test laziness of if() then/else clause
3271 Test laziness of if() then/else clause
3267
3272
3268 $ hg debugtemplate '{count(0)}'
3273 $ hg debugtemplate '{count(0)}'
3269 abort: incompatible use of template filter 'count'
3274 hg: parse error: not countable
3275 (incompatible use of template filter 'count')
3270 [255]
3276 [255]
3271 $ hg debugtemplate '{if(true, "", count(0))}'
3277 $ hg debugtemplate '{if(true, "", count(0))}'
3272 $ hg debugtemplate '{if(false, count(0), "")}'
3278 $ hg debugtemplate '{if(false, count(0), "")}'
General Comments 0
You need to be logged in to leave comments. Login now