##// END OF EJS Templates
patchbomb: consistently use opts.get
Christian Ebert -
r5818:77775ae8 default
parent child Browse files
Show More
@@ -166,16 +166,16 b' def patchbomb(ui, repo, *revs, **opts):'
166 # 'Patch subject is complete summary.')
166 # 'Patch subject is complete summary.')
167 #body += '\n\n\n'
167 #body += '\n\n\n'
168
168
169 if opts['plain']:
169 if opts.get('plain'):
170 while patch and patch[0].startswith('# '):
170 while patch and patch[0].startswith('# '):
171 patch.pop(0)
171 patch.pop(0)
172 if patch:
172 if patch:
173 patch.pop(0)
173 patch.pop(0)
174 while patch and not patch[0].strip():
174 while patch and not patch[0].strip():
175 patch.pop(0)
175 patch.pop(0)
176 if opts['diffstat']:
176 if opts.get('diffstat'):
177 body += cdiffstat('\n'.join(desc), patch) + '\n\n'
177 body += cdiffstat('\n'.join(desc), patch) + '\n\n'
178 if opts['attach']:
178 if opts.get('attach'):
179 msg = email.MIMEMultipart.MIMEMultipart()
179 msg = email.MIMEMultipart.MIMEMultipart()
180 if body:
180 if body:
181 msg.attach(email.MIMEText.MIMEText(body, 'plain'))
181 msg.attach(email.MIMEText.MIMEText(body, 'plain'))
@@ -199,7 +199,7 b' def patchbomb(ui, repo, *revs, **opts):'
199
199
200 subj = desc[0].strip().rstrip('. ')
200 subj = desc[0].strip().rstrip('. ')
201 if total == 1:
201 if total == 1:
202 subj = '[PATCH] ' + (opts['subject'] or subj)
202 subj = '[PATCH] ' + (opts.get('subject') or subj)
203 else:
203 else:
204 tlen = len(str(total))
204 tlen = len(str(total))
205 subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj)
205 subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj)
@@ -233,7 +233,7 b' def patchbomb(ui, repo, *revs, **opts):'
233 pass
233 pass
234 os.rmdir(tmpdir)
234 os.rmdir(tmpdir)
235
235
236 if not (opts['test'] or opts['mbox']):
236 if not (opts.get('test') or opts.get('mbox')):
237 # really sending
237 # really sending
238 mail.validateconfig(ui)
238 mail.validateconfig(ui)
239
239
@@ -264,7 +264,7 b' def patchbomb(ui, repo, *revs, **opts):'
264
264
265 # start
265 # start
266 if opts.get('date'):
266 if opts.get('date'):
267 start_time = util.parsedate(opts['date'])
267 start_time = util.parsedate(opts.get('date'))
268 else:
268 else:
269 start_time = util.makedate()
269 start_time = util.makedate()
270
270
@@ -272,8 +272,8 b' def patchbomb(ui, repo, *revs, **opts):'
272 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
272 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
273
273
274 def getdescription(body, sender):
274 def getdescription(body, sender):
275 if opts['desc']:
275 if opts.get('desc'):
276 body = open(opts['desc']).read()
276 body = open(opts.get('desc')).read()
277 else:
277 else:
278 ui.write(_('\nWrite the introductory message for the '
278 ui.write(_('\nWrite the introductory message for the '
279 'patch series.\n\n'))
279 'patch series.\n\n'))
@@ -316,12 +316,12 b' def patchbomb(ui, repo, *revs, **opts):'
316
316
317 subj = '[PATCH %0*d of %d] %s' % (
317 subj = '[PATCH %0*d of %d] %s' % (
318 tlen, 0, len(patches),
318 tlen, 0, len(patches),
319 opts['subject'] or
319 opts.get('subject') or
320 prompt('Subject:',
320 prompt('Subject:',
321 rest=' [PATCH %0*d of %d] ' % (tlen, 0, len(patches))))
321 rest=' [PATCH %0*d of %d] ' % (tlen, 0, len(patches))))
322
322
323 body = ''
323 body = ''
324 if opts['diffstat']:
324 if opts.get('diffstat'):
325 d = cdiffstat(_('Final summary:\n'), jumbo)
325 d = cdiffstat(_('Final summary:\n'), jumbo)
326 if d:
326 if d:
327 body = '\n' + d
327 body = '\n' + d
@@ -334,7 +334,7 b' def patchbomb(ui, repo, *revs, **opts):'
334 return msgs
334 return msgs
335
335
336 def getbundlemsgs(bundle):
336 def getbundlemsgs(bundle):
337 subj = (opts['subject']
337 subj = (opts.get('subject')
338 or prompt('Subject:', default='A bundle for your repository'))
338 or prompt('Subject:', default='A bundle for your repository'))
339
339
340 body = getdescription('', sender)
340 body = getdescription('', sender)
@@ -350,7 +350,7 b' def patchbomb(ui, repo, *revs, **opts):'
350 msg['Subject'] = subj
350 msg['Subject'] = subj
351 return [msg]
351 return [msg]
352
352
353 sender = (opts['from'] or ui.config('email', 'from') or
353 sender = (opts.get('from') or ui.config('email', 'from') or
354 ui.config('patchbomb', 'from') or
354 ui.config('patchbomb', 'from') or
355 prompt('From', ui.username()))
355 prompt('From', ui.username()))
356
356
@@ -360,7 +360,7 b' def patchbomb(ui, repo, *revs, **opts):'
360 msgs = getexportmsgs()
360 msgs = getexportmsgs()
361
361
362 def getaddrs(opt, prpt, default = None):
362 def getaddrs(opt, prpt, default = None):
363 addrs = opts[opt] or (ui.config('email', opt) or
363 addrs = opts.get(opt) or (ui.config('email', opt) or
364 ui.config('patchbomb', opt) or
364 ui.config('patchbomb', opt) or
365 prompt(prpt, default = default)).split(',')
365 prompt(prpt, default = default)).split(',')
366 return [a.strip() for a in addrs if a.strip()]
366 return [a.strip() for a in addrs if a.strip()]
@@ -368,7 +368,7 b' def patchbomb(ui, repo, *revs, **opts):'
368 to = getaddrs('to', 'To')
368 to = getaddrs('to', 'To')
369 cc = getaddrs('cc', 'Cc', '')
369 cc = getaddrs('cc', 'Cc', '')
370
370
371 bcc = opts['bcc'] or (ui.config('email', 'bcc') or
371 bcc = opts.get('bcc') or (ui.config('email', 'bcc') or
372 ui.config('patchbomb', 'bcc') or '').split(',')
372 ui.config('patchbomb', 'bcc') or '').split(',')
373 bcc = [a.strip() for a in bcc if a.strip()]
373 bcc = [a.strip() for a in bcc if a.strip()]
374
374
@@ -396,7 +396,7 b' def patchbomb(ui, repo, *revs, **opts):'
396 m['Cc'] = ', '.join(cc)
396 m['Cc'] = ', '.join(cc)
397 if bcc:
397 if bcc:
398 m['Bcc'] = ', '.join(bcc)
398 m['Bcc'] = ', '.join(bcc)
399 if opts['test']:
399 if opts.get('test'):
400 ui.status('Displaying ', m['Subject'], ' ...\n')
400 ui.status('Displaying ', m['Subject'], ' ...\n')
401 ui.flush()
401 ui.flush()
402 if 'PAGER' in os.environ:
402 if 'PAGER' in os.environ:
@@ -411,9 +411,10 b' def patchbomb(ui, repo, *revs, **opts):'
411 raise
411 raise
412 if fp is not ui:
412 if fp is not ui:
413 fp.close()
413 fp.close()
414 elif opts['mbox']:
414 elif opts.get('mbox'):
415 ui.status('Writing ', m['Subject'], ' ...\n')
415 ui.status('Writing ', m['Subject'], ' ...\n')
416 fp = open(opts['mbox'], m.has_key('In-Reply-To') and 'ab+' or 'wb+')
416 fp = open(opts.get('mbox'),
417 m.has_key('In-Reply-To') and 'ab+' or 'wb+')
417 date = util.datestr(date=start_time,
418 date = util.datestr(date=start_time,
418 format='%a %b %d %H:%M:%S %Y', timezone=False)
419 format='%a %b %d %H:%M:%S %Y', timezone=False)
419 fp.write('From %s %s\n' % (sender_addr, date))
420 fp.write('From %s %s\n' % (sender_addr, date))
General Comments 0
You need to be logged in to leave comments. Login now