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

Martin Geisler mrtn.gslr at gmail.com
Sat May 12 13:09:17 CDT 2012


# HG changeset patch
# User Martin Geisler <martin at geisler.net>
# Date 1336831413 -7200
# Node ID 9875610eedbc968e1caa3a3771dcd08448e976d1
# Parent  4eb2cda189ba9885ea786b3c6aa5ae998e8056fc
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
@@ -15,7 +15,9 @@
     return ' '.join(s for s in args if s)
 
 def shouldprint(ui):
-    return (not ui.configbool('progress', 'disable')
+    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')))
 
@@ -156,7 +158,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()))
 
@@ -197,6 +199,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
@@ -476,8 +476,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:
@@ -485,8 +484,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()
@@ -713,9 +711,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
 
@@ -732,8 +727,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