progress: use %d to format ints instead of %s
authorAugie Fackler <augie@google.com>
Tue, 13 Feb 2018 10:20:57 -0500
changeset 42598 7f5108e58083503ea0b992a8d54c6f61ab2990db
parent 42597 d541042f32f6a18ee96c31f2333aca9f601162b2
child 42599 72d155a792b161b5ac6472c451018a437e183c47
push id689
push usergszorc@mozilla.com
push dateWed, 14 Feb 2018 06:07:45 +0000
progress: use %d to format ints instead of %s Due to behavioral changes between '% Ns' and '% Nd' this has some unfortunate extra dancing. I'm not sure of a better way to solve this problem. Differential Revision: https://phab.mercurial-scm.org/D2226
mercurial/progress.py
--- a/mercurial/progress.py
+++ b/mercurial/progress.py
@@ -115,17 +115,21 @@ class progbar(object):
         tail = ''
         for indicator in self.order:
             add = ''
             if indicator == 'topic':
                 add = topic
             elif indicator == 'number':
                 if total:
                     padamount = '%d' % len(str(total))
-                    add = ('% '+ padamount + 's/%s') % (pos, total)
+                    # '% 1d' % 1 adds an extra space compared to '% 1s' % 1.
+                    # To avoid this change in output, we convert to a string
+                    # first, then do the padding.
+                    spos = '%d' % pos
+                    add = ('% '+ padamount + 's/%d') % (spos, total)
                 else:
                     add = str(pos)
             elif indicator.startswith('item') and item:
                 slice = 'end'
                 if '-' in indicator:
                     wid = int(indicator.split('-')[1])
                 elif '+' in indicator:
                     slice = 'beginning'