[PATCH] Patchbomb: option --text allows to send patches as plain text

Simon Heimberg simohe at besonet.ch
Sat Sep 20 06:03:47 CDT 2008


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1221908363 -7200
# Node ID c3a022ce4ecedee201e4d9d579b42970cc30dd5a
# Parent  1a6213062a2d8e1f9c3df5b87f9e90d802928a73
Patchbomb: option --text allows to send patches as plain text

diff -r 1a6213062a2d -r c3a022ce4ece hgext/patchbomb.py
--- a/hgext/patchbomb.py	Tue Sep 09 19:45:46 2008 +0200
+++ b/hgext/patchbomb.py	Sat Sep 20 12:59:23 2008 +0200
@@ -177,18 +177,24 @@
             msg = email.MIMEMultipart.MIMEMultipart()
             if body:
                 msg.attach(email.MIMEText.MIMEText(body, 'plain'))
-            p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
+            p = email.MIMEText.MIMEText('\n'.join(patch),
+                opts.get('text') and 'plain' or 'x-patch')
             binnode = bin(node)
             # if node is mq patch, it will have patch file name as tag
             patchname = [t for t in repo.nodetags(binnode)
                          if t.endswith('.patch') or t.endswith('.diff')]
+            ending = '.patch'
+            if opts.get('text'):
+                ending = '.txt'
             if patchname:
                 patchname = patchname[0]
+                if opts.get('text'):
+                    patchname[:patchname.rindex('.')] + ending
             elif total > 1:
-                patchname = cmdutil.make_filename(repo, '%b-%n.patch',
+                patchname = cmdutil.make_filename(repo, '%b-%n' + ending,
                                                   binnode, idx, total)
             else:
-                patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
+                patchname = cmdutil.make_filename(repo, '%b' + ending, binnode)
             disposition = 'inline'
             if opts['attach']:
                 disposition = 'attachment'
@@ -457,6 +463,7 @@
           ('s', 'subject', '',
            _('subject of first message (intro or single patch)')),
           ('t', 'to', [], _('email addresses of recipients')),
+          ('', 'text', None, _('mime type "text/plain" and file ending "txt"')),
           ('', 'force', None,
            _('run even when remote repository is unrelated (with -b)')),
           ('', 'base', [],
diff -r 1a6213062a2d -r c3a022ce4ece tests/test-patchbomb
--- a/tests/test-patchbomb	Tue Sep 09 19:45:46 2008 +0200
+++ b/tests/test-patchbomb	Sat Sep 20 12:59:23 2008 +0200
@@ -24,7 +24,11 @@
 hg email --date '1970-1-1 0:2' -n -f quux -t foo -c bar -s test 0:tip | \
   fixheaders
 
-hg email -m test.mbox -f quux -t foo -c bar -s test 0:tip
+hg email --date '1970-1-1 0:3' -m test.mbox -f quux -t foo -c bar -s test 0:tip
+cat test.mbox | fixheaders
+
+hg email --date '1970-1-1 0:4' -n -a --text -s testPlainText -f quux -t foo -c bar -r tip | \
+  fixheaders
 
 cd ..
 
diff -r 1a6213062a2d -r c3a022ce4ece tests/test-patchbomb.out
--- a/tests/test-patchbomb.out	Tue Sep 09 19:45:46 2008 +0200
+++ b/tests/test-patchbomb.out	Sat Sep 20 12:59:23 2008 +0200
@@ -107,6 +107,116 @@
 Writing [PATCH 0 of 2] test ...
 Writing [PATCH 1 of 2] a ...
 Writing [PATCH 2 of 2] b ...
+From quux Thu Jan 01 00:03:01 1970
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 0 of 2] test
+Message-Id: <patchbomb.180@
+Date: Thu, 01 Jan 1970 00:03:00 +0000
+From: quux
+To: foo
+Cc: bar
+
+
+
+From quux Thu Jan 01 00:03:02 1970
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 1 of 2] a
+X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+Message-Id: <8580ff50825a50c8f716.181@
+In-Reply-To: <patchbomb.180@
+Date: Thu, 01 Jan 1970 00:03: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
+
+
+From quux Thu Jan 01 00:03:03 1970
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Subject: [PATCH 2 of 2] b
+X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+Message-Id: <97d72e5f12c7e84f8506.182@
+In-Reply-To: <patchbomb.180@
+Date: Thu, 01 Jan 1970 00:03: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
+
+
+This patch series consists of 1 patches.
+
+
+Displaying [PATCH] testPlainText ...
+Content-Type: multipart/mixed; boundary="===
+MIME-Version: 1.0
+Subject: [PATCH] testPlainText
+X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+Message-Id: <97d72e5f12c7e84f8506.240@
+Date: Thu, 01 Jan 1970 00:04:00 +0000
+From: quux
+To: foo
+Cc: bar
+
+--===
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+Patch subject is complete summary.
+
+
+
+--===
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Disposition: attachment; filename=t.txt
+
+# 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
+
+--===
 adding c
 % test bundle and description
 searching for changes



More information about the Mercurial-devel mailing list