changeset 3350:ab900698b832

update ui.quiet/verbose/debug/interactive every time the config changes - ui.quiet/verbose/debug/interactive become just a cache of the ui.cdata settings - the quiet, verbose, debug and interactive options from the [ui] section from .hg/hgrc files are respected for commands that open the repo - setting ui.quiet/verbose/debug/interactive with --config works - the command line options always override the hgrc settings - previously it wasn't possible to override a [ui] debug = True. --debug still takes precedence over --quiet and --verbose.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 10 Oct 2006 18:43:20 -0300
parents 25d270e0b27f
children 04fa31a43b93
files mercurial/ui.py tests/test-ui-verbosity.out
diffstat 2 files changed, 44 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Tue Oct 10 18:43:20 2006 -0300
+++ b/mercurial/ui.py	Tue Oct 10 18:43:20 2006 -0300
@@ -32,15 +32,13 @@
             # this is the parent of all ui children
             self.parentui = None
             self.readhooks = []
+            self.quiet = quiet
+            self.verbose = verbose
+            self.debugflag = debug
+            self.interactive = interactive
+            self.traceback = traceback
             self.cdata = ConfigParser.SafeConfigParser()
             self.readconfig(util.rcpath())
-
-            self.quiet = self.configbool("ui", "quiet")
-            self.verbose = self.configbool("ui", "verbose")
-            self.debugflag = self.configbool("ui", "debug")
-            self.interactive = self.configbool("ui", "interactive", True)
-            self.traceback = traceback
-
             self.updateopts(verbose, debug, quiet, interactive)
         else:
             # parentui may point to an ui object which is already a child
@@ -55,28 +53,32 @@
 
     def updateopts(self, verbose=False, debug=False, quiet=False,
                    interactive=True, traceback=False, config=[]):
-        self.quiet = self.quiet or quiet
-        self.verbose = self.verbose or verbose
-        self.debugflag = self.debugflag or debug
-
-        self.verbosity_constraints(quiet, verbose, debug)
-
-        self.interactive = (self.interactive and interactive)
-        self.traceback = self.traceback or traceback
         for section, name, value in config:
             self.setconfig(section, name, value)
 
-    def verbosity_constraints(self, quiet, verbose, debug):
+        if quiet or verbose or debug:
+            self.setconfig('ui', 'quiet', str(bool(quiet)))
+            self.setconfig('ui', 'verbose', str(bool(verbose)))
+            self.setconfig('ui', 'debug', str(bool(debug)))
+
+        self.verbosity_constraints()
+
+        if not interactive:
+            self.setconfig('ui', 'interactive', 'False')
+            self.interactive = False
+
+        self.traceback = self.traceback or traceback
+
+    def verbosity_constraints(self):
+        self.quiet = self.configbool('ui', 'quiet')
+        self.verbose = self.configbool('ui', 'verbose')
+        self.debugflag = self.configbool('ui', 'debug')
+
         if self.debugflag:
             self.verbose = True
             self.quiet = False
         elif self.verbose and self.quiet:
-            if quiet and not verbose:
-                self.verbose = False
-            elif not quiet and verbose:
-                self.quiet = False
-            else:
-                self.quiet = self.verbose = False
+            self.quiet = self.verbose = False
 
     def readconfig(self, fn, root=None):
         if isinstance(fn, basestring):
@@ -114,6 +116,14 @@
                     if path and "://" not in path and not os.path.isabs(path):
                         cdata.set("paths", n, os.path.join(root, path))
 
+        # update quiet/verbose/debug and interactive status
+        if section is None or section == 'ui':
+            if name is None or name in ('quiet', 'verbose', 'debug'):
+                self.verbosity_constraints()
+
+            if name is None or name == 'interactive':
+                self.interactive = self.configbool("ui", "interactive", True)
+
     def setconfig(self, section, name, value):
         if not self.overlay:
             self.overlay = ConfigParser.SafeConfigParser()
--- a/tests/test-ui-verbosity.out	Tue Oct 10 18:43:20 2006 -0300
+++ b/tests/test-ui-verbosity.out	Tue Oct 10 18:43:20 2006 -0300
@@ -12,26 +12,26 @@
  9   True False False    True False False  ->   True False False
 10  False  True False    True False False  ->   True False False
 11   True  True False    True False False  ->   True False False
-12  False False  True    True False False  ->  False  True  True
-13   True False  True    True False False  ->  False  True  True
-14  False  True  True    True False False  ->  False  True  True
-15   True  True  True    True False False  ->  False  True  True
+12  False False  True    True False False  ->   True False False
+13   True False  True    True False False  ->   True False False
+14  False  True  True    True False False  ->   True False False
+15   True  True  True    True False False  ->   True False False
 16  False False False   False  True False  ->  False  True False
 17   True False False   False  True False  ->  False  True False
 18  False  True False   False  True False  ->  False  True False
 19   True  True False   False  True False  ->  False  True False
-20  False False  True   False  True False  ->  False  True  True
-21   True False  True   False  True False  ->  False  True  True
-22  False  True  True   False  True False  ->  False  True  True
-23   True  True  True   False  True False  ->  False  True  True
+20  False False  True   False  True False  ->  False  True False
+21   True False  True   False  True False  ->  False  True False
+22  False  True  True   False  True False  ->  False  True False
+23   True  True  True   False  True False  ->  False  True False
 24  False False False    True  True False  ->  False False False
 25   True False False    True  True False  ->  False False False
 26  False  True False    True  True False  ->  False False False
 27   True  True False    True  True False  ->  False False False
-28  False False  True    True  True False  ->  False  True  True
-29   True False  True    True  True False  ->  False  True  True
-30  False  True  True    True  True False  ->  False  True  True
-31   True  True  True    True  True False  ->  False  True  True
+28  False False  True    True  True False  ->  False False False
+29   True False  True    True  True False  ->  False False False
+30  False  True  True    True  True False  ->  False False False
+31   True  True  True    True  True False  ->  False False False
 32  False False False   False False  True  ->  False  True  True
 33   True False False   False False  True  ->  False  True  True
 34  False  True False   False False  True  ->  False  True  True