templater: byte-stringify dict/list values before passing to default format
bytestr() is applied only when no custom format string like '%d' is specified.
--- a/mercurial/formatter.py Thu Mar 01 08:07:22 2018 -0500
+++ b/mercurial/formatter.py Thu Mar 01 08:14:54 2018 -0500
@@ -248,15 +248,20 @@
@staticmethod
def formatdict(data, key, value, fmt, sep):
'''stringify key-value pairs separated by sep'''
+ prefmt = pycompat.identity
if fmt is None:
fmt = '%s=%s'
- return sep.join(fmt % (k, v) for k, v in _iteritems(data))
+ prefmt = pycompat.bytestr
+ return sep.join(fmt % (prefmt(k), prefmt(v))
+ for k, v in _iteritems(data))
@staticmethod
def formatlist(data, name, fmt, sep):
'''stringify iterable separated by sep'''
+ prefmt = pycompat.identity
if fmt is None:
fmt = '%s'
- return sep.join(fmt % e for e in data)
+ prefmt = pycompat.bytestr
+ return sep.join(fmt % prefmt(e) for e in data)
class plainformatter(baseformatter):
'''the default text output scheme'''
--- a/mercurial/templatekw.py Thu Mar 01 08:07:22 2018 -0500
+++ b/mercurial/templatekw.py Thu Mar 01 08:14:54 2018 -0500
@@ -99,16 +99,20 @@
def hybriddict(data, key='key', value='value', fmt=None, gen=None):
"""Wrap data to support both dict-like and string-like operations"""
+ prefmt = pycompat.identity
if fmt is None:
fmt = '%s=%s'
+ prefmt = pycompat.bytestr
return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
- lambda k: fmt % (k, data[k]))
+ lambda k: fmt % (prefmt(k), prefmt(data[k])))
def hybridlist(data, name, fmt=None, gen=None):
"""Wrap data to support both list-like and string-like operations"""
+ prefmt = pycompat.identity
if fmt is None:
fmt = '%s'
- return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x)
+ prefmt = pycompat.bytestr
+ return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % prefmt(x))
def unwraphybrid(thing):
"""Return an object which can be stringified possibly by using a legacy