diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -55,14 +55,29 @@ class ui(object): 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] diff --git a/tests/test-ui-verbosity b/tests/test-ui-verbosity new file mode 100755 --- /dev/null +++ b/tests/test-ui-verbosity @@ -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)) diff --git a/tests/test-ui-verbosity.out b/tests/test-ui-verbosity.out new file mode 100644 --- /dev/null +++ b/tests/test-ui-verbosity.out @@ -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