# HG changeset patch # User Benoit Boissinot # Date 2009-01-09 00:36:35 # Node ID ab39d1813e5154d02904d387047caac13eed4243 # Parent dafcc96c12856e28834504771afc2bfc844cea5b 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. diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -63,23 +63,10 @@ That should be all. Now your patchbomb i 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 @@ def patchbomb(ui, repo, *revs, **opts): 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 @@ def patchbomb(ui, repo, *revs, **opts): 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 diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1338,8 +1338,6 @@ def export(repo, revs, template='hg-%h.p 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)