Mercurial > hg
comparison hgext/patchbomb.py @ 23215:83a191031f94
patchbomb: extract 'getpatchmsgs' closure into its own function
Keep marching toward the promised land of simplification!
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 06 Nov 2014 11:55:37 +0000 |
parents | 563d33fc4b3d |
children | a074eeeabe32 |
comparison
equal
deleted
inserted
replaced
23214:563d33fc4b3d | 23215:83a191031f94 |
---|---|
270 msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) | 270 msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) |
271 msg['Subject'] = mail.headencode(ui, subj, _charsets, | 271 msg['Subject'] = mail.headencode(ui, subj, _charsets, |
272 opts.get('test')) | 272 opts.get('test')) |
273 return (msg, subj, diffstat) | 273 return (msg, subj, diffstat) |
274 | 274 |
275 def _getpatchmsgs(repo, sender, patches, patchnames=None, **opts): | |
276 """return a list of emails from a list of patches | |
277 | |
278 This involves introduction message creation if necessary. | |
279 | |
280 This function returns a list of "email" tuples (subject, content, None). | |
281 """ | |
282 ui = repo.ui | |
283 _charsets = mail._charsets(ui) | |
284 msgs = [] | |
285 | |
286 ui.write(_('this patch series consists of %d patches.\n\n') | |
287 % len(patches)) | |
288 | |
289 # build the intro message, or skip it if the user declines | |
290 if introwanted(opts, len(patches)): | |
291 msg = _makeintro(repo, sender, patches, **opts) | |
292 if msg: | |
293 msgs.append(msg) | |
294 | |
295 # are we going to send more than one message? | |
296 numbered = len(msgs) + len(patches) > 1 | |
297 | |
298 # now generate the actual patch messages | |
299 name = None | |
300 for i, p in enumerate(patches): | |
301 if patchnames: | |
302 name = patchnames[i] | |
303 msg = makepatch(ui, repo, p, opts, _charsets, i + 1, | |
304 len(patches), numbered, name) | |
305 msgs.append(msg) | |
306 | |
307 return msgs | |
308 | |
275 emailopts = [ | 309 emailopts = [ |
276 ('', 'body', None, _('send patches as inline message text (default)')), | 310 ('', 'body', None, _('send patches as inline message text (default)')), |
277 ('a', 'attach', None, _('send patches as attachments')), | 311 ('a', 'attach', None, _('send patches as attachments')), |
278 ('i', 'inline', None, _('send patches as inline attachments')), | 312 ('i', 'inline', None, _('send patches as inline attachments')), |
279 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')), | 313 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')), |
445 start_time = util.makedate() | 479 start_time = util.makedate() |
446 | 480 |
447 def genmsgid(id): | 481 def genmsgid(id): |
448 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn()) | 482 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn()) |
449 | 483 |
450 def getpatchmsgs(patches, patchnames=None): | |
451 msgs = [] | |
452 | |
453 ui.write(_('this patch series consists of %d patches.\n\n') | |
454 % len(patches)) | |
455 | |
456 # build the intro message, or skip it if the user declines | |
457 if introwanted(opts, len(patches)): | |
458 msg = _makeintro(repo, sender, patches, **opts) | |
459 if msg: | |
460 msgs.append(msg) | |
461 | |
462 # are we going to send more than one message? | |
463 numbered = len(msgs) + len(patches) > 1 | |
464 | |
465 # now generate the actual patch messages | |
466 name = None | |
467 for i, p in enumerate(patches): | |
468 if patchnames: | |
469 name = patchnames[i] | |
470 msg = makepatch(ui, repo, p, opts, _charsets, i + 1, | |
471 len(patches), numbered, name) | |
472 msgs.append(msg) | |
473 | |
474 return msgs | |
475 | |
476 | |
477 sender = (opts.get('from') or ui.config('email', 'from') or | 484 sender = (opts.get('from') or ui.config('email', 'from') or |
478 ui.config('patchbomb', 'from') or | 485 ui.config('patchbomb', 'from') or |
479 prompt(ui, 'From', ui.username())) | 486 prompt(ui, 'From', ui.username())) |
480 | 487 |
481 if patches: | 488 if patches: |
482 msgs = getpatchmsgs(patches, opts.get('patchnames')) | 489 msgs = _getpatchmsgs(repo, sender, patches, opts.get('patchnames'), |
490 **opts) | |
483 elif bundle: | 491 elif bundle: |
484 bundledata = _getbundle(repo, dest, **opts) | 492 bundledata = _getbundle(repo, dest, **opts) |
485 bundleopts = opts.copy() | 493 bundleopts = opts.copy() |
486 bundleopts.pop('bundle', None) # already processed | 494 bundleopts.pop('bundle', None) # already processed |
487 msgs = _getbundlemsgs(repo, sender, bundledata, **bundleopts) | 495 msgs = _getbundlemsgs(repo, sender, bundledata, **bundleopts) |
488 else: | 496 else: |
489 msgs = getpatchmsgs(list(_getpatches(repo, revs, **opts))) | 497 _patches = list(_getpatches(repo, revs, **opts)) |
498 msgs = _getpatchmsgs(repo, sender, _patches, **opts) | |
490 | 499 |
491 showaddrs = [] | 500 showaddrs = [] |
492 | 501 |
493 def getaddrs(header, ask=False, default=None): | 502 def getaddrs(header, ask=False, default=None): |
494 configkey = header.lower() | 503 configkey = header.lower() |