##// END OF EJS Templates
patch: export shouldn't close files received as a parameter...
Benoit Boissinot -
r7615:ab39d181 default
parent child Browse files
Show More
@@ -63,23 +63,10 b' That should be all. Now your patchbomb i'
63 import os, errno, socket, tempfile, cStringIO
63 import os, errno, socket, tempfile, cStringIO
64 import email.MIMEMultipart, email.MIMEBase
64 import email.MIMEMultipart, email.MIMEBase
65 import email.Utils, email.Encoders, email.Generator
65 import email.Utils, email.Encoders, email.Generator
66 from mercurial import cmdutil, commands, hg, mail, patch, util
66 from mercurial import cmdutil, commands, hg, mail, mdiff, patch, util
67 from mercurial.i18n import _
67 from mercurial.i18n import _
68 from mercurial.node import bin
68 from mercurial.node import bin
69
69
70 class exportee:
71 def __init__(self, container):
72 self.lines = []
73 self.container = container
74 self.name = 'email'
75
76 def write(self, data):
77 self.lines.append(data)
78
79 def close(self):
80 self.container.append(''.join(self.lines).split('\n'))
81 self.lines = []
82
83 def prompt(ui, prompt, default=None, rest=': ', empty_ok=False):
70 def prompt(ui, prompt, default=None, rest=': ', empty_ok=False):
84 if not ui.interactive:
71 if not ui.interactive:
85 return default
72 return default
@@ -234,6 +221,13 b' def patchbomb(ui, repo, *revs, **opts):'
234 o = repo.changelog.nodesbetween(o, revs or None)[0]
221 o = repo.changelog.nodesbetween(o, revs or None)[0]
235 return [str(repo.changelog.rev(r)) for r in o]
222 return [str(repo.changelog.rev(r)) for r in o]
236
223
224 def getpatches(revs):
225 for r in cmdutil.revrange(repo, revs):
226 output = cStringIO.StringIO()
227 p = patch.export(repo, [r], fp=output,
228 opts=mdiff.diffopts(git=opts.get('git')))
229 yield output.getvalue().split('\n')
230
237 def getbundle(dest):
231 def getbundle(dest):
238 tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
232 tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
239 tmpfn = os.path.join(tmpdir, 'bundle')
233 tmpfn = os.path.join(tmpdir, 'bundle')
@@ -355,18 +349,14 b' def patchbomb(ui, repo, *revs, **opts):'
355 ui.config('patchbomb', 'from') or
349 ui.config('patchbomb', 'from') or
356 prompt(ui, 'From', ui.username()))
350 prompt(ui, 'From', ui.username()))
357
351
352 # internal option used by pbranches
358 patches = opts.get('patches')
353 patches = opts.get('patches')
359 if patches:
354 if patches:
360 msgs = getpatchmsgs(patches, opts.get('patchnames'))
355 msgs = getpatchmsgs(patches, opts.get('patchnames'))
361 elif opts.get('bundle'):
356 elif opts.get('bundle'):
362 msgs = getbundlemsgs(getbundle(dest))
357 msgs = getbundlemsgs(getbundle(dest))
363 else:
358 else:
364 patches = []
359 msgs = getpatchmsgs(list(getpatches(revs)))
365 commands.export(ui, repo, *revs, **{'output': exportee(patches),
366 'switch_parent': False,
367 'text': None,
368 'git': opts.get('git')})
369 msgs = getpatchmsgs(patches)
370
360
371 def getaddrs(opt, prpt, default = None):
361 def getaddrs(opt, prpt, default = None):
372 addrs = opts.get(opt) or (ui.config('email', opt) or
362 addrs = opts.get(opt) or (ui.config('email', opt) or
@@ -1338,8 +1338,6 b" def export(repo, revs, template='hg-%h.p"
1338
1338
1339 for chunk in diff(repo, prev, node, opts=opts):
1339 for chunk in diff(repo, prev, node, opts=opts):
1340 fp.write(chunk)
1340 fp.write(chunk)
1341 if fp not in (sys.stdout, repo.ui):
1342 fp.close()
1343
1341
1344 for seqno, rev in enumerate(revs):
1342 for seqno, rev in enumerate(revs):
1345 single(rev, seqno+1, fp)
1343 single(rev, seqno+1, fp)
General Comments 0
You need to be logged in to leave comments. Login now