[patchbomb] prepend leading zeros in the "[PATCH N of M]" string
authorJosef "Jeff" Sipek <jeffpc@josefsipek.net>
Sat, 07 Oct 2006 15:16:47 -0400
changeset 3291 0b5d626b354e
parent 3290 ae8583e746f1
child 3292 764688cf51e5
child 3317 399c04369a1b
child 3318 a225055b3b59
[patchbomb] prepend leading zeros in the "[PATCH N of M]" string Without this patch, if one tries to send a patch bomb with more than 9 patches, the resulting subjects are not easily alphabetically sortable. For example: ... [PATCH 9 of 10] [PATCH 10 of 10] This patch prepends as many leading zeros as necessary. E.g., [PATCH 09 of 10] or [PATCH 009 of 100]
hgext/patchbomb.py
--- a/hgext/patchbomb.py	Sun Oct 08 10:56:21 2006 +0200
+++ b/hgext/patchbomb.py	Sat Oct 07 15:16:47 2006 -0400
@@ -158,7 +158,8 @@
         if total == 1:
             subj = '[PATCH] ' + desc[0].strip()
         else:
-            subj = '[PATCH %d of %d] %s' % (idx, total, desc[0].strip())
+            tlen = len(str(total))
+            subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, desc[0].strip())
         if subj.endswith('.'): subj = subj[:-1]
         msg['Subject'] = subj
         msg['X-Mercurial-Node'] = node
@@ -217,10 +218,14 @@
     if len(patches) > 1:
         ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
 
-        subj = '[PATCH 0 of %d] %s' % (
+        tlen = len(str(len(patches)))
+
+        subj = '[PATCH %0*d of %d] %s' % (
+            tlen, 0,
             len(patches),
             opts['subject'] or
-            prompt('Subject:', rest = ' [PATCH 0 of %d] ' % len(patches)))
+            prompt('Subject:', rest = ' [PATCH %0*d of %d] ' % (tlen, 0,
+                len(patches))))
 
         ui.write(_('Finish with ^D or a dot on a line by itself.\n\n'))