Patchwork [1,of,4,V3] config: move config.sortdict class into util

login
register
mail settings
Submitter Angel Ezquerra
Date June 25, 2014, 11:22 p.m.
Message ID <e500ce49a9a30c6fdd61.1403738527@ubuntu>
Download mbox | patch
Permalink /patch/5065/
State Accepted
Commit c2262004c2e229f176468b2de649315254087f2f
Headers show

Comments

Angel Ezquerra - June 25, 2014, 11:22 p.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1393116991 -3600
#      Sun Feb 23 01:56:31 2014 +0100
# Node ID e500ce49a9a30c6fdd6179f46559690e03da65d1
# Parent  becb61de90a1a0384af535a393fb32e7da7a9059
config: move config.sortdict class into util

This makes it more natural to use the sortdict class from outside config.py.

Patch

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -9,37 +9,6 @@ 
 import error, util
 import os, errno
 
-class sortdict(dict):
-    'a simple sorted dictionary'
-    def __init__(self, data=None):
-        self._list = []
-        if data:
-            self.update(data)
-    def copy(self):
-        return sortdict(self)
-    def __setitem__(self, key, val):
-        if key in self:
-            self._list.remove(key)
-        self._list.append(key)
-        dict.__setitem__(self, key, val)
-    def __iter__(self):
-        return self._list.__iter__()
-    def update(self, src):
-        for k in src:
-            self[k] = src[k]
-    def clear(self):
-        dict.clear(self)
-        self._list = []
-    def items(self):
-        return [(k, self[k]) for k in self._list]
-    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):
         self._data = {}
@@ -65,7 +34,7 @@ 
                 del self._source[(s, n)]
         for s in src:
             if s not in self:
-                self._data[s] = sortdict()
+                self._data[s] = util.sortdict()
             self._data[s].update(src._data[s])
         self._source.update(src._source)
     def get(self, section, item, default=None):
@@ -91,7 +60,7 @@ 
         return self._data.get(section, {}).items()
     def set(self, section, item, value, source=""):
         if section not in self:
-            self._data[section] = sortdict()
+            self._data[section] = util.sortdict()
         self._data[section][item] = value
         if source:
             self._source[(section, item)] = source
@@ -162,7 +131,7 @@ 
                 if remap:
                     section = remap.get(section, section)
                 if section not in self:
-                    self._data[section] = sortdict()
+                    self._data[section] = util.sortdict()
                 continue
             m = itemre.match(l)
             if m:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -223,6 +223,37 @@ 
                     del self[i]
                     break
 
+class sortdict(dict):
+    '''a simple sorted dictionary'''
+    def __init__(self, data=None):
+        self._list = []
+        if data:
+            self.update(data)
+    def copy(self):
+        return sortdict(self)
+    def __setitem__(self, key, val):
+        if key in self:
+            self._list.remove(key)
+        self._list.append(key)
+        dict.__setitem__(self, key, val)
+    def __iter__(self):
+        return self._list.__iter__()
+    def update(self, src):
+        for k in src:
+            self[k] = src[k]
+    def clear(self):
+        dict.clear(self)
+        self._list = []
+    def items(self):
+        return [(k, self[k]) for k in self._list]
+    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 lrucachedict(object):
     '''cache most recent gets from or sets to this dictionary'''
     def __init__(self, maxsize):