mercurial/cmdutil.py
changeset 4630 e6d105a51ec7
parent 4621 6fc26982f203
child 4632 8d46056960ab
--- a/mercurial/cmdutil.py	Mon Jun 18 15:21:02 2007 -0700
+++ b/mercurial/cmdutil.py	Mon Jun 18 17:49:56 2007 -0500
@@ -9,7 +9,7 @@
 from i18n import _
 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex
 import mdiff, bdiff, util, templater, patch, commands, hg, lock, time
-import fancyopts, revlog, version, extensions
+import fancyopts, revlog, version, extensions, hook
 
 revrangesep = ':'
 
@@ -272,6 +272,7 @@
     if fallback:
         util._fallbackencoding = fallback
 
+    fullargs = args
     cmd, func, args, options, cmdoptions = parse(ui, args)
 
     if options["encoding"]:
@@ -302,8 +303,8 @@
     elif not cmd:
         return commands.help_(ui, 'shortlist')
 
+    repo = None
     if cmd not in commands.norepo.split():
-        repo = None
         try:
             repo = hg.repository(ui, path=path)
             ui = repo.ui
@@ -316,7 +317,15 @@
     else:
         d = lambda: func(ui, *args, **cmdoptions)
 
-    return runcommand(ui, options, cmd, d)
+    # run pre-hook, and abort if it fails
+    ret = hook.hook(ui, 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(ui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
+                    result = ret)
+    return ret
 
 def runcommand(ui, options, cmd, cmdfunc):
     def checkargs():