Patchwork [1,of,3,V2] config: move config.sortdict class into its own file

login
register
mail settings
Submitter Angel Ezquerra
Date March 17, 2014, 6:36 a.m.
Message ID <2080392f1e7380880935.1395038211@ubuntu>
Download mbox | patch
Permalink /patch/3953/
State Changes Requested
Headers show

Comments

Angel Ezquerra - March 17, 2014, 6:36 a.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1393116991 -3600
#      Sun Feb 23 01:56:31 2014 +0100
# Node ID 2080392f1e7380880935f646a7751d79f4ab6b7d
# Parent  e87bd3485a07f4b231febef26c6797855a64af3d
config: move config.sortdict class into its own file

This makes it more natural to use the sortdict class from outside config.py.
Matt Mackall - March 26, 2014, 8:01 p.m.
On Mon, 2014-03-17 at 07:36 +0100, Angel Ezquerra wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra@gmail.com>
> # Date 1393116991 -3600
> #      Sun Feb 23 01:56:31 2014 +0100
> # Node ID 2080392f1e7380880935f646a7751d79f4ab6b7d
> # Parent  e87bd3485a07f4b231febef26c6797855a64af3d
> config: move config.sortdict class into its own file

If you must, move this to util.

Patch

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -8,37 +8,7 @@ 
 from i18n import _
 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__()
+from sortdict import sortdict
 
 class config(object):
     def __init__(self, data=None):
diff --git a/mercurial/sortdict.py b/mercurial/sortdict.py
new file mode 100644
--- /dev/null
+++ b/mercurial/sortdict.py
@@ -0,0 +1,37 @@ 
+# sortdict.py - simple sorted dictionary for Mercurial
+#
+#  Copyright 2009 Matt Mackall <mpm@selenic.com> and others
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+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__()