config: move config.sortdict class into util
This makes it more natural to use the sortdict class from outside config.py.
--- a/mercurial/config.py Mon Jun 23 09:33:07 2014 -0400
+++ b/mercurial/config.py Sun Feb 23 01:56:31 2014 +0100
@@ -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:
--- a/mercurial/util.py Mon Jun 23 09:33:07 2014 -0400
+++ b/mercurial/util.py Sun Feb 23 01:56:31 2014 +0100
@@ -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):