# HG changeset patch # User Bill Barry # Date 2009-02-12 16:36:15 # Node ID 14b703252f1407f0e9293af5aa03b75b489ae854 # Parent b6b9065c20b31846ce11d49c57758f6bf4dafcc1 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. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -239,6 +239,17 @@ def _earlygetopt(aliases, args): 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 @@ def _dispatch(ui, args): 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():