Mercurial > hg
changeset 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 | b6b9065c20b3 |
children | 346fafc144fc |
files | mercurial/dispatch.py |
diffstat | 1 files changed, 12 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dispatch.py Thu Feb 05 23:47:31 2009 +0100 +++ b/mercurial/dispatch.py Thu Feb 12 09:36:15 2009 -0700 @@ -239,6 +239,17 @@ pos += 1 return values +def runcommand(lui, repo, cmd, fullargs, ui, options, d): + # run pre-hook, and abort if it fails + ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) + if ret: + return ret + ret = _runcommand(ui, options, cmd, d) + # run post-hook, passing command result + hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), + result = ret) + return ret + _loaded = {} def _dispatch(ui, args): # read --config before doing anything else @@ -358,16 +369,7 @@ ui.warn("warning: --repository ignored\n") d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) - - # run pre-hook, and abort if it fails - ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) - if ret: - return ret - ret = _runcommand(ui, options, cmd, d) - # run post-hook, passing command result - hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), - result = ret) - return ret + return runcommand(lui, repo, cmd, fullargs, ui, options, d) def _runcommand(ui, options, cmd, cmdfunc): def checkargs():