Patchwork [1,of,3] template: modify showextras to return a hybrid

login
register
mail settings
Submitter Matthew Turk
Date Nov. 21, 2013, 9:04 p.m.
Message ID <e4c89fff1cc57f532d43.1385067863@ridcully>
Download mbox | patch
Permalink /patch/3074/
State Accepted
Commit de7e6c489412c6a1caec93ec23e37b8bab7e2a2f
Headers show

Comments

Matthew Turk - Nov. 21, 2013, 9:04 p.m.
# HG changeset patch
# User Matthew Turk <matthewturk@gmail.com>
# Date 1385066809 18000
#      Thu Nov 21 15:46:49 2013 -0500
# Node ID e4c89fff1cc57f532d43d0015445ab44a739f6d7
# Parent  f8737bce736a6e8171ec955734aa6a19b8def074
template: modify showextras to return a hybrid.

This modifies slightly the behavior introduced in 519120a96c63 to allow
showextras to return a hybrid, rather than showlist.  The example in the
template help file now executes and returns meaningful results.

Patch

diff -r f8737bce736a -r e4c89fff1cc5 mercurial/templatekw.py
--- a/mercurial/templatekw.py	Mon Nov 11 16:35:12 2013 -0800
+++ b/mercurial/templatekw.py	Thu Nov 21 15:46:49 2013 -0500
@@ -221,8 +221,10 @@ 
 def showextras(**args):
     """:extras: List of dicts with key, value entries of the 'extras'
     field of this changeset."""
-    yield showlist('extra', sorted(dict(key=a, value=b)
-                   for (a, b) in args['ctx'].extra().items()), **args)
+    extras = args['ctx'].extra()
+    c = [{'key': x[0], 'value': x[1]} for x in sorted(extras.items())]
+    f = _showlist('extra', c, plural='extras', **args)
+    return _hybrid(f, c, lambda x: '%s=%s' % (x['key'], x['value']))
 
 def showfileadds(**args):
     """:file_adds: List of strings. Files added by this changeset."""