changeset 3349:25d270e0b27f

ui.py: untangle updateopts The code in ui.updateopts that handles ui.quiet, ui.verbose and ui.debugflag is too smart, making it somewhat hard to see what are the exact constraints placed on the values of these variables, hiding some buglets. This patch makes these constraints more explicit, fixing these buglets and changing the behaviour slightly. It also adds a test to make sure things work as expected in the future. The buglets: - setting ui.debug = True in a hgrc wouldn't turn on verbose mode - additionally, setting ui.quiet = True or using --quiet would give you a "quiet debug" mode. The behaviour change: - previously, in a hgrc file, ui.quiet wins against ui.verbose (i.e. the final result would be quiet mode), but --verbose wins against --quiet - now ui.quiet nullifies ui.verbose and --verbose nullifies --quiet. As a consequence, using -qv always gives you normal mode (unless debug mode was turned on somewhere)
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 10 Oct 2006 18:43:20 -0300
parents e4aa22eaa0e4
children ab900698b832
files mercurial/ui.py tests/test-ui-verbosity tests/test-ui-verbosity.out
diffstat 3 files changed, 126 insertions(+), 3 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
@@ -55,14 +55,29 @@
 
     def updateopts(self, verbose=False, debug=False, quiet=False,
                    interactive=True, traceback=False, config=[]):
-        self.quiet = (self.quiet or quiet) and not verbose and not debug
-        self.verbose = ((self.verbose or verbose) or debug) and not self.quiet
-        self.debugflag = (self.debugflag or debug)
+        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 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
+
     def readconfig(self, fn, root=None):
         if isinstance(fn, basestring):
             fn = [fn]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-ui-verbosity	Tue Oct 10 18:43:20 2006 -0300
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import os
+from mercurial import ui
+
+hgrc = os.environ['HGRCPATH']
+
+print '      hgrc settings    command line options      final result   '
+print '    quiet verbo debug   quiet verbo debug      quiet verbo debug'
+
+for i in xrange(64):
+    hgrc_quiet   = bool(i & 1<<0)
+    hgrc_verbose = bool(i & 1<<1)
+    hgrc_debug   = bool(i & 1<<2)
+    cmd_quiet    = bool(i & 1<<3)
+    cmd_verbose  = bool(i & 1<<4)
+    cmd_debug    = bool(i & 1<<5)
+
+    f = open(hgrc, 'w')
+    f.write('[ui]\n')
+    if hgrc_quiet:
+        f.write('quiet = True\n')
+    if hgrc_verbose:
+        f.write('verbose = True\n')
+    if hgrc_debug:
+        f.write('debug = True\n')
+    f.close()
+
+    u = ui.ui()
+    u.updateopts(quiet=cmd_quiet, verbose=cmd_verbose, debug=cmd_debug)
+
+    check = ''
+    if u.debugflag:
+        if not u.verbose or u.quiet:
+            check = ' *'
+    elif u.verbose and u.quiet:
+        check = ' +'
+
+    print ('%2d  %5s %5s %5s   %5s %5s %5s  ->  %5s %5s %5s%s'
+           % (i, hgrc_quiet, hgrc_verbose, hgrc_debug,
+              cmd_quiet, cmd_verbose, cmd_debug,
+              u.quiet, u.verbose, u.debugflag, check))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-ui-verbosity.out	Tue Oct 10 18:43:20 2006 -0300
@@ -0,0 +1,66 @@
+      hgrc settings    command line options      final result   
+    quiet verbo debug   quiet verbo debug      quiet verbo debug
+ 0  False False False   False False False  ->  False False False
+ 1   True False False   False False False  ->   True False False
+ 2  False  True False   False False False  ->  False  True False
+ 3   True  True False   False False False  ->  False False False
+ 4  False False  True   False False False  ->  False  True  True
+ 5   True False  True   False False False  ->  False  True  True
+ 6  False  True  True   False False False  ->  False  True  True
+ 7   True  True  True   False False False  ->  False  True  True
+ 8  False False False    True False False  ->   True False False
+ 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
+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
+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
+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
+35   True  True False   False False  True  ->  False  True  True
+36  False False  True   False False  True  ->  False  True  True
+37   True False  True   False False  True  ->  False  True  True
+38  False  True  True   False False  True  ->  False  True  True
+39   True  True  True   False False  True  ->  False  True  True
+40  False False False    True False  True  ->  False  True  True
+41   True False False    True False  True  ->  False  True  True
+42  False  True False    True False  True  ->  False  True  True
+43   True  True False    True False  True  ->  False  True  True
+44  False False  True    True False  True  ->  False  True  True
+45   True False  True    True False  True  ->  False  True  True
+46  False  True  True    True False  True  ->  False  True  True
+47   True  True  True    True False  True  ->  False  True  True
+48  False False False   False  True  True  ->  False  True  True
+49   True False False   False  True  True  ->  False  True  True
+50  False  True False   False  True  True  ->  False  True  True
+51   True  True False   False  True  True  ->  False  True  True
+52  False False  True   False  True  True  ->  False  True  True
+53   True False  True   False  True  True  ->  False  True  True
+54  False  True  True   False  True  True  ->  False  True  True
+55   True  True  True   False  True  True  ->  False  True  True
+56  False False False    True  True  True  ->  False  True  True
+57   True False False    True  True  True  ->  False  True  True
+58  False  True False    True  True  True  ->  False  True  True
+59   True  True False    True  True  True  ->  False  True  True
+60  False False  True    True  True  True  ->  False  True  True
+61   True False  True    True  True  True  ->  False  True  True
+62  False  True  True    True  True  True  ->  False  True  True
+63   True  True  True    True  True  True  ->  False  True  True