##// END OF EJS Templates
py3: handle keyword arguments correctly in hgext/patchbomb.py...
Pulkit Goyal -
r35035:71e63fe6 default
parent child Browse files
Show More
@@ -89,6 +89,7 b' from mercurial import ('
89 89 mail,
90 90 node as nodemod,
91 91 patch,
92 pycompat,
92 93 registrar,
93 94 repair,
94 95 scmutil,
@@ -318,7 +319,7 b' def _getbundle(repo, dest, **opts):'
318 319 tmpfn = os.path.join(tmpdir, 'bundle')
319 320 btype = ui.config('patchbomb', 'bundletype')
320 321 if btype:
321 opts['type'] = btype
322 opts[r'type'] = btype
322 323 try:
323 324 commands.bundle(ui, repo, tmpfn, dest, **opts)
324 325 return util.readfile(tmpfn)
@@ -338,8 +339,8 b' def _getdescription(repo, defaultbody, s'
338 339 the user through the editor.
339 340 """
340 341 ui = repo.ui
341 if opts.get('desc'):
342 body = open(opts.get('desc')).read()
342 if opts.get(r'desc'):
343 body = open(opts.get(r'desc')).read()
343 344 else:
344 345 ui.write(_('\nWrite the introductory message for the '
345 346 'patch series.\n\n'))
@@ -359,21 +360,21 b' def _getbundlemsgs(repo, sender, bundle,'
359 360 """
360 361 ui = repo.ui
361 362 _charsets = mail._charsets(ui)
362 subj = (opts.get('subject')
363 subj = (opts.get(r'subject')
363 364 or prompt(ui, 'Subject:', 'A bundle for your repository'))
364 365
365 366 body = _getdescription(repo, '', sender, **opts)
366 367 msg = emailmod.MIMEMultipart.MIMEMultipart()
367 368 if body:
368 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
369 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get(r'test')))
369 370 datapart = emailmod.MIMEBase.MIMEBase('application', 'x-mercurial-bundle')
370 371 datapart.set_payload(bundle)
371 bundlename = '%s.hg' % opts.get('bundlename', 'bundle')
372 bundlename = '%s.hg' % opts.get(r'bundlename', 'bundle')
372 373 datapart.add_header('Content-Disposition', 'attachment',
373 374 filename=bundlename)
374 375 emailmod.Encoders.encode_base64(datapart)
375 376 msg.attach(datapart)
376 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
377 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get(r'test'))
377 378 return [(msg, subj, None)]
378 379
379 380 def _makeintro(repo, sender, revs, patches, **opts):
@@ -384,9 +385,9 b' def _makeintro(repo, sender, revs, patch'
384 385 _charsets = mail._charsets(ui)
385 386
386 387 # use the last revision which is likely to be a bookmarked head
387 prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'),
388 prefix = _formatprefix(ui, repo, revs.last(), opts.get(r'flag'),
388 389 0, len(patches), numbered=True)
389 subj = (opts.get('subject') or
390 subj = (opts.get(r'subject') or
390 391 prompt(ui, '(optional) Subject: ', rest=prefix, default=''))
391 392 if not subj:
392 393 return None # skip intro if the user doesn't bother
@@ -394,7 +395,7 b' def _makeintro(repo, sender, revs, patch'
394 395 subj = prefix + ' ' + subj
395 396
396 397 body = ''
397 if opts.get('diffstat'):
398 if opts.get(r'diffstat'):
398 399 # generate a cumulative diffstat of the whole patch series
399 400 diffstat = patch.diffstat(sum(patches, []))
400 401 body = '\n' + diffstat
@@ -402,9 +403,9 b' def _makeintro(repo, sender, revs, patch'
402 403 diffstat = None
403 404
404 405 body = _getdescription(repo, body, sender, **opts)
405 msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
406 msg = mail.mimeencode(ui, body, _charsets, opts.get(r'test'))
406 407 msg['Subject'] = mail.headencode(ui, subj, _charsets,
407 opts.get('test'))
408 opts.get(r'test'))
408 409 return (msg, subj, diffstat)
409 410
410 411 def _getpatchmsgs(repo, sender, revs, patchnames=None, **opts):
@@ -414,6 +415,7 b' def _getpatchmsgs(repo, sender, revs, pa'
414 415
415 416 This function returns a list of "email" tuples (subject, content, None).
416 417 """
418 bytesopts = pycompat.byteskwargs(opts)
417 419 ui = repo.ui
418 420 _charsets = mail._charsets(ui)
419 421 patches = list(_getpatches(repo, revs, **opts))
@@ -423,7 +425,7 b' def _getpatchmsgs(repo, sender, revs, pa'
423 425 % len(patches))
424 426
425 427 # build the intro message, or skip it if the user declines
426 if introwanted(ui, opts, len(patches)):
428 if introwanted(ui, bytesopts, len(patches)):
427 429 msg = _makeintro(repo, sender, revs, patches, **opts)
428 430 if msg:
429 431 msgs.append(msg)
@@ -437,8 +439,8 b' def _getpatchmsgs(repo, sender, revs, pa'
437 439 for i, (r, p) in enumerate(zip(revs, patches)):
438 440 if patchnames:
439 441 name = patchnames[i]
440 msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1,
441 len(patches), numbered, name)
442 msg = makepatch(ui, repo, r, p, bytesopts, _charsets,
443 i + 1, len(patches), numbered, name)
442 444 msgs.append(msg)
443 445
444 446 return msgs
@@ -579,6 +581,7 b' def email(ui, repo, *revs, **opts):'
579 581 Before using this command, you will need to enable email in your
580 582 hgrc. See the [email] section in hgrc(5) for details.
581 583 '''
584 opts = pycompat.byteskwargs(opts)
582 585
583 586 _charsets = mail._charsets(ui)
584 587
@@ -672,12 +675,13 b' def email(ui, repo, *revs, **opts):'
672 675 prompt(ui, 'From', ui.username()))
673 676
674 677 if bundle:
675 bundledata = _getbundle(repo, dest, **opts)
676 bundleopts = opts.copy()
677 bundleopts.pop('bundle', None) # already processed
678 stropts = pycompat.strkwargs(opts)
679 bundledata = _getbundle(repo, dest, **stropts)
680 bundleopts = stropts.copy()
681 bundleopts.pop(r'bundle', None) # already processed
678 682 msgs = _getbundlemsgs(repo, sender, bundledata, **bundleopts)
679 683 else:
680 msgs = _getpatchmsgs(repo, sender, revs, **opts)
684 msgs = _getpatchmsgs(repo, sender, revs, **pycompat.strkwargs(opts))
681 685
682 686 showaddrs = []
683 687
General Comments 0
You need to be logged in to leave comments. Login now