dispatch: extract command execution block into method
authorBill Barry <after.fallout@gmail.com>
Thu, 12 Feb 2009 09:36:15 -0700
changeset 7819 14b703252f14
parent 7818 b6b9065c20b3
child 7820 346fafc144fc
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.
mercurial/dispatch.py
--- 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():