[PATCH 3 of 5] progress: only show time estimate when progress format contains 'estimate'

Augie Fackler durin42 at gmail.com
Wed Dec 15 11:25:35 CST 2010


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1292430126 21600
# Node ID 114f2d42d52214adc881dcd63ffa6100310cb76a
# Parent  b4b57fd01d89c45031e019c84130f66fd214b226
progress: only show time estimate when progress format contains 'estimate'

diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -36,10 +36,11 @@
   assume-tty = False # if true, ALWAYS show a progress bar, unless
                      # disable is given
 
-Valid entries for the format field are topic, bar, number, unit, 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.
+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
+characters.
 """
 
 import sys
@@ -128,6 +129,8 @@
                 needprogress = True
             elif indicator == 'unit' and unit:
                 add = unit
+            elif indicator == 'estimate':
+                add = self.estimate(topic, pos, total, now)
             if not needprogress:
                 head = spacejoin(head, add)
             else:
@@ -140,17 +143,6 @@
                 used += len(tail) + 1
             progwidth = termwidth - used - 3
             if total and pos <= total:
-                initial = self.startvals[topic]
-                target = total - initial
-                delta = pos - initial
-                if delta > 0:
-                    elapsed = now - self.starttimes[topic]
-                    if elapsed > float(
-                        self.ui.config('progress', 'estimate', default=2)):
-                        seconds = (elapsed * (target - delta)) // delta + 1
-                        remaining = fmtremaining(seconds)
-                        progwidth -= len(remaining) + 1
-                        tail = spacejoin(tail, remaining)
                 amt = pos * progwidth // total
                 bar = '=' * (amt - 1)
                 if amt > 0:
@@ -190,6 +182,18 @@
         tw = self.ui.termwidth()
         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
 
+    def estimate(self, topic, pos, total, now):
+        initialpos = self.startvals[topic]
+        target = total - initialpos
+        delta = pos - initialpos
+        if delta > 0:
+            elapsed = now - self.starttimes[topic]
+            if elapsed > float(
+                self.ui.config('progress', 'estimate', default=2)):
+                seconds = (elapsed * (target - delta)) // delta + 1
+                return fmtremaining(seconds)
+        return ''
+
     def progress(self, topic, pos, item='', unit='', total=None):
         now = time.time()
         if pos is None:


More information about the Mercurial-devel mailing list