progress: stop getting stuck in a nested topic during a long inner step
authorAugie Fackler <raf@durin42.com>
Fri, 23 Aug 2013 13:28:18 -0400
changeset 19619 4694ccd5d994
parent 19618 6ac206fb6f27
child 19620 d4a0055af149
progress: stop getting stuck in a nested topic during a long inner step Convert, for example, has loops like this: for revision in source_repo: progress(revisions) for file in revision: progresss(file) Prior to this change, we would start showing the file-level progress when we encountered a big revision, and then we'd get stuck in showing file-progress instead of revision progress, often producing many many instantly-completing progress bars rather than the actually-helpful top-level revisions bar.
hgext/progress.py
tests/test-progress.t
--- a/hgext/progress.py	Thu Aug 15 21:36:53 2013 -0400
+++ b/hgext/progress.py	Fri Aug 23 13:28:18 2013 -0400
@@ -239,6 +239,13 @@
             # this one are also closed
             if topic in self.topics:
                 self.topics = self.topics[:self.topics.index(topic)]
+                # reset the last topic to the one we just unwound to,
+                # so that higher-level topics will be stickier than
+                # lower-level topics
+                if self.topics:
+                    self.lasttopic = self.topics[-1]
+                else:
+                    self.lasttopic = None
         else:
             if topic not in self.topics:
                 self.starttimes[topic] = now
--- a/tests/test-progress.t	Thu Aug 15 21:36:53 2013 -0400
+++ b/tests/test-progress.t	Fri Aug 23 13:28:18 2013 -0400
@@ -1,6 +1,14 @@
 
   $ cat > loop.py <<EOF
   > from mercurial import commands
+  > import time
+  > class incrementingtime(object):
+  >     def __init__(self):
+  >         self._time = 0.0
+  >     def __call__(self):
+  >         self._time += 0.25
+  >         return self._time
+  > time.time = incrementingtime()
   > 
   > def loop(ui, loops, **opts):
   >     loops = int(loops)
@@ -19,9 +27,14 @@
   >         if opts.get('parallel'):
   >             ui.progress('other', i, 'other.%d' % i, 'othernum', total)
   >         if nested:
-  >             for j in range(2):
-  >                 ui.progress('nested', j, 'nested.%d' % j, 'nestnum', 2)
-  >             ui.progress('nested', None, 'nested.done', 'nestnum', 2)
+  >             nested_steps = 2
+  >             if i and i % 4 == 0:
+  >                 nested_steps = 5
+  >             for j in range(nested_steps):
+  >                 ui.progress(
+  >                   'nested', j, 'nested.%d' % j, 'nestnum', nested_steps)
+  >             ui.progress(
+  >               'nested', None, 'nested.done', 'nestnum', nested_steps)
   >     ui.progress('loop', None, 'loop.done', 'loopnum', total)
   > 
   > commands.norepo += " loop"
@@ -69,6 +82,24 @@
   loop [===============================>                ] 2/3\r (no-eol) (esc)
                                                               \r (no-eol) (esc)
 
+Test nested long-lived topic which has the same name as a short-lived
+peer. We shouldn't get stuck showing the short-lived inner steps, and
+should go back to skipping the inner steps when the slow nested step
+finishes.
+
+  $ hg -y loop 7 --nested
+  \r (no-eol) (esc)
+  loop [                                                ] 0/7\r (no-eol) (esc)
+  loop [=====>                                          ] 1/7\r (no-eol) (esc)
+  loop [============>                                   ] 2/7\r (no-eol) (esc)
+  loop [===================>                            ] 3/7\r (no-eol) (esc)
+  loop [==========================>                     ] 4/7\r (no-eol) (esc)
+  nested [==========================>                   ] 3/5\r (no-eol) (esc)
+  nested [===================================>          ] 4/5\r (no-eol) (esc)
+  loop [=================================>              ] 5/7\r (no-eol) (esc)
+  loop [========================================>       ] 6/7\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+
 
   $ hg --config progress.changedelay=0 -y loop 3 --nested
   \r (no-eol) (esc)