##// END OF EJS Templates
templater: implement _hybrid.__contains__ so that ifcontains can accept dict...
Yuya Nishihara -
r24240:bd504d90 default
parent child Browse files
Show More
@@ -12,6 +12,8 b' import hbisect'
12 12 # This helper class allows us to handle both:
13 13 # "{files}" (legacy command-line-specific list hack) and
14 14 # "{files % '{file}\n'}" (hgweb-style with inlining and function support)
15 # and to access raw values:
16 # "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
15 17
16 18 class _hybrid(object):
17 19 def __init__(self, gen, values, makemap, joinfmt=None):
@@ -28,6 +30,8 b' class _hybrid(object):'
28 30 makemap = self._makemap
29 31 for x in self.values:
30 32 yield makemap(x)
33 def __contains__(self, x):
34 return x in self.values
31 35 def __len__(self):
32 36 return len(self.values)
33 37
@@ -330,10 +330,7 b' def ifcontains(context, mapping, args):'
330 330 item = stringify(args[0][0](context, mapping, args[0][1]))
331 331 items = args[1][0](context, mapping, args[1][1])
332 332
333 # Iterating over items gives a formatted string, so we iterate
334 # directly over the raw values.
335 if ((callable(items) and item in [i.values()[0] for i in items()]) or
336 (isinstance(items, str) and item in items)):
333 if item in items:
337 334 yield _evalifliteral(args[2], context, mapping)
338 335 elif len(args) == 4:
339 336 yield _evalifliteral(args[3], context, mapping)
@@ -47,6 +47,9 b' Second branch starting at nullrev:'
47 47 fourth (second)
48 48 $ hg log -T '{file_copies % "{source} -> {name}\n"}' -r .
49 49 second -> fourth
50 $ hg log -T '{rev} {ifcontains("fourth", file_copies, "t", "f")}\n' -r .:7
51 8 t
52 7 f
50 53
51 54 Quoting for ui.logtemplate
52 55
@@ -2386,6 +2389,10 b' Test current bookmark templating'
2386 2389 2 bar foo
2387 2390 1 baz
2388 2391 0
2392 $ hg log --template "{rev} {ifcontains('foo', bookmarks, 't', 'f')}\n"
2393 2 t
2394 1 f
2395 0 f
2389 2396
2390 2397 Test stringify on sub expressions
2391 2398
General Comments 0
You need to be logged in to leave comments. Login now