changeset 14280:98e4d3914c2e

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.
author Martin Geisler <mg@aragost.com>
date Mon, 09 May 2011 16:41:45 +0200
parents b039b667515d
children ccb7240acf32
files hgext/progress.py
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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: