templatekw: change joinfmt to a mandatory argument of _hybrid object
We've fixed several bugs caused by the misuse of the default joinfmt. Make
it more explicit to prevent future bugs.
dict.values()[0] is replaced by dict[element] as showlist() knows what the
key is.
--- a/mercurial/templatekw.py Mon Jul 18 23:12:09 2016 +0900
+++ b/mercurial/templatekw.py Sat Jul 23 13:08:43 2016 +0900
@@ -26,14 +26,11 @@
# "{get(extras, key)}"
class _hybrid(object):
- def __init__(self, gen, values, makemap, joinfmt=None):
+ def __init__(self, gen, values, makemap, joinfmt):
self.gen = gen
self.values = values
self._makemap = makemap
- if joinfmt:
- self.joinfmt = joinfmt
- else:
- self.joinfmt = lambda x: x.values()[0]
+ self.joinfmt = joinfmt
def __iter__(self):
return self.gen
def itermaps(self):
@@ -53,7 +50,7 @@
if not element:
element = name
f = _showlist(name, values, plural, separator, **args)
- return _hybrid(f, values, lambda x: {element: x})
+ return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
def _showlist(name, values, plural=None, separator=' ', **args):
'''expand set of values.