[PATCH] (resend+bugfix) Make patchbomb extension honor global encoding setting.

Wesley J. Landaker wjl at icecavern.net
Sat Jul 14 11:57:26 CDT 2007


# HG changeset patch
# User Wesley J. Landaker <wjl at icecavern.net>
# Date 1184432222 21600
# Node ID edc4c0731a68c25278253324385b6eed2e56fb3a
# Parent  28b23b9073a8652f95b87975f6648912dfec5f71
Make patchbomb extension honor global encoding setting.

Currently the patchbomb extension does not honor the global encoding
setting, using neither the default, nor honoring the --encoding option.
Instead, it always generates emails and patches using us-ascii. This
obviously works 90% of the time, but isn't correct, and breaks things
whenever people's names, logs of the changesets, etc are in the default
encoding (e.g. usually UTF-8 by default).

This patch makes patchbomb use the global encoding used everywhere else
in mercurial. Because things were broken for all encodings previously,
and the default mercurial encoding is a superset of us-ascii, this does
not have any backwards compatibility issues.

diff -r 28b23b9073a8 -r edc4c0731a68 hgext/patchbomb.py
--- a/hgext/patchbomb.py	Fri Jul 13 08:28:57 2007 -0700
+++ b/hgext/patchbomb.py	Sat Jul 14 10:57:02 2007 -0600
@@ -65,7 +65,7 @@
 # That should be all.  Now your patchbomb is on its way out.
 
 import os, errno, socket, tempfile
-import email.MIMEMultipart, email.MIMEText, email.MIMEBase
+import email.MIMEMultipart, email.MIMEText, email.MIMEBase, email.Charset
 import email.Utils, email.Encoders
 from mercurial import cmdutil, commands, hg, mail, ui, patch, util
 from mercurial.i18n import _
@@ -161,6 +161,11 @@ def patchbomb(ui, repo, *revs, **opts):
         #        'Patch subject is complete summary.')
         #body += '\n\n\n'
 
+        # always use raw encoding if we are previewing to the screen
+        # to make it easier to manually review without a mail client
+        if opts['test']:
+            email.Charset.add_charset(util._encoding.lower(), None, None)
+
         if opts['plain']:
             while patch and patch[0].startswith('# '): patch.pop(0)
             if patch: patch.pop(0)
@@ -169,8 +174,8 @@ def patchbomb(ui, repo, *revs, **opts):
             body += cdiffstat('\n'.join(desc), patch) + '\n\n'
         if opts['attach']:
             msg = email.MIMEMultipart.MIMEMultipart()
-            if body: msg.attach(email.MIMEText.MIMEText(body, 'plain'))
-            p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
+            if body: msg.attach(email.MIMEText.MIMEText(body, 'plain', util._encoding))
+            p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch', util._encoding)
             binnode = bin(node)
             # if node is mq patch, it will have patch file name as tag
             patchname = [t for t in repo.nodetags(binnode)
@@ -186,7 +191,7 @@ def patchbomb(ui, repo, *revs, **opts):
             msg.attach(p)
         else:
             body += '\n'.join(patch)
-            msg = email.MIMEText.MIMEText(body)
+            msg = email.MIMEText.MIMEText(body, 'plain', util._encoding)
 
         subj = desc[0].strip().rstrip('. ')
         if total == 1:



More information about the Mercurial-devel mailing list