[PATCH] ui: only fix config if the relevant section has changed

Nicolas Dumazet nicdumz at gmail.com
Mon Oct 18 00:42:02 CDT 2010


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1287378636 -32400
# Node ID 100d5ba4d46d8464daa8ebaf5a8101b187256c26
# Parent  175fb1b193f494683801c3156a338da477b82bb0
ui: only fix config if the relevant section has changed

In particular, when extensions add hooks, or add non-ui and non-paths
configuration items during their setups, we really have no reason
to re-"fix" the config dictionaries.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -97,42 +97,46 @@
             root = os.path.expanduser('~')
         self.fixconfig(root=root)
 
-    def fixconfig(self, root=None):
-        # expand vars and ~
-        # translate paths relative to root (or home) into absolute paths
-        root = root or os.getcwd()
-        for c in self._tcfg, self._ucfg, self._ocfg:
-            for n, p in c.items('paths'):
-                if not p:
-                    continue
-                if '%%' in p:
-                    self.warn(_("(deprecated '%%' in path %s=%s from %s)\n")
-                              % (n, p, self.configsource('paths', n)))
-                    p = p.replace('%%', '%')
-                p = util.expandpath(p)
-                if '://' not in p and not os.path.isabs(p):
-                    p = os.path.normpath(os.path.join(root, p))
-                c.set("paths", n, p)
+    def fixconfig(self, root=None, section=None):
+        if section in (None, 'paths'):
+            # expand vars and ~
+            # translate paths relative to root (or home) into absolute paths
+            root = root or os.getcwd()
+            for c in self._tcfg, self._ucfg, self._ocfg:
+                for n, p in c.items('paths'):
+                    if not p:
+                        continue
+                    if '%%' in p:
+                        self.warn(_("(deprecated '%%' in path %s=%s from %s)\n")
+                                  % (n, p, self.configsource('paths', n)))
+                        p = p.replace('%%', '%')
+                    p = util.expandpath(p)
+                    if '://' not in p and not os.path.isabs(p):
+                        p = os.path.normpath(os.path.join(root, p))
+                    c.set("paths", n, p)
 
-        # update ui options
-        self.debugflag = self.configbool('ui', 'debug')
-        self.verbose = self.debugflag or self.configbool('ui', 'verbose')
-        self.quiet = not self.debugflag and self.configbool('ui', 'quiet')
-        if self.verbose and self.quiet:
-            self.quiet = self.verbose = False
-        self._reportuntrusted = self.configbool("ui", "report_untrusted", True)
-        self.tracebackflag = self.configbool('ui', 'traceback', False)
+        if section in (None, 'ui'):
+            # update ui options
+            self.debugflag = self.configbool('ui', 'debug')
+            self.verbose = self.debugflag or self.configbool('ui', 'verbose')
+            self.quiet = not self.debugflag and self.configbool('ui', 'quiet')
+            if self.verbose and self.quiet:
+                self.quiet = self.verbose = False
+            self._reportuntrusted = self.configbool("ui", "report_untrusted",
+                                        True)
+            self.tracebackflag = self.configbool('ui', 'traceback', False)
 
-        # update trust information
-        self._trustusers.update(self.configlist('trusted', 'users'))
-        self._trustgroups.update(self.configlist('trusted', 'groups'))
+        if section in (None, 'trusted'):
+            # update trust information
+            self._trustusers.update(self.configlist('trusted', 'users'))
+            self._trustgroups.update(self.configlist('trusted', 'groups'))
 
     def setconfig(self, section, name, value, overlay=True):
         if overlay:
             self._ocfg.set(section, name, value)
         self._tcfg.set(section, name, value)
         self._ucfg.set(section, name, value)
-        self.fixconfig()
+        self.fixconfig(section=section)
 
     def _data(self, untrusted):
         return untrusted and self._ucfg or self._tcfg


More information about the Mercurial-devel mailing list