changeset 9346:bb3f8f692bc6

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]
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Wed, 15 Jul 2009 11:26:47 +0900
parents 94114ea3503d
children d0474b184347
files hgext/patchbomb.py tests/test-patchbomb tests/test-patchbomb.out
diffstat 3 files changed, 242 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/patchbomb.py	Wed Aug 12 12:07:11 2009 -0500
+++ b/hgext/patchbomb.py	Wed Jul 15 11:26:47 2009 +0900
@@ -162,12 +162,16 @@
         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 @@
         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 @@
            _('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')),
          ]
 
--- a/tests/test-patchbomb	Wed Aug 12 12:07:11 2009 -0500
+++ b/tests/test-patchbomb	Wed Jul 15 11:26:47 2009 +0900
@@ -151,3 +151,19 @@
 
 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
--- a/tests/test-patchbomb.out	Wed Aug 12 12:07:11 2009 -0500
+++ b/tests/test-patchbomb.out	Wed Jul 15 11:26:47 2009 +0900
@@ -1254,3 +1254,215 @@
 @@ -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: <ff2c9fa2018b15fa74b3.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:00 +0000
+From: quux
+To: foo
+Cc: bar
+
+# HG changeset patch
+# User test
+# Date 3 0
+# Node ID ff2c9fa2018b15fa74b33363bda9527323e2a99f
+# Parent  97d72e5f12c7e84f85064aa72e5a297142c36ed9
+c
+
+diff -r 97d72e5f12c7 -r ff2c9fa2018b c
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/c	Thu Jan 01 00:00:03 1970 +0000
+@@ -0,0 +1,1 @@
++c
+
+% test single flag for multiple patches
+This patch series consists of 2 patches.
+
+
+Write the introductory message for the patch series.
+
+
+Displaying [PATCH 0 of 2 fooFlag] test ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 0 of 2 fooFlag] test
+Message-Id: <patchbomb.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:00 +0000
+From: quux
+To: foo
+Cc: bar
+
+
+Displaying [PATCH 1 of 2 fooFlag] a ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 1 of 2 fooFlag] a
+X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+Message-Id: <8580ff50825a50c8f716.61@
+In-Reply-To: <patchbomb.60@
+References: <patchbomb.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:01 +0000
+From: quux
+To: foo
+Cc: bar
+
+# HG changeset patch
+# User test
+# Date 1 0
+# Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+# Parent  0000000000000000000000000000000000000000
+a
+
+diff -r 000000000000 -r 8580ff50825a a
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/a	Thu Jan 01 00:00:01 1970 +0000
+@@ -0,0 +1,1 @@
++a
+
+Displaying [PATCH 2 of 2 fooFlag] b ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 2 of 2 fooFlag] b
+X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+Message-Id: <97d72e5f12c7e84f8506.62@
+In-Reply-To: <patchbomb.60@
+References: <patchbomb.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:02 +0000
+From: quux
+To: foo
+Cc: bar
+
+# HG changeset patch
+# User test
+# Date 2 0
+# Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+# Parent  8580ff50825a50c8f716709acdf8de0deddcd6ab
+b
+
+diff -r 8580ff50825a -r 97d72e5f12c7 b
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/b	Thu Jan 01 00:00:02 1970 +0000
+@@ -0,0 +1,1 @@
++b
+
+% test mutiple flags for single patch
+This patch series consists of 1 patches.
+
+
+Displaying [PATCH fooFlag barFlag] test ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH fooFlag barFlag] test
+X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
+Message-Id: <ff2c9fa2018b15fa74b3.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:00 +0000
+From: quux
+To: foo
+Cc: bar
+
+# HG changeset patch
+# User test
+# Date 3 0
+# Node ID ff2c9fa2018b15fa74b33363bda9527323e2a99f
+# Parent  97d72e5f12c7e84f85064aa72e5a297142c36ed9
+c
+
+diff -r 97d72e5f12c7 -r ff2c9fa2018b c
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/c	Thu Jan 01 00:00:03 1970 +0000
+@@ -0,0 +1,1 @@
++c
+
+% test multiple flags for multiple patches
+This patch series consists of 2 patches.
+
+
+Write the introductory message for the patch series.
+
+
+Displaying [PATCH 0 of 2 fooFlag barFlag] test ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 0 of 2 fooFlag barFlag] test
+Message-Id: <patchbomb.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:00 +0000
+From: quux
+To: foo
+Cc: bar
+
+
+Displaying [PATCH 1 of 2 fooFlag barFlag] a ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 1 of 2 fooFlag barFlag] a
+X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+Message-Id: <8580ff50825a50c8f716.61@
+In-Reply-To: <patchbomb.60@
+References: <patchbomb.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:01 +0000
+From: quux
+To: foo
+Cc: bar
+
+# HG changeset patch
+# User test
+# Date 1 0
+# Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+# Parent  0000000000000000000000000000000000000000
+a
+
+diff -r 000000000000 -r 8580ff50825a a
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/a	Thu Jan 01 00:00:01 1970 +0000
+@@ -0,0 +1,1 @@
++a
+
+Displaying [PATCH 2 of 2 fooFlag barFlag] b ...
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 2 of 2 fooFlag barFlag] b
+X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+Message-Id: <97d72e5f12c7e84f8506.62@
+In-Reply-To: <patchbomb.60@
+References: <patchbomb.60@
+User-Agent: Mercurial-patchbomb
+Date: Thu, 01 Jan 1970 00:01:02 +0000
+From: quux
+To: foo
+Cc: bar
+
+# HG changeset patch
+# User test
+# Date 2 0
+# Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+# Parent  8580ff50825a50c8f716709acdf8de0deddcd6ab
+b
+
+diff -r 8580ff50825a -r 97d72e5f12c7 b
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/b	Thu Jan 01 00:00:02 1970 +0000
+@@ -0,0 +1,1 @@
++b
+