Mercurial > public > mercurial-scm > hg
diff mercurial/templatekw.py @ 24240:bd504d90588d
templater: implement _hybrid.__contains__ so that ifcontains can accept dict
d8fb835376d1 is fine for "{revset()}", but "i.values()[0]" does not work if
each item has more than one values such as "{bookmarks}".
This fixes the problem by using list.__contains__ or dict.__contains__
appropriately.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 18 Feb 2015 23:01:33 +0900 |
parents | 31f9b1b16d1e |
children | e7baf88c29c3 |
line wrap: on
line diff
--- a/mercurial/templatekw.py Sun Mar 08 14:46:42 2015 +0900 +++ b/mercurial/templatekw.py Wed Feb 18 23:01:33 2015 +0900 @@ -12,6 +12,8 @@ # This helper class allows us to handle both: # "{files}" (legacy command-line-specific list hack) and # "{files % '{file}\n'}" (hgweb-style with inlining and function support) +# and to access raw values: +# "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}" class _hybrid(object): def __init__(self, gen, values, makemap, joinfmt=None): @@ -28,6 +30,8 @@ makemap = self._makemap for x in self.values: yield makemap(x) + def __contains__(self, x): + return x in self.values def __len__(self): return len(self.values)