comparison mercurial/config.py @ 19087:7d82ad4b3727 stable

config: discard "%unset" values defined in the other files read in previously Before this patch, "%unset" can't unset values defined in the other files read in previously, even though online help document says that it can. It can unset only values defined in the same configuration file. For example, the value defined in "~/.hgrc" can't be unset by "%unset" in ".hg/hgrc" of the repository. This patch records "%unset"-ed values in "config.parse()", and discards corresponding values in "config.update()".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 26 Apr 2013 23:36:12 +0900
parents 31f32a96e1e3
children d19c9bdbbf35
comparison
equal deleted inserted replaced
19086:8fb8dce3f9b6 19087:7d82ad4b3727
42 42
43 class config(object): 43 class config(object):
44 def __init__(self, data=None): 44 def __init__(self, data=None):
45 self._data = {} 45 self._data = {}
46 self._source = {} 46 self._source = {}
47 self._unset = []
47 if data: 48 if data:
48 for k in data._data: 49 for k in data._data:
49 self._data[k] = data[k].copy() 50 self._data[k] = data[k].copy()
50 self._source = data._source.copy() 51 self._source = data._source.copy()
51 def copy(self): 52 def copy(self):
56 return self._data.get(section, {}) 57 return self._data.get(section, {})
57 def __iter__(self): 58 def __iter__(self):
58 for d in self.sections(): 59 for d in self.sections():
59 yield d 60 yield d
60 def update(self, src): 61 def update(self, src):
62 for s, n in src._unset:
63 if s in self and n in self._data[s]:
64 del self._data[s][n]
65 del self._source[(s, n)]
61 for s in src: 66 for s in src:
62 if s not in self: 67 if s not in self:
63 self._data[s] = sortdict() 68 self._data[s] = sortdict()
64 self._data[s].update(src._data[s]) 69 self._data[s].update(src._data[s])
65 self._source.update(src._source) 70 self._source.update(src._source)
171 name = m.group(1) 176 name = m.group(1)
172 if sections and section not in sections: 177 if sections and section not in sections:
173 continue 178 continue
174 if self.get(section, name) is not None: 179 if self.get(section, name) is not None:
175 del self._data[section][name] 180 del self._data[section][name]
181 self._unset.append((section, name))
176 continue 182 continue
177 183
178 raise error.ParseError(l.rstrip(), ("%s:%s" % (src, line))) 184 raise error.ParseError(l.rstrip(), ("%s:%s" % (src, line)))
179 185
180 def read(self, path, fp=None, sections=None, remap=None): 186 def read(self, path, fp=None, sections=None, remap=None):