61 That should be all. Now your patchbomb is on its way out.''' |
61 That should be all. Now your patchbomb is on its way out.''' |
62 |
62 |
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 |
|
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 |
69 |
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 |
86 if default: |
73 if default: |
232 ui.status(_("no changes found\n")) |
219 ui.status(_("no changes found\n")) |
233 return [] |
220 return [] |
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') |
240 try: |
234 try: |
241 commands.bundle(ui, repo, tmpfn, dest, **opts) |
235 commands.bundle(ui, repo, tmpfn, dest, **opts) |
353 |
347 |
354 sender = (opts.get('from') or ui.config('email', 'from') or |
348 sender = (opts.get('from') or ui.config('email', 'from') or |
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 |
373 ui.config('patchbomb', opt) or |
363 ui.config('patchbomb', opt) or |
374 prompt(ui, prpt, default)).split(',') |
364 prompt(ui, prpt, default)).split(',') |