# HG changeset patch # User Yuya Nishihara # Date 1488014201 -32400 # Node ID 8018b90f8307c55e485375f650be8a8a6c0ef0a8 # Parent 5660c45ecba60b7a9de6efa0b9a658bc2943af89 patchbomb: factor out function that builds a prefix string to patch subject I'll add templating support. diff -r 5660c45ecba6 -r 8018b90f8307 hgext/patchbomb.py --- a/hgext/patchbomb.py Sun Jan 18 18:04:44 2015 +0900 +++ b/hgext/patchbomb.py Sat Feb 25 18:16:41 2017 +0900 @@ -135,6 +135,18 @@ intro = 1 < number return intro +def _formatprefix(flags, idx, total, numbered): + """build prefix to patch subject""" + flag = ' '.join(flags) + if flag: + flag = ' ' + flag + + if not numbered: + return '[PATCH%s]' % flag + else: + tlen = len(str(total)) + return '[PATCH %0*d of %d%s]' % (tlen, idx, total, flag) + def makepatch(ui, repo, patchlines, opts, _charsets, idx, total, numbered, patchname=None): @@ -202,16 +214,12 @@ else: msg = mail.mimetextpatch(body, display=opts.get('test')) - flag = ' '.join(opts.get('flag')) - if flag: - flag = ' ' + flag - + prefix = _formatprefix(opts.get('flag'), idx, total, numbered) subj = desc[0].strip().rstrip('. ') if not numbered: - subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj) + subj = ' '.join([prefix, opts.get('subject') or subj]) else: - tlen = len(str(total)) - subj = '[PATCH %0*d of %d%s] %s' % (tlen, idx, total, flag, subj) + subj = ' '.join([prefix, subj]) msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) msg['X-Mercurial-Node'] = node msg['X-Mercurial-Series-Index'] = '%i' % idx @@ -309,13 +317,8 @@ email is returned as (subject, body, cumulative-diffstat)""" ui = repo.ui _charsets = mail._charsets(ui) - tlen = len(str(len(patches))) - flag = opts.get('flag') or '' - if flag: - flag = ' ' + ' '.join(flag) - prefix = '[PATCH %0*d of %d%s]' % (tlen, 0, len(patches), flag) - + prefix = _formatprefix(opts.get('flag'), 0, len(patches), numbered=True) subj = (opts.get('subject') or prompt(ui, '(optional) Subject: ', rest=prefix, default='')) if not subj: