diff hgext/progress.py @ 14838:5d261fd00446

progress: add a changedelay to prevent parallel topics from flapping (issue2698) When combined with the earlier change to make the progress object truly a singleton, this prevents the progress bar swapping on 'hg clone --pull' on a local filesystem. Thanks to timeless for lots of debugging help at the Copenhagen sprint to isolate the root cause of this and a first draft an idea that would fix it.
author Augie Fackler <durin42@gmail.com>
date Thu, 23 Jun 2011 15:00:45 -0500
parents ec4ba216ddef
children 06671371e634
line wrap: on
line diff
--- a/hgext/progress.py	Thu Jun 23 14:55:09 2011 -0500
+++ b/hgext/progress.py	Thu Jun 23 15:00:45 2011 -0500
@@ -27,6 +27,9 @@
 
   [progress]
   delay = 3 # number of seconds (float) before showing the progress bar
+  changedelay = 1 # changedelay: minimum delay before showing a new topic.
+                  # If set to less than 3 * refresh, that value will
+                  # be used instead.
   refresh = 0.1 # time in seconds between refreshes of the progress bar
   format = topic bar number estimate # format of the progress bar
   width = <none> # if set, the maximum width of the progress information
@@ -105,9 +108,13 @@
         self.printed = False
         self.lastprint = time.time() + float(self.ui.config(
             'progress', 'delay', default=3))
+        self.lasttopic = None
         self.indetcount = 0
         self.refresh = float(self.ui.config(
             'progress', 'refresh', default=0.1))
+        self.changedelay = max(3 * self.refresh,
+                               float(self.ui.config(
+                                   'progress', 'changedelay', default=1)))
         self.order = self.ui.configlist(
             'progress', 'format',
             default=['topic', 'bar', 'number', 'estimate'])
@@ -184,6 +191,7 @@
         else:
             out = spacejoin(head, tail)
         sys.stderr.write('\r' + out[:termwidth])
+        self.lasttopic = topic
         sys.stderr.flush()
 
     def clear(self):
@@ -248,8 +256,13 @@
                 self.topics.append(topic)
             self.topicstates[topic] = pos, item, unit, total
             if now - self.lastprint >= self.refresh and self.topics:
-                self.lastprint = now
-                self.show(now, topic, *self.topicstates[topic])
+                if (self.lasttopic is None # first time we printed
+                    # not a topic change
+                    or topic == self.lasttopic
+                    # it's been long enough we should print anyway
+                    or now - self.lastprint >= self.changedelay):
+                    self.lastprint = now
+                    self.show(now, topic, *self.topicstates[topic])
 
 _singleton = None