# HG changeset patch # User Nicolas Dumazet # Date 2009-07-15 02:26:47 # Node ID bb3f8f692bc684797a93f2fedea8c7e6733d9d7a # Parent 94114ea3503d9a9eed4c42e0417b87769401f199 patchbomb: add --flag to put flags in subject prefixes --flag foo uses: [PATCH foo] or [PATCH M of N foo] depending on the number of patches. Multiple flags are supported: --flag foo --flag bar gives [PATCH foo bar] diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -162,12 +162,16 @@ def makepatch(ui, repo, patch, opts, _ch body += '\n'.join(patch) msg = mail.mimetextpatch(body, display=opts.get('test')) + flag = ' '.join(opts.get('flag')) + if flag: + flag = ' ' + flag + subj = desc[0].strip().rstrip('. ') if total == 1 and not opts.get('intro'): - subj = '[PATCH] ' + (opts.get('subject') or subj) + subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj) else: tlen = len(str(total)) - subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj) + subj = '[PATCH %0*d of %d%s] %s' % (tlen, idx, total, flag, subj) msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) msg['X-Mercurial-Node'] = node return msg, subj @@ -322,11 +326,13 @@ def patchbomb(ui, repo, *revs, **opts): if len(patches) > 1 or opts.get('intro'): tlen = len(str(len(patches))) - subj = '[PATCH %0*d of %d] %s' % ( - tlen, 0, len(patches), - opts.get('subject') or - prompt(ui, 'Subject:', - rest=' [PATCH %0*d of %d] ' % (tlen, 0, len(patches)))) + flag = ' '.join(opts.get('flag')) + if flag: + subj = '[PATCH %0*d of %d %s] ' % (tlen, 0, len(patches), flag) + else: + subj = '[PATCH %0*d of %d] ' % (tlen, 0, len(patches)) + subj += opts.get('subject') or prompt(ui, 'Subject:', rest=subj, + default='None') body = '' if opts.get('diffstat'): @@ -477,6 +483,7 @@ emailopts = [ _('subject of first message (intro or single patch)')), ('', 'in-reply-to', '', _('message identifier to reply to')), + ('', 'flag', [], _('flags to add in subject prefixes')), ('t', 'to', [], _('email addresses of recipients')), ] diff --git a/tests/test-patchbomb b/tests/test-patchbomb --- a/tests/test-patchbomb +++ b/tests/test-patchbomb @@ -151,3 +151,19 @@ hg email --date '1970-1-1 0:1' -n -f quu hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar --in-reply-to baz \ -r 0:1 | fixheaders + +echo "% test single flag for single patch" +hg email --date '1970-1-1 0:1' -n --flag fooFlag -f quux -t foo -c bar -s test \ + -r 2 | fixheaders + +echo "% test single flag for multiple patches" +hg email --date '1970-1-1 0:1' -n --flag fooFlag -f quux -t foo -c bar -s test \ + -r 0:1 | fixheaders + +echo "% test mutiple flags for single patch" +hg email --date '1970-1-1 0:1' -n --flag fooFlag --flag barFlag -f quux -t foo \ + -c bar -s test -r 2 | fixheaders + +echo "% test multiple flags for multiple patches" +hg email --date '1970-1-1 0:1' -n --flag fooFlag --flag barFlag -f quux -t foo \ + -c bar -s test -r 0:1 | fixheaders diff --git a/tests/test-patchbomb.out b/tests/test-patchbomb.out --- a/tests/test-patchbomb.out +++ b/tests/test-patchbomb.out @@ -1254,3 +1254,215 @@ diff -r 8580ff50825a -r 97d72e5f12c7 b @@ -0,0 +1,1 @@ +b +% test single flag for single patch +This patch series consists of 1 patches. + + +Displaying [PATCH fooFlag] test ... +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Subject: [PATCH fooFlag] test +X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f +Message-Id: