comparison mercurial/dispatch.py @ 7819:14b703252f14

dispatch: extract command execution block into method This pulls the pre-command hook/command/post-command hook workflow out of the method it is in and puts it into its own method so that it potentially could be exposed for extensions to wrap.
author Bill Barry <after.fallout@gmail.com>
date Thu, 12 Feb 2009 09:36:15 -0700
parents 88887054d277
children 4a4c7f6a5912
comparison
equal deleted inserted replaced
7818:b6b9065c20b3 7819:14b703252f14
237 argcount -= 1 237 argcount -= 1
238 else: 238 else:
239 pos += 1 239 pos += 1
240 return values 240 return values
241 241
242 def runcommand(lui, repo, cmd, fullargs, ui, options, d):
243 # run pre-hook, and abort if it fails
244 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs))
245 if ret:
246 return ret
247 ret = _runcommand(ui, options, cmd, d)
248 # run post-hook, passing command result
249 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
250 result = ret)
251 return ret
252
242 _loaded = {} 253 _loaded = {}
243 def _dispatch(ui, args): 254 def _dispatch(ui, args):
244 # read --config before doing anything else 255 # read --config before doing anything else
245 # (e.g. to change trust settings for reading .hg/hgrc) 256 # (e.g. to change trust settings for reading .hg/hgrc)
246 config = _earlygetopt(['--config'], args) 257 config = _earlygetopt(['--config'], args)
356 args.insert(0, repo) 367 args.insert(0, repo)
357 elif rpath: 368 elif rpath:
358 ui.warn("warning: --repository ignored\n") 369 ui.warn("warning: --repository ignored\n")
359 370
360 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) 371 d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
361 372 return runcommand(lui, repo, cmd, fullargs, ui, options, d)
362 # run pre-hook, and abort if it fails
363 ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs))
364 if ret:
365 return ret
366 ret = _runcommand(ui, options, cmd, d)
367 # run post-hook, passing command result
368 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
369 result = ret)
370 return ret
371 373
372 def _runcommand(ui, options, cmd, cmdfunc): 374 def _runcommand(ui, options, cmd, cmdfunc):
373 def checkargs(): 375 def checkargs():
374 try: 376 try:
375 return cmdfunc() 377 return cmdfunc()