[PATCH 1 of 3] progress: react more reasonably to nested progress topics

Augie Fackler durin42 at gmail.com
Sat Dec 11 12:05:14 CST 2010


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1292021772 21600
# Node ID f1bfbb584d4eed48ca9eac134b2feb1255a120f8
# Parent  bf763946f8b09fd23aa7835f44c8699998a8c389
progress: react more reasonably to nested progress topics

Previously, we'd reset the entire progress bar state when a topic was
completed, even if it wasn't the outermost progress topic. Now we
print the state of the next progress topic on the stack if one is left
rather than reset the progress bar.

diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -61,6 +61,7 @@
 
     def resetstate(self):
         self.topics = []
+        self.topicstates = {}
         self.printed = False
         self.lastprint = time.time() + float(self.ui.config(
             'progress', 'delay', default=3))
@@ -161,17 +162,24 @@
 
     def progress(self, topic, pos, item='', unit='', total=None):
         if pos is None:
-            if self.topics and self.topics[-1] == topic and self.printed:
+            self.topicstates.pop(topic, None)
+            # reset the progress bar if this is the outermost topic
+            if self.topics and self.topics[0] == topic and self.printed:
                 self.complete()
                 self.resetstate()
+            # truncate the list of topics assuming all topics within
+            # this one are also closed
+            if topic in self.topics:
+              self.topics = self.topics[:self.topics.index(topic)]
         else:
             if topic not in self.topics:
                 self.topics.append(topic)
             now = time.time()
-            if (now - self.lastprint >= self.refresh
-                and topic == self.topics[-1]):
+            self.topicstates[topic] = pos, item, unit, total
+            if now - self.lastprint >= self.refresh and self.topics:
                 self.lastprint = now
-                self.show(topic, pos, item, unit, total)
+                current = self.topics[-1]
+                self.show(current, *self.topicstates[current])
 
 def uisetup(ui):
     class progressui(ui.__class__):
diff --git a/tests/test-convert-svn-move.t b/tests/test-convert-svn-move.t
--- a/tests/test-convert-svn-move.t
+++ b/tests/test-convert-svn-move.t
@@ -196,13 +196,11 @@
                                                                                   
   converting [=======>                                                      ] 1/7
   scanning paths [                                                          ] 0/1
-                                                                                  
   getting files [==========================================================>] 1/1
                                                                                   
   converting [================>                                             ] 2/7
   scanning paths [                                                          ] 0/2
   scanning paths [============================>                             ] 1/2
-                                                                                  
   getting files [=============>                                             ] 1/4
   getting files [============================>                              ] 2/4
   getting files [===========================================>               ] 3/4
@@ -210,19 +208,16 @@
                                                                                   
   converting [=========================>                                    ] 3/7
   scanning paths [                                                          ] 0/1
-                                                                                  
   getting files [==========================================================>] 1/1
                                                                                   
   converting [==================================>                           ] 4/7
   scanning paths [                                                          ] 0/1
-                                                                                  
   getting files [==========================================================>] 1/1
                                                                                   
   converting [===========================================>                  ] 5/7
   scanning paths [                                                          ] 0/3
   scanning paths [==================>                                       ] 1/3
   scanning paths [=====================================>                    ] 2/3
-                                                                                  
   getting files [======>                                                    ] 1/8
   getting files [=============>                                             ] 2/8
   getting files [=====================>                                     ] 3/8
@@ -234,7 +229,6 @@
                                                                                   
   converting [====================================================>         ] 6/7
   scanning paths [                                                          ] 0/1
-                                                                                  
   getting files [======>                                                    ] 1/8
   getting files [=============>                                             ] 2/8
   getting files [=====================>                                     ] 3/8


More information about the Mercurial-devel mailing list