[PATCH 3 of 3] progress: move quiet/shouldprint logic into progress

Martin Geisler mrtn.gslr at gmail.com
Sat May 12 09:39:48 CDT 2012


# HG changeset patch
# User Martin Geisler <martin at geisler.net>
# Date 1336831413 -7200
# Node ID b4d8b4f81f9fbb54edca1fbd6d313912c38905ca
# Parent  626948279d984204b8289531ffe5c71ec37d5347
progress: move quiet/shouldprint logic into progress

Before, ui would guard calls to self._progbar.clear and
self._progbar.progress by self._progbar.printed. The progress bar now
manages this internally.

diff --git a/mercurial/progress.py b/mercurial/progress.py
--- a/mercurial/progress.py
+++ b/mercurial/progress.py
@@ -45,7 +45,9 @@
     return ' '.join(s for s in args if s)
 
 def shouldprint(ui):
-    return (not ui.configbool('progress', 'disabled')
+    return (not ui.debugflag
+            and not ui.quiet
+            and not ui.configbool('progress', 'disabled')
             and (util.isatty(sys.stderr)
                  or ui.configbool('progress', 'assume-tty')))
 
@@ -186,7 +188,7 @@
         sys.stderr.flush()
 
     def clear(self):
-        if not shouldprint(self.ui):
+        if not self.printed or not shouldprint(self.ui):
             return
         sys.stderr.write('\r%s\r' % (' ' * self.width()))
 
@@ -227,6 +229,9 @@
         return ''
 
     def progress(self, topic, pos, item='', unit='', total=None):
+        if self.ui.debugflag or self.ui.quiet:
+            return
+
         now = time.time()
         if pos is None:
             self.starttimes.pop(topic, None)
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -470,8 +470,7 @@
         "cmdname.type" is recommended. For example, status issues
         a label of "status.modified" for modified files.
         '''
-        if not self._quiet() and self._progbar.printed:
-            self._progbar.clear()
+        self._progbar.clear()
         if self._buffers:
             self._buffers[-1].extend([str(a) for a in args])
         else:
@@ -479,8 +478,7 @@
                 self.fout.write(str(a))
 
     def write_err(self, *args, **opts):
-        if not self._quiet() and self._progbar.printed:
-            self._progbar.clear()
+        self._progbar.clear()
         try:
             if not getattr(self.fout, 'closed', False):
                 self.fout.flush()
@@ -707,9 +705,6 @@
                 os.environ.get("VISUAL") or
                 os.environ.get("EDITOR", editor))
 
-    def _quiet(self):
-        return self.debugflag or self.quiet
-
     def progress(self, topic, pos, item="", unit="", total=None):
         '''show a progress message
 
@@ -726,8 +721,7 @@
         All topics should be marked closed by setting pos to None at
         termination.
         '''
-        if not self._quiet():
-            self._progbar.progress(topic, pos, item, unit, total)
+        self._progbar.progress(topic, pos, item, unit, total)
 
         if pos is None or not self.debugflag:
             return


More information about the Mercurial-devel mailing list