config: make sortdict keys() and iterkeys() methods respect the item order
authorAngel Ezquerra <angel.ezquerra@gmail.com>
Tue, 29 May 2012 23:26:55 +0200
changeset 16865 a6543fdcf869
parent 16864 92cfde8728ac
child 16866 91f3ac205816
config: make sortdict keys() and iterkeys() methods respect the item order The config.sortdict class is a simple "sorted dictionary" container class, based on python's regular dict container. The main difference compared to regular dicts is that sortdicts remember the order in which items have been added to it. Without this patch the items() method returns the sortdict elements in the right order. However, getting the list of keys by using the keys() or iterkeys() methods, and consequencly, looping through the container elements in a for loop does not respect that order. This patch fixes this problem.
mercurial/config.py
--- a/mercurial/config.py	Mon Jun 04 16:59:57 2012 -0500
+++ b/mercurial/config.py	Tue May 29 23:26:55 2012 +0200
@@ -35,6 +35,10 @@
     def __delitem__(self, key):
         dict.__delitem__(self, key)
         self._list.remove(key)
+    def keys(self):
+        return self._list
+    def iterkeys(self):
+        return self._list.__iter__()
 
 class config(object):
     def __init__(self, data=None):