changeset 10439:509f4ed56509

progress: correctly handle empty progress topic
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sat, 13 Feb 2010 09:55:28 +0100
parents e6dc44147234
children b39b32c33269
files hgext/progress.py
diffstat 1 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/progress.py	Fri Feb 12 19:59:09 2010 -0500
+++ b/hgext/progress.py	Sat Feb 13 09:55:28 2010 +0100
@@ -140,25 +140,29 @@
     def clear(self):
         sys.stdout.write('\r%s\r' % (' ' * self.width()))
 
+    def complete(self):
+        if self.ui.configbool('progress', 'clear-complete', default=True):
+            self.clear()
+        else:
+            sys.stdout.write('\n')
+        sys.stdout.flush()
+
     def width(self):
         tw = util.termwidth()
         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
 
     def progress(self, orig, topic, pos, item='', unit='', total=None):
-        now = time.time()
-        if pos is None and self.topics[-1] == topic and self.printed:
-            if self.ui.configbool('progress', 'clear-complete', default=True):
-                self.clear()
-            else:
-                sys.stdout.write('\n')
-            sys.stdout.flush()
+        if pos is None:
+            if self.topics and self.topics[-1] == topic and self.printed:
+                self.complete()
             self.resetstate()
-        elif topic not in self.topics:
-            self.topics.append(topic)
-
-        if now - self.lastprint > 0.1 and topic == self.topics[-1]:
-            self.lastprint = now
-            self.show(topic, pos, item, unit, total)
+        else:
+            if topic not in self.topics:
+                self.topics.append(topic)
+            now = time.time()
+            if now - self.lastprint > 0.1 and topic == self.topics[-1]:
+                self.lastprint = now
+                self.show(topic, pos, item, unit, total)
         return orig(topic, pos, item=item, unit=unit, total=total)
 
     def write(self, orig, *args):