comparison hgext/patchbomb.py @ 3291:0b5d626b354e

[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]
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 07 Oct 2006 15:16:47 -0400
parents 1e2941fda520
children 0e68608bd11d
comparison
equal deleted inserted replaced
3290:ae8583e746f1 3291:0b5d626b354e
156 body += '\n'.join(patch) 156 body += '\n'.join(patch)
157 msg = email.MIMEText.MIMEText(body) 157 msg = email.MIMEText.MIMEText(body)
158 if total == 1: 158 if total == 1:
159 subj = '[PATCH] ' + desc[0].strip() 159 subj = '[PATCH] ' + desc[0].strip()
160 else: 160 else:
161 subj = '[PATCH %d of %d] %s' % (idx, total, desc[0].strip()) 161 tlen = len(str(total))
162 subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, desc[0].strip())
162 if subj.endswith('.'): subj = subj[:-1] 163 if subj.endswith('.'): subj = subj[:-1]
163 msg['Subject'] = subj 164 msg['Subject'] = subj
164 msg['X-Mercurial-Node'] = node 165 msg['X-Mercurial-Node'] = node
165 return msg 166 return msg
166 167
215 bcc = [a.strip() for a in bcc if a.strip()] 216 bcc = [a.strip() for a in bcc if a.strip()]
216 217
217 if len(patches) > 1: 218 if len(patches) > 1:
218 ui.write(_('\nWrite the introductory message for the patch series.\n\n')) 219 ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
219 220
220 subj = '[PATCH 0 of %d] %s' % ( 221 tlen = len(str(len(patches)))
222
223 subj = '[PATCH %0*d of %d] %s' % (
224 tlen, 0,
221 len(patches), 225 len(patches),
222 opts['subject'] or 226 opts['subject'] or
223 prompt('Subject:', rest = ' [PATCH 0 of %d] ' % len(patches))) 227 prompt('Subject:', rest = ' [PATCH %0*d of %d] ' % (tlen, 0,
228 len(patches))))
224 229
225 ui.write(_('Finish with ^D or a dot on a line by itself.\n\n')) 230 ui.write(_('Finish with ^D or a dot on a line by itself.\n\n'))
226 231
227 body = [] 232 body = []
228 233