diff hgext/patchbomb.py @ 2707:084f07cacba0

patchbomb: add content-disposition to make display inline and add filename if rev being emailed has tag that ends in .patch or .diff then use that as filename. else make up filename from name of repo.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 27 Jul 2006 15:19:58 -0700
parents 4af7b178976a
children 10e95059ffd7
line wrap: on
line diff
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -45,6 +45,7 @@ demandload(globals(), '''email.MIMEMulti
                          mercurial:commands,hg,ui
                          os errno popen2 socket sys tempfile time''')
 from mercurial.i18n import gettext as _
+from mercurial.node import *
 
 try:
     # readline gives raw_input editing capabilities, but is not
@@ -133,7 +134,20 @@ def patchbomb(ui, repo, *revs, **opts):
         if opts['attach']:
             msg = email.MIMEMultipart.MIMEMultipart()
             if body: msg.attach(email.MIMEText.MIMEText(body, 'plain'))
-            msg.attach(email.MIMEText.MIMEText('\n'.join(patch), 'x-patch'))
+            p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
+            node = bin(node)
+            # if node is mq patch, it will have patch file name as tag
+            patchname = [t for t in repo.nodetags(node)
+                         if t.endswith('.patch') or t.endswith('.diff')]
+            if patchname:
+                patchname = patchname[0]
+            elif total > 1:
+                patchname = commands.make_filename(repo, '%b-%n.patch',
+                                                   node, idx, total)
+            else:
+                patchname = commands.make_filename(repo, '%b.patch', node)
+            p['Content-Disposition'] = 'inline; filename=' + patchname
+            msg.attach(p)
         else:
             body += '\n'.join(patch)
             msg = email.MIMEText.MIMEText(body)