[PATCH] patchbomb: add --text flag to send patches both as inline text and as attachments

1 view
Skip to first unread message

Angel Ezquerra

unread,
Mar 20, 2012, 5:15:27 PM3/20/12
to mercuri...@selenic.com
# HG changeset patch
# User Angel Ezquerra <angel.e...@gmail.com>
# Date 1332234227 -3600
# Node ID 2893014b498c2e3413b0c93e7dfd2708ee0dbb80
# Parent 63a1bed65fa32262a45136a583fb6af117215241
patchbomb: add --text flag to send patches both as inline text and as attachments

There is currently no way to make patchbombo include patches both as attachments
and as inline text. This would be quite convenient when sending patches to
people who use web email clients (e.g. gmail) which often mangle the patches,
making them hard to apply.

The default behavior of the email command is unchanged. However you can now
use the --text flag _in addition_ to the -i or -a flags, in which case the
patchbomb emails will contain the patch as inline text and as an attachment.

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -84,7 +84,7 @@
if not patchname and not node:
raise ValueError

- if opts.get('attach'):
+ if opts.get('attach') and not opts.get('text'):
body = ('\n'.join(desc[1:]).strip() or
'Patch subject is complete summary.')
body += '\n\n\n'
@@ -101,7 +101,11 @@
if opts.get('diffstat'):
body += ds + '\n\n'

- if opts.get('attach') or opts.get('inline'):
+ addattachment = opts.get('attach') or opts.get('inline')
+ if not addattachment or opts.get('text'):
+ body += '\n'.join(patchlines)
+ msg = mail.mimetextpatch(body, display=opts.get('test'))
+ if addattachment:
msg = email.MIMEMultipart.MIMEMultipart()
if body:
msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
@@ -123,9 +127,6 @@
disposition = 'attachment'
p['Content-Disposition'] = disposition + '; filename=' + patchname
msg.attach(p)
- else:
- body += '\n'.join(patchlines)
- msg = mail.mimetextpatch(body, display=opts.get('test'))

flag = ' '.join(opts.get('flag'))
if flag:
@@ -142,6 +143,7 @@
return msg, subj, ds

emailopts = [
+ ('', 'text', None, _('send patches as inline text (the default)')),
('a', 'attach', None, _('send patches as attachments')),
('i', 'inline', None, _('send patches as inline attachments')),
('', 'bcc', [], _('email addresses of blind carbon copy recipients')),
_______________________________________________
Mercurial-devel mailing list
Mercuri...@selenic.com
http://selenic.com/mailman/listinfo/mercurial-devel

Greg Ward

unread,
Mar 20, 2012, 8:39:48 PM3/20/12
to Angel Ezquerra, mercuri...@selenic.com
On 20 March 2012, Angel Ezquerra said:
> # HG changeset patch
> # User Angel Ezquerra <angel.e...@gmail.com>
> # Date 1332234227 -3600
> # Node ID 2893014b498c2e3413b0c93e7dfd2708ee0dbb80
> # Parent 63a1bed65fa32262a45136a583fb6af117215241
> patchbomb: add --text flag to send patches both as inline text and as attachments

I think --body, --in-body, or --as-body are better names for this
option.

> There is currently no way to make patchbombo include patches both as attachments

patchbombo is the Spanish spelling? ;-)

> and as inline text. This would be quite convenient when sending patches to
> people who use web email clients (e.g. gmail) which often mangle the patches,
> making them hard to apply.
>
> The default behavior of the email command is unchanged. However you can now
> use the --text flag _in addition_ to the -i or -a flags, in which case the
> patchbomb emails will contain the patch as inline text and as an attachment.
>
> diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
> --- a/hgext/patchbomb.py
> +++ b/hgext/patchbomb.py

Tests?

Greg
--
Greg Ward http://www.gerg.ca/
What the hell, go ahead and put all your eggs in one basket.

Angel Ezquerra Moreu

