changeset 7615:ab39d1813e51

patch: export shouldn't close files received as a parameter We rely on __del__ to close the fd instead. Patchbomb was relying on this behaviour, fix it. Thanks to Manuel Barkhau for reporting it.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Fri, 09 Jan 2009 01:36:35 +0100
parents dafcc96c1285
children b9bd6f789633
files hgext/patchbomb.py mercurial/patch.py
diffstat 2 files changed, 10 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/patchbomb.py	Thu Jan 08 14:26:30 2009 +0100
+++ b/hgext/patchbomb.py	Fri Jan 09 01:36:35 2009 +0100
@@ -63,23 +63,10 @@
 import os, errno, socket, tempfile, cStringIO
 import email.MIMEMultipart, email.MIMEBase
 import email.Utils, email.Encoders, email.Generator
-from mercurial import cmdutil, commands, hg, mail, patch, util
+from mercurial import cmdutil, commands, hg, mail, mdiff, patch, util
 from mercurial.i18n import _
 from mercurial.node import bin
 
-class exportee:
-    def __init__(self, container):
-        self.lines = []
-        self.container = container
-        self.name = 'email'
-
-    def write(self, data):
-        self.lines.append(data)
-
-    def close(self):
-        self.container.append(''.join(self.lines).split('\n'))
-        self.lines = []
-
 def prompt(ui, prompt, default=None, rest=': ', empty_ok=False):
     if not ui.interactive:
         return default
@@ -234,6 +221,13 @@
         o = repo.changelog.nodesbetween(o, revs or None)[0]
         return [str(repo.changelog.rev(r)) for r in o]
 
+    def getpatches(revs):
+        for r in cmdutil.revrange(repo, revs):
+            output = cStringIO.StringIO()
+            p = patch.export(repo, [r], fp=output,
+                             opts=mdiff.diffopts(git=opts.get('git')))
+            yield output.getvalue().split('\n')
+
     def getbundle(dest):
         tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
         tmpfn = os.path.join(tmpdir, 'bundle')
@@ -355,18 +349,14 @@
               ui.config('patchbomb', 'from') or
               prompt(ui, 'From', ui.username()))
 
+    # internal option used by pbranches
     patches = opts.get('patches')
     if patches:
         msgs = getpatchmsgs(patches, opts.get('patchnames'))
     elif opts.get('bundle'):
         msgs = getbundlemsgs(getbundle(dest))
     else:
-        patches = []
-        commands.export(ui, repo, *revs, **{'output': exportee(patches),
-                                            'switch_parent': False,
-                                            'text': None,
-                                            'git': opts.get('git')})
-        msgs = getpatchmsgs(patches)
+        msgs = getpatchmsgs(list(getpatches(revs)))
 
     def getaddrs(opt, prpt, default = None):
         addrs = opts.get(opt) or (ui.config('email', opt) or
--- a/mercurial/patch.py	Thu Jan 08 14:26:30 2009 +0100
+++ b/mercurial/patch.py	Fri Jan 09 01:36:35 2009 +0100
@@ -1338,8 +1338,6 @@
 
         for chunk in diff(repo, prev, node, opts=opts):
             fp.write(chunk)
-        if fp not in (sys.stdout, repo.ui):
-            fp.close()
 
     for seqno, rev in enumerate(revs):
         single(rev, seqno+1, fp)