mercurial/config.py
changeset 8184 9189afe1eba3
parent 8183 2858ab754995
child 8185 dc10a7a3f1d4
equal deleted inserted replaced
8183:2858ab754995 8184:9189afe1eba3
     1 from i18n import _
     1 from i18n import _
     2 import re, error, os
     2 import re, error, os
     3 
     3 
     4 class sortdict(dict):
     4 class sortdict(dict):
     5     'a simple append-only sorted dictionary'
     5     'a simple sorted dictionary'
     6     def __init__(self, data=None):
     6     def __init__(self, data=None):
     7         self._list = []
     7         self._list = []
     8         if data:
     8         if data:
     9             if hasattr(data, '_list'):
     9             if hasattr(data, '_list'):
    10                 self._list = list(data._list)
    10                 self._list = list(data._list)
    21     def update(self, src):
    21     def update(self, src):
    22         for k in src:
    22         for k in src:
    23             self[k] = src[k]
    23             self[k] = src[k]
    24     def items(self):
    24     def items(self):
    25         return [(k,self[k]) for k in self._list]
    25         return [(k,self[k]) for k in self._list]
       
    26     def __delitem__(self, key):
       
    27         dict.__delitem__(self, key)
       
    28         self._list.remove(key)
    26 
    29 
    27 class config:
    30 class config:
    28     def __init__(self, data=None):
    31     def __init__(self, data=None):
    29         self._data = {}
    32         self._data = {}
    30         if data:
    33         if data:
    60     def read(self, path, fp=None):
    63     def read(self, path, fp=None):
    61         sectionre = re.compile(r'\[([^\[]+)\]')
    64         sectionre = re.compile(r'\[([^\[]+)\]')
    62         itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
    65         itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
    63         contre = re.compile(r'\s+(\S.*)')
    66         contre = re.compile(r'\s+(\S.*)')
    64         emptyre = re.compile(r'(;|#|\s*$)')
    67         emptyre = re.compile(r'(;|#|\s*$)')
       
    68         unsetre = re.compile(r'%unset\s+(\S.*)')
    65         includere = re.compile(r'%include\s+(\S.*)')
    69         includere = re.compile(r'%include\s+(\S.*)')
    66         section = ""
    70         section = ""
    67         item = None
    71         item = None
    68         line = 0
    72         line = 0
    69         cont = 0
    73         cont = 0
   100             if m:
   104             if m:
   101                 item = m.group(1)
   105                 item = m.group(1)
   102                 self.set(section, item, m.group(2), "%s:%d" % (path, line))
   106                 self.set(section, item, m.group(2), "%s:%d" % (path, line))
   103                 cont = 1
   107                 cont = 1
   104                 continue
   108                 continue
       
   109             m = unsetre.match(l)
       
   110             if m:
       
   111                 name = m.group(1)
       
   112                 if self.get(section, name) != None:
       
   113                     del self._data[section][name]
       
   114                 continue
       
   115 
   105             raise error.ConfigError(_('config error at %s:%d: \'%s\'')
   116             raise error.ConfigError(_('config error at %s:%d: \'%s\'')
   106                                     % (path, line, l.rstrip()))
   117                                     % (path, line, l.rstrip()))