[PATCH] progress: skip progress estimate when current exceeds total
timeless
timeless at gmail.com
Mon Mar 14 20:13:30 CDT 2011
# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1300013265 -7200
# Node ID 40db5a0ba4c811644dd97ce4a1dbd2b0d85172df
# Parent 0652b2da832daada866a68f7a4359227570c2447
progress: skip progress estimate when current exceeds total
This is to avoid nonsensical output like:
bundling [ <=> ] 463/405 -4s
diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -207,13 +207,26 @@ class progbar(object):
if total is None:
return ''
initialpos = self.startvals[topic]
- target = total - initialpos
- delta = pos - initialpos
- if delta > 0:
+ displacement = pos - initialpos + 1
+ remaining = total - pos
+ # 0 i p t p
+ # \--d--/ \--r--/
+ # ( e ) ( s )
+ # i = initialpos
+ # d = displacement from i to p
+ # p = pos (note that pos need not be <= total)
+ # r = remaining from pos to total
+ # e = elapsed
+ # s = seconds to reach t
+ #
+ # the time it takes to reach total
+ # assuming a constant rate (displacement/time)
+ # should be roughly t1 = (t * r) / d
+ if remaining >= 0:
elapsed = now - self.starttimes[topic]
if elapsed > float(
self.ui.config('progress', 'estimate', default=2)):
- seconds = (elapsed * (target - delta)) // delta + 1
+ seconds = (elapsed * (remaining)) // displacement
return fmtremaining(seconds)
return ''
diff --git a/tests/test-progress.t b/tests/test-progress.t
--- a/tests/test-progress.t
+++ b/tests/test-progress.t
@@ -158,6 +158,15 @@ test delay time estimates
loop [=============================> ] 3/4 23w02d
\r (esc)
+Time estimate with count overrun:
+ $ hg -y loop --total 4 6 2>&1 | python $TESTDIR/filtercr.py
+
+ loop [=====================> ] 2/4 23s
+ loop [================================> ] 3/4 12s
+ loop [===========================================>] 4/4 01s
+ loop [ <=> ] 5/4
+ \r (esc)
+
Time estimates should not fail when there's no end point:
$ hg -y loop -- -4 2>&1 | python $TESTDIR/filtercr.py
More information about the Mercurial-devel
mailing list