Mercurial > hg
diff mercurial/templatekw.py @ 18970:3cdb6f2f6789
templatekw: add default styles for hybrid types (issue3887)
This allows elements like file_copies to be printed as 'name (source)'
when used with join.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 16 Apr 2013 09:44:29 -0500 |
parents | c4ff927b6f68 |
children | ad27cdacc743 faa4b3fc4197 |
line wrap: on
line diff
--- a/mercurial/templatekw.py Wed Apr 10 02:27:35 2013 +0900 +++ b/mercurial/templatekw.py Tue Apr 16 09:44:29 2013 -0500 @@ -14,9 +14,13 @@ # "{files % '{file}\n'}" (hgweb-style with inlining and function support) class _hybrid(object): - def __init__(self, gen, values): + def __init__(self, gen, values, joinfmt=None): self.gen = gen self.values = values + if joinfmt: + self.joinfmt = joinfmt + else: + self.joinfmt = lambda x: x.values()[0] def __iter__(self): return self.gen def __call__(self): @@ -245,7 +249,7 @@ c = [{'name': x[0], 'source': x[1]} for x in copies] f = _showlist('file_copy', c, plural='file_copies', **args) - return _hybrid(f, c) + return _hybrid(f, c, lambda x: '%s (%s)' % (x['name'], x['source'])) # showfilecopiesswitch() displays file copies only if copy records are # provided before calling the templater, usually with a --copies @@ -257,7 +261,7 @@ copies = args['revcache'].get('copies') or [] c = [{'name': x[0], 'source': x[1]} for x in copies] f = _showlist('file_copy', c, plural='file_copies', **args) - return _hybrid(f, c) + return _hybrid(f, c, lambda x: '%s (%s)' % (x['name'], x['source'])) def showfiledels(**args): """:file_dels: List of strings. Files removed by this changeset."""