[PATCH 4 of 4] progress: slightly nicer handling of nested progress topics

Augie Fackler durin42 at gmail.com
Tue Oct 19 12:48:31 CDT 2010


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1287481985 -10800
# Node ID a6a67d123ccdd6e4cfb014f0b0feb011679a6236
# Parent  57a07c97a5d50b475eab77eafa393b4811faebf7
progress: slightly nicer handling of nested progress topics

Previously we'd declare "complete" after an inner progress topic
completed and erase the progress bar. Now we print the state of the
enclosing progress topic as it was last recorded.

diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -62,6 +62,7 @@
 
     def resetstate(self):
         self.topics = []
+        self.topicstates = {}
         self.pendingtopics = {}
         self.printed = False
         self.lastprint = time.time() + float(self.ui.config(
@@ -76,8 +77,13 @@
     def show(self, topic, pos, item, unit, total):
         if not shouldprint(self.ui):
             return
+        state = (topic, pos, item, unit, total)
+        if self.printed == state:
+            # don't double-print progress information, otherwise
+            # possible in the case of unwinding the topic stack
+            return
         termwidth = self.width()
-        self.printed = True
+        self.printed = state
         head = ''
         needprogress = False
         tail = ''
@@ -162,28 +168,31 @@
         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
 
     def progress(self, topic, pos, item='', unit='', total=None):
+        now = time.time()
         if pos is None:
             self.pendingtopics.pop(topic, None)
-            if self.topics and self.topics[-1] == topic and self.printed:
+            if self.topics and self.topics[0] == topic and self.printed:
                 self.complete()
                 self.resetstate()
+            if topic in self.topics:
+                self.topics = self.topics[:self.topics.index(topic)]
         else:
             if self.topics:
                 if topic in self.pendingtopics:
-                    if self.pendingtopics[topic] > time.time():
+                    if self.pendingtopics[topic] > now:
                         return
                 else:
-                    self.pendingtopics[topic] = time.time() + float(
+                    self.pendingtopics[topic] = now + float(
                         self.ui.config('progress', 'nestdelay', default=0.5))
                     return
             if topic not in self.topics:
                 self.pendingtopics[topic] = 0
                 self.topics.append(topic)
-            now = time.time()
-            if (now - self.lastprint >= self.refresh
-                and topic == self.topics[-1]):
-                self.lastprint = now
-                self.show(topic, pos, item, unit, total)
+            self.topicstates[topic] = pos, item, unit, total
+        if now - self.lastprint >= self.refresh and self.topics:
+            self.lastprint = now
+            curtopic = self.topics[-1]
+            self.show(curtopic, *self.topicstates[curtopic])
 
 def uisetup(ui):
     class progressui(ui.__class__):


More information about the Mercurial-devel mailing list