[PATCH 3 of 3] progress: refactor for readability and show XXs instead of 0mXXs

Augie Fackler durin42 at gmail.com
Mon Dec 13 14:56:49 CST 2010


Found a bug in this today, will resend the whole series.

On Sat, Dec 11, 2010 at 12:05 PM, Augie Fackler <durin42 at gmail.com> wrote:
> # HG changeset patch
> # User Augie Fackler <durin42 at gmail.com>
> # Date 1291937620 21600
> # Node ID cd5c75062668af6962cc9dedc1dc980c17f1405a
> # Parent  02908b263aa8113b467c6934018162cc46f8f9d6
> 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
> +    remaining = _("%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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>


More information about the Mercurial-devel mailing list