unread,
Mar 21, 2012, 3:40:14 AM3/21/12
to Angel Ezquerra, mercuri...@selenic.com
On Wed, Mar 21, 2012 at 1:39 AM, Greg Ward <gr...@gerg.ca> wrote:
> On 20 March 2012, Angel Ezquerra said:
>> # HG changeset patch
>> # User Angel Ezquerra <angel.e...@gmail.com>
>> # Date 1332234227 -3600
>> # Node ID 2893014b498c2e3413b0c93e7dfd2708ee0dbb80
>> # Parent  63a1bed65fa32262a45136a583fb6af117215241
>> patchbomb: add --text flag to send patches both as inline text and as attachments
>
> I think --body, --in-body, or --as-body are better names for this
> option.

You are right. I did not like "--text" too much but I could not think
of anything better. I like "in-body" much more!

I believe that it is currently preferred not to use "-" on flag names.
However the email command already uses them on several of its flag
names (e.g. reply-to and in-reply-to). Should the new option be called
"inbody" instead?


>> There is currently no way to make patchbombo include patches both as attachments
>
> patchbombo is the Spanish spelling? ;-)

:-) Probably "bomba de parches" would be the accurate term.

>> and as inline text. This would be quite convenient when sending patches to
>> people who use web email clients (e.g. gmail) which often mangle the patches,
>> making them hard to apply.
>>
>> The default behavior of the email command is unchanged. However you can now
>> use the --text flag _in addition_ to the -i or -a flags, in which case the
>> patchbomb emails will contain the patch as inline text and as an attachment.
>>
>> diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
>> --- a/hgext/patchbomb.py
>> +++ b/hgext/patchbomb.py
>
> Tests?

I thought that I could not run the tests on Windows, which is my only
development environment (I am using hackable mercurial 2.1). However
http://mercurial.selenic.com/wiki/HackableMercurial implies that it
should be possible to run part of the test suite now (although the
setting it up seems a bit complicated).

Do you know if the patchbomb tests can be run on Windows?

Angel

Adrian Buehlmann

unread,
Mar 21, 2012, 4:24:27 AM3/21/12
to Angel Ezquerra Moreu, mercuri...@selenic.com

May I recommend to install VirtualBox
(https://www.virtualbox.org/wiki/Downloads) and then install a Linux in
a virtual machine (for example, Ubuntu is pretty easy to install and use).

This worked pretty well back when I was contributing to mercurial /
TortoiseHg. But you'll need a decent enough hardware to get acceptable
speed results. Or you'll need to install Linux natively (i.e. not in a
VM), which is not as handy as having linux in a VM, which allows you to
switch Windows <-> Linux desktops very convenientely.

Not running the testsuite on Linux (or similar) is IMHO pretty much a no no.

BTW, using virtual machines with pristine windows installs is also very
handy for testing TortoiseHg installers for Windows. The VMs make it
pretty easy to get back to the pristine OS state, which provides easy
repeatability.

Greg Ward

unread,
Mar 21, 2012, 9:38:40 AM3/21/12
to Angel Ezquerra Moreu, mercuri...@selenic.com
On 21 March 2012, Angel Ezquerra Moreu said:
> You are right. I did not like "--text" too much but I could not think
> of anything better. I like "in-body" much more!

Actually, I prefer --body. Short and sweet. Prepositions just get in
the way. ;-)

> I believe that it is currently preferred not to use "-" on flag names.
> However the email command already uses them on several of its flag
> names (e.g. reply-to and in-reply-to). Should the new option be called
> "inbody" instead?

I don't recall seeing documentation or an official pronouncement
anywhere, but I do remember that "strip --nobackup" was changed to
"strip --no-backup" to be consistent with revert, rather than the
other way around. So I think hyphens are OK in options. Just not
necessary in this case.

> > Tests?
>
> I thought that I could not run the tests on Windows, which is my only
> development environment (I am using hackable mercurial 2.1). However
> http://mercurial.selenic.com/wiki/HackableMercurial implies that it
> should be possible to run part of the test suite now (although the
> setting it up seems a bit complicated).
>
> Do you know if the patchbomb tests can be run on Windows?

No idea. Why don't you try it and let us know? My recollection is that
test-patchbomb.t uses "-n" for every test, and just asserts that the
textual output is correct. Testing a complete email system would be
challenging on any platform.

Greg
--
Greg Ward http://www.gerg.ca/

Know thyself. If you need help, call the CIA.

Reply all
Reply to author
Forward
0 new messages