changeset 10891:83af68e38be3

progress: fall back to indeterminate progress if position is >= total
author Augie Fackler <durin42@gmail.com>
date Thu, 08 Apr 2010 15:04:00 -0500
parents 301633755dec
children e39e94377eb2
files hgext/progress.py tests/test-progress tests/test-progress.out
diffstat 3 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/progress.py	Sun Apr 11 14:25:02 2010 -0500
+++ b/hgext/progress.py	Thu Apr 08 15:04:00 2010 -0500
@@ -114,7 +114,7 @@
             if tail:
                 used += len(tail) + 1
             progwidth = termwidth - used - 3
-            if total:
+            if total and pos <= total:
                 amt = pos * progwidth // total
                 bar = '=' * (amt - 1)
                 if amt > 0:
--- a/tests/test-progress	Sun Apr 11 14:25:02 2010 -0500
+++ b/tests/test-progress	Thu Apr 08 15:04:00 2010 -0500
@@ -8,6 +8,8 @@
     total = None
     if loops >= 0:
         total = loops
+    if opts.get('total', None):
+        total = int(opts.get('total'))
     loops = abs(loops)
 
     for i in range(loops):
@@ -17,7 +19,8 @@
 commands.norepo += " loop"
 
 cmdtable = {
-    "loop": (loop, [], 'hg loop LOOPS'),
+    "loop": (loop, [('', 'total', '', 'override for total')],
+             'hg loop LOOPS'),
 }
 EOF
 
@@ -55,5 +58,8 @@
 echo '% test format options and indeterminate progress'
 hg -y --config 'progress.format=number item bar' loop -- -2 2>&1 | python filtercr.py
 
+echo "% make sure things don't fall over if count > total"
+hg -y loop --total 4 6 2>&1 | python filtercr.py
+
 echo '% test immediate progress completion'
 hg -y loop 0 2>&1 | python filtercr.py
--- a/tests/test-progress.out	Sun Apr 11 14:25:02 2010 -0500
+++ b/tests/test-progress.out	Thu Apr 08 15:04:00 2010 -0500
@@ -17,4 +17,12 @@
 
 0 loop.0               [ <=>                                                  ]
 1 loop.1               [  <=>                                                 ]
+                                                                                
% make sure things don't fall over if count > total
+
+loop [                                                                    ] 0/4
+loop [================>                                                   ] 1/4
+loop [=================================>                                  ] 2/4
+loop [==================================================>                 ] 3/4
+loop [===================================================================>] 4/4
+loop [ <=>                                                                ] 5/4
                                                                                 
% test immediate progress completion