Show More
@@ -12,6 +12,8 b' import hbisect' | |||||
12 | # This helper class allows us to handle both: |
|
12 | # This helper class allows us to handle both: | |
13 | # "{files}" (legacy command-line-specific list hack) and |
|
13 | # "{files}" (legacy command-line-specific list hack) and | |
14 | # "{files % '{file}\n'}" (hgweb-style with inlining and function support) |
|
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 | class _hybrid(object): |
|
18 | class _hybrid(object): | |
17 | def __init__(self, gen, values, makemap, joinfmt=None): |
|
19 | def __init__(self, gen, values, makemap, joinfmt=None): | |
@@ -28,6 +30,8 b' class _hybrid(object):' | |||||
28 | makemap = self._makemap |
|
30 | makemap = self._makemap | |
29 | for x in self.values: |
|
31 | for x in self.values: | |
30 | yield makemap(x) |
|
32 | yield makemap(x) | |
|
33 | def __contains__(self, x): | |||
|
34 | return x in self.values | |||
31 | def __len__(self): |
|
35 | def __len__(self): | |
32 | return len(self.values) |
|
36 | return len(self.values) | |
33 |
|
37 |
@@ -330,10 +330,7 b' def ifcontains(context, mapping, args):' | |||||
330 | item = stringify(args[0][0](context, mapping, args[0][1])) |
|
330 | item = stringify(args[0][0](context, mapping, args[0][1])) | |
331 | items = args[1][0](context, mapping, args[1][1]) |
|
331 | items = args[1][0](context, mapping, args[1][1]) | |
332 |
|
332 | |||
333 | # Iterating over items gives a formatted string, so we iterate |
|
333 | if item in items: | |
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)): |
|
|||
337 | yield _evalifliteral(args[2], context, mapping) |
|
334 | yield _evalifliteral(args[2], context, mapping) | |
338 | elif len(args) == 4: |
|
335 | elif len(args) == 4: | |
339 | yield _evalifliteral(args[3], context, mapping) |
|
336 | yield _evalifliteral(args[3], context, mapping) |
@@ -47,6 +47,9 b' Second branch starting at nullrev:' | |||||
47 | fourth (second) |
|
47 | fourth (second) | |
48 | $ hg log -T '{file_copies % "{source} -> {name}\n"}' -r . |
|
48 | $ hg log -T '{file_copies % "{source} -> {name}\n"}' -r . | |
49 | second -> fourth |
|
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 | Quoting for ui.logtemplate |
|
54 | Quoting for ui.logtemplate | |
52 |
|
55 | |||
@@ -2386,6 +2389,10 b' Test current bookmark templating' | |||||
2386 | 2 bar foo |
|
2389 | 2 bar foo | |
2387 | 1 baz |
|
2390 | 1 baz | |
2388 | 0 |
|
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 | Test stringify on sub expressions |
|
2397 | Test stringify on sub expressions | |
2391 |
|
2398 |
General Comments 0
You need to be logged in to leave comments.
Login now