ui.py: normalize settings every time the configuration changes
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 10 Oct 2006 18:43:20 -0300
changeset 3347 bce7c1b4c1c8
parent 3346 1700a103458e
child 3348 e4aa22eaa0e4
ui.py: normalize settings every time the configuration changes Previously, we would normalize settings (e.g. turn relative paths into absolute ones) only after reading a config file. Now "--config paths.foo=bar" will use the cwd to make "bar" an absolute path.
mercurial/ui.py
--- a/mercurial/ui.py	Tue Oct 10 18:43:20 2006 -0300
+++ b/mercurial/ui.py	Tue Oct 10 18:43:20 2006 -0300
@@ -71,21 +71,34 @@
                 self.cdata.read(f)
             except ConfigParser.ParsingError, inst:
                 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
-        # translate paths relative to root (or home) into absolute paths
-        if root is None:
-            root = os.path.expanduser('~')
-        for name, path in self.configitems("paths"):
-            if path and "://" not in path and not os.path.isabs(path):
-                self.cdata.set("paths", name, os.path.join(root, path))
         # override data from config files with data set with ui.setconfig
         if self.overlay:
             updateconfig(self.overlay, self.cdata)
+        if root is None:
+            root = os.path.expanduser('~')
+        self.fixconfig(root=root)
         for hook in self.readhooks:
             hook(self)
 
     def addreadhook(self, hook):
         self.readhooks.append(hook)
 
+    def fixconfig(self, section=None, name=None, value=None, root=None):
+        # translate paths relative to root (or home) into absolute paths
+        if section is None or section == 'paths':
+            if root is None:
+                root = os.getcwd()
+            items = section and [(name, value)] or []
+            for cdata in self.cdata, self.overlay:
+                if not cdata: continue
+                if not items and cdata.has_section('paths'):
+                    pathsitems = cdata.items('paths')
+                else:
+                    pathsitems = items
+                for n, path in pathsitems:
+                    if path and "://" not in path and not os.path.isabs(path):
+                        cdata.set("paths", n, os.path.join(root, path))
+
     def setconfig(self, section, name, value):
         if not self.overlay:
             self.overlay = ConfigParser.SafeConfigParser()
@@ -93,6 +106,7 @@
             if not cdata.has_section(section):
                 cdata.add_section(section)
             cdata.set(section, name, value)
+        self.fixconfig(section, name, value)
 
     def _config(self, section, name, default, funcname):
         if self.cdata.has_option(section, name):