progress: add speed format
This is not enabled by default, but the user can add it by setting
progress.format.
We might want to let the estimate format output a speed instead of an
ETA if there is not total. Currently estimate just returns the empty
string in that case.
--- a/hgext/progress.py Mon May 09 14:40:49 2011 +0200
+++ b/hgext/progress.py Mon May 09 16:41:45 2011 +0200
@@ -37,9 +37,9 @@
# disable is given
Valid entries for the format field are topic, bar, number, unit,
-estimate, and item. item defaults to the last 20 characters of the
-item, but this can be changed by adding either ``-<num>`` which would
-take the last num characters, or ``+<num>`` for the first num
+estimate, speed, and item. item defaults to the last 20 characters of
+the item, but this can be changed by adding either ``-<num>`` which
+would take the last num characters, or ``+<num>`` for the first num
characters.
"""
@@ -151,6 +151,8 @@
add = unit
elif indicator == 'estimate':
add = self.estimate(topic, pos, total, now)
+ elif indicator == 'speed':
+ add = self.speed(topic, pos, unit, now)
if not needprogress:
head = spacejoin(head, add)
else:
@@ -216,6 +218,15 @@
return fmtremaining(seconds)
return ''
+ def speed(self, topic, pos, unit, now):
+ initialpos = self.startvals[topic]
+ delta = pos - initialpos
+ elapsed = now - self.starttimes[topic]
+ if elapsed > float(
+ self.ui.config('progress', 'estimate', default=2)):
+ return _('%d %s/sec') % (delta / elapsed, unit)
+ return ''
+
def progress(self, topic, pos, item='', unit='', total=None):
now = time.time()
if pos is None: