# HG changeset patch # User Martin Geisler # Date 2011-05-09 14:41:45 # Node ID 98e4d3914c2e807bc68b04d2d28a8fd1edaa5e81 # Parent b039b667515d472a7ce456ab78a47069b0306a1b 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. diff --git a/hgext/progress.py b/hgext/progress.py --- a/hgext/progress.py +++ b/hgext/progress.py @@ -37,9 +37,9 @@ The following settings are available:: # 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 ``-`` which would -take the last num characters, or ``+`` 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 ``-`` which +would take the last num characters, or ``+`` for the first num characters. """ @@ -151,6 +151,8 @@ class progbar(object): 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 @@ class progbar(object): 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: