comparison mercurial/dispatch.py @ 11330:713ae78bb583

provide pre- and post- hooks with parsed command line arguments. python hooks are passed two new keyword arguments: - opts: a dict of options; unsepcified options are set to their default - pats: a list of arguments shell hooks receive two new variables containing string representations of the above data: - $HG_OPTS - $HG_PATS for example, the opts and pats for 'hg -f v1.1' would be: {'force': True, 'message': '', 'rev': '', 'user': '', 'date': '', 'local': None, 'remove': None, 'mq': None} ['v1.1']
author Chad Dombrova <chadrik@gmail.com>
date Thu, 10 Jun 2010 09:32:19 -0700
parents d4cafcb63f77
children 2347513f562a d8d0fc3988ca
comparison
equal deleted inserted replaced
11329:390518de232e 11330:713ae78bb583
340 argcount -= 1 340 argcount -= 1
341 else: 341 else:
342 pos += 1 342 pos += 1
343 return values 343 return values
344 344
345 def runcommand(lui, repo, cmd, fullargs, ui, options, d): 345 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions):
346 # run pre-hook, and abort if it fails 346 # run pre-hook, and abort if it fails
347 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) 347 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs),
348 pats=cmdpats, opts=cmdoptions)
348 if ret: 349 if ret:
349 return ret 350 return ret
350 ret = _runcommand(ui, options, cmd, d) 351 ret = _runcommand(ui, options, cmd, d)
351 # run post-hook, passing command result 352 # run post-hook, passing command result
352 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), 353 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
353 result = ret) 354 result=ret, pats=cmdpats, opts=cmdoptions)
354 return ret 355 return ret
355 356
356 _loaded = set() 357 _loaded = set()
357 def _dispatch(ui, args): 358 def _dispatch(ui, args):
358 # read --config before doing anything else 359 # read --config before doing anything else
452 return commands.version_(ui) 453 return commands.version_(ui)
453 elif not cmd: 454 elif not cmd:
454 return commands.help_(ui, 'shortlist') 455 return commands.help_(ui, 'shortlist')
455 456
456 repo = None 457 repo = None
458 cmdpats = args[:]
457 if cmd not in commands.norepo.split(): 459 if cmd not in commands.norepo.split():
458 try: 460 try:
459 repo = hg.repository(ui, path=path) 461 repo = hg.repository(ui, path=path)
460 ui = repo.ui 462 ui = repo.ui
461 if not repo.local(): 463 if not repo.local():
475 args.insert(0, repo) 477 args.insert(0, repo)
476 elif rpath: 478 elif rpath:
477 ui.warn("warning: --repository ignored\n") 479 ui.warn("warning: --repository ignored\n")
478 480
479 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) 481 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
480 return runcommand(lui, repo, cmd, fullargs, ui, options, d) 482 return runcommand(lui, repo, cmd, fullargs, ui, options, d,
483 cmdpats, cmdoptions)
481 484
482 def _runcommand(ui, options, cmd, cmdfunc): 485 def _runcommand(ui, options, cmd, cmdfunc):
483 def checkargs(): 486 def checkargs():
484 try: 487 try:
485 return cmdfunc() 488 return cmdfunc()