Patchwork [2,of,6] templatekw: convert list of key/value pairs to sortdict

login
register
mail settings
Submitter Yuya Nishihara
Date March 8, 2015, 11:56 a.m.
Message ID <d15979ee87019b834380.1425815764@mimosa>
Download mbox | patch
Permalink /patch/7933/
State Accepted
Headers show

Comments

Yuya Nishihara - March 8, 2015, 11:56 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1425791855 -32400
#      Sun Mar 08 14:17:35 2015 +0900
# Node ID d15979ee87019b8343801b0674f76080d2362123
# Parent  023d0f46318665e8d01fe42fb58ac1726532b4c0
templatekw: convert list of key/value pairs to sortdict

These sortdict objects will be passed to _hybrid later, which will allow
us to handle them by "ifcontains()" and "get()" as expected.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -241,7 +241,8 @@  def showextras(**args):
     """:extras: List of dicts with key, value entries of the 'extras'
     field of this changeset."""
     extras = args['ctx'].extra()
-    c = [{'key': x[0], 'value': x[1]} for x in sorted(extras.items())]
+    extras = util.sortdict((k, extras[k]) for k in sorted(extras))
+    c = [{'key': k, 'value': extras[k]} for k in extras]
     f = _showlist('extra', c, plural='extras', **args)
     return _hybrid(f, c, lambda x: '%s=%s' % (x['key'], x['value']))
 
@@ -267,7 +268,8 @@  def showfilecopies(**args):
             if rename:
                 copies.append((fn, rename[0]))
 
-    c = [{'name': x[0], 'source': x[1]} for x in copies]
+    copies = util.sortdict(copies)
+    c = [{'name': k, 'source': copies[k]} for k in copies]
     f = _showlist('file_copy', c, plural='file_copies', **args)
     return _hybrid(f, c, lambda x: '%s (%s)' % (x['name'], x['source']))
 
@@ -279,7 +281,8 @@  def showfilecopiesswitch(**args):
     only if the --copied switch is set.
     """
     copies = args['revcache'].get('copies') or []
-    c = [{'name': x[0], 'source': x[1]} for x in copies]
+    copies = util.sortdict(copies)
+    c = [{'name': k, 'source': copies[k]} for k in copies]
     f = _showlist('file_copy', c, plural='file_copies', **args)
     return _hybrid(f, c, lambda x: '%s (%s)' % (x['name'], x['source']))