config: add section filter to read
authorMatt Mackall <mpm@selenic.com>
Sun, 26 Apr 2009 16:50:43 -0500
changeset 8193 94246e90081e
parent 8192 5fd8e60a935d
child 8194 63c47e4ac617
config: add section filter to read move section filtering out of ui.readconfig kill section filtering in config.update
mercurial/config.py
mercurial/ui.py
--- a/mercurial/config.py	Sun Apr 26 16:50:43 2009 -0500
+++ b/mercurial/config.py	Sun Apr 26 16:50:43 2009 -0500
@@ -42,17 +42,12 @@
     def __iter__(self):
         for d in self.sections():
             yield d
-    def update(self, src, sections=None):
-        if not sections:
-            sections = src.sections()
-        for s in sections:
-            if s not in src:
-                continue
+    def update(self, src):
+        for s in src:
             if s not in self:
                 self._data[s] = sortdict()
-            for k in src._data[s]:
-                self._data[s][k] = src._data[s][k]
-                self._source[(s, k)] = src._source[(s, k)]
+            self._data[s].update(src._data[s])
+        self._source.update(src._source)
     def get(self, section, item, default=None):
         return self._data.get(section, {}).get(item, default)
     def getsource(self, section, item):
@@ -67,7 +62,7 @@
         self._data[section][item] = value
         self._source[(section, item)] = source
 
-    def read(self, path, fp=None):
+    def read(self, path, fp=None, sections=None):
         sectionre = re.compile(r'\[([^\[]+)\]')
         itemre = re.compile(r'([^=\s]+)\s*=\s*(.*\S|)')
         contre = re.compile(r'\s+(\S.*\S)')
@@ -87,6 +82,8 @@
             if cont:
                 m = contre.match(l)
                 if m:
+                    if sections and section not in sections:
+                        continue
                     v = self.get(section, item) + "\n" + m.group(1)
                     self.set(section, item, v, "%s:%d" % (path, line))
                     continue
@@ -110,12 +107,16 @@
             m = itemre.match(l)
             if m:
                 item = m.group(1)
+                cont = 1
+                if sections and section not in sections:
+                    continue
                 self.set(section, item, m.group(2), "%s:%d" % (path, line))
-                cont = 1
                 continue
             m = unsetre.match(l)
             if m:
                 name = m.group(1)
+                if sections and section not in sections:
+                    continue
                 if self.get(section, name) != None:
                     del self._data[section][name]
                 continue
--- a/mercurial/ui.py	Sun Apr 26 16:50:43 2009 -0500
+++ b/mercurial/ui.py	Sun Apr 26 16:50:43 2009 -0500
@@ -82,17 +82,17 @@
         trusted = sections or assumetrusted or self._is_trusted(fp, filename)
 
         try:
-            cdata.read(filename, fp)
+            cdata.read(filename, fp, sections=sections)
         except error.ConfigError, inst:
             if trusted:
                 raise
             self.warn(_("Ignored: %s\n") % str(inst))
 
         if trusted:
-            self.cdata.update(cdata, sections)
-            self.cdata.update(self.overlay, sections)
-        self.ucdata.update(cdata, sections)
-        self.ucdata.update(self.overlay, sections)
+            self.cdata.update(cdata)
+            self.cdata.update(self.overlay)
+        self.ucdata.update(cdata)
+        self.ucdata.update(self.overlay)
 
         if root is None:
             root = os.path.expanduser('~')