comparison hgext/patchbomb.py @ 11413:4c1fe996838c

patchbomb: reduce number of opts.get calls Rename outgoing() function to getoutgoing() analogous to getbundle() etc. to avoid name conflict.
author Christian Ebert <blacktrash@gmx.net>
date Wed, 16 Jun 2010 00:37:21 +0200
parents 40c06bbf58be
children 6449be7b8a3b 469850088fc1
comparison
equal deleted inserted replaced
11412:51ceb1571805 11413:4c1fe996838c
233 hgrc. See the [email] section in hgrc(5) for details. 233 hgrc. See the [email] section in hgrc(5) for details.
234 ''' 234 '''
235 235
236 _charsets = mail._charsets(ui) 236 _charsets = mail._charsets(ui)
237 237
238 def outgoing(dest, revs): 238 bundle = opts.get('bundle')
239 date = opts.get('date')
240 mbox = opts.get('mbox')
241 outgoing = opts.get('outgoing')
242 rev = opts.get('rev')
243 # internal option used by pbranches
244 patches = opts.get('patches')
245
246 def getoutgoing(dest, revs):
239 '''Return the revisions present locally but not in dest''' 247 '''Return the revisions present locally but not in dest'''
240 dest = ui.expandpath(dest or 'default-push', dest or 'default') 248 dest = ui.expandpath(dest or 'default-push', dest or 'default')
241 dest, branches = hg.parseurl(dest) 249 dest, branches = hg.parseurl(dest)
242 revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) 250 revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
243 if revs: 251 if revs:
269 os.unlink(tmpfn) 277 os.unlink(tmpfn)
270 except: 278 except:
271 pass 279 pass
272 os.rmdir(tmpdir) 280 os.rmdir(tmpdir)
273 281
274 if not (opts.get('test') or opts.get('mbox')): 282 if not (opts.get('test') or mbox):
275 # really sending 283 # really sending
276 mail.validateconfig(ui) 284 mail.validateconfig(ui)
277 285
278 if not (revs or opts.get('rev') 286 if not (revs or rev or outgoing or bundle or patches):
279 or opts.get('outgoing') or opts.get('bundle')
280 or opts.get('patches')):
281 raise util.Abort(_('specify at least one changeset with -r or -o')) 287 raise util.Abort(_('specify at least one changeset with -r or -o'))
282 288
283 if opts.get('outgoing') and opts.get('bundle'): 289 if outgoing and bundle:
284 raise util.Abort(_("--outgoing mode always on with --bundle;" 290 raise util.Abort(_("--outgoing mode always on with --bundle;"
285 " do not re-specify --outgoing")) 291 " do not re-specify --outgoing"))
286 292
287 if opts.get('outgoing') or opts.get('bundle'): 293 if outgoing or bundle:
288 if len(revs) > 1: 294 if len(revs) > 1:
289 raise util.Abort(_("too many destinations")) 295 raise util.Abort(_("too many destinations"))
290 dest = revs and revs[0] or None 296 dest = revs and revs[0] or None
291 revs = [] 297 revs = []
292 298
293 if opts.get('rev'): 299 if rev:
294 if revs: 300 if revs:
295 raise util.Abort(_('use only one form to specify the revision')) 301 raise util.Abort(_('use only one form to specify the revision'))
296 revs = opts.get('rev') 302 revs = rev
297 303
298 if opts.get('outgoing'): 304 if outgoing:
299 revs = outgoing(dest, opts.get('rev')) 305 revs = getoutgoing(dest, rev)
300 if opts.get('bundle'): 306 if bundle:
301 opts['revs'] = revs 307 opts['revs'] = revs
302 308
303 # start 309 # start
304 if opts.get('date'): 310 if date:
305 start_time = util.parsedate(opts.get('date')) 311 start_time = util.parsedate(date)
306 else: 312 else:
307 start_time = util.makedate() 313 start_time = util.makedate()
308 314
309 def genmsgid(id): 315 def genmsgid(id):
310 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn()) 316 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
379 385
380 sender = (opts.get('from') or ui.config('email', 'from') or 386 sender = (opts.get('from') or ui.config('email', 'from') or
381 ui.config('patchbomb', 'from') or 387 ui.config('patchbomb', 'from') or
382 prompt(ui, 'From', ui.username())) 388 prompt(ui, 'From', ui.username()))
383 389
384 # internal option used by pbranches
385 patches = opts.get('patches')
386 if patches: 390 if patches:
387 msgs = getpatchmsgs(patches, opts.get('patchnames')) 391 msgs = getpatchmsgs(patches, opts.get('patchnames'))
388 elif opts.get('bundle'): 392 elif bundle:
389 msgs = getbundlemsgs(getbundle(dest)) 393 msgs = getbundlemsgs(getbundle(dest))
390 else: 394 else:
391 msgs = getpatchmsgs(list(getpatches(revs))) 395 msgs = getpatchmsgs(list(getpatches(revs)))
392 396
393 def getaddrs(opt, prpt=None, default=None): 397 def getaddrs(opt, prpt=None, default=None):
461 except IOError, inst: 465 except IOError, inst:
462 if inst.errno != errno.EPIPE: 466 if inst.errno != errno.EPIPE:
463 raise 467 raise
464 if fp is not ui: 468 if fp is not ui:
465 fp.close() 469 fp.close()
466 elif opts.get('mbox'): 470 elif mbox:
467 ui.status(_('Writing '), subj, ' ...\n') 471 ui.status(_('Writing '), subj, ' ...\n')
468 fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+') 472 fp = open(mbox, 'In-Reply-To' in m and 'ab+' or 'wb+')
469 generator = email.Generator.Generator(fp, mangle_from_=True) 473 generator = email.Generator.Generator(fp, mangle_from_=True)
470 # Should be time.asctime(), but Windows prints 2-characters day 474 # Should be time.asctime(), but Windows prints 2-characters day
471 # of month instead of one. Make them print the same thing. 475 # of month instead of one. Make them print the same thing.
472 date = time.strftime('%a %b %d %H:%M:%S %Y', 476 date = time.strftime('%a %b %d %H:%M:%S %Y',
473 time.localtime(start_time[0])) 477 time.localtime(start_time[0]))