[PATCH 3 of 3 v2] progress: refactor for readability and show XXs instead of 0mXXs
Augie Fackler
durin42 at gmail.com
Mon Dec 13 23:58:44 CST 2010
# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1291937620 21600
# Node ID 0f652ea645ab7393dfdc507165f61b853fd6e092
# Parent 8a25d5d965b797f49f1e90c51cd1b67ac92e0244
progress: refactor for readability and show XXs instead of 0mXXs.
diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -55,6 +55,19 @@
return (getattr(sys.stderr, 'isatty', None) and
(sys.stderr.isatty() or ui.configbool('progress', 'assume-tty')))
+def fmtremaining(seconds):
+ if seconds < 60:
+ return _("%02ds") % (seconds)
+ minutes = seconds // 60
+ if minutes < 60:
+ seconds -= minutes * 60
+ return _("%dm%02ds") % (minutes, seconds)
+ # we're going to ignore seconds in this case
+ minutes += 1
+ hours = minutes // 60
+ minutes -= hours * 60
+ return _("%dh%02dm") % (hours, minutes)
+
class progbar(object):
def __init__(self, ui):
self.ui = ui
@@ -132,16 +145,7 @@
if elapsed > float(
self.ui.config('progress', 'estimate', default=2)):
seconds = (elapsed * (target - delta)) // delta + 1
- minutes = seconds // 60
- if minutes < 10:
- seconds -= minutes * 60
- remaining = _("%dm%02ds") % (minutes, seconds)
- else:
- # we're going to ignore seconds in this case
- minutes += 1
- hours = minutes // 60
- minutes -= hours * 60
- remaining = _("%dh%02dm") % (hours, minutes)
+ remaining = fmtremaining(seconds)
progwidth -= len(remaining) + 1
tail = spacejoin(tail, remaining)
amt = pos * progwidth // total
More information about the Mercurial-devel
mailing list