diff mercurial/dispatch.py @ 11330:713ae78bb583

provide pre- and post- hooks with parsed command line arguments. python hooks are passed two new keyword arguments: - opts: a dict of options; unsepcified options are set to their default - pats: a list of arguments shell hooks receive two new variables containing string representations of the above data: - $HG_OPTS - $HG_PATS for example, the opts and pats for 'hg -f v1.1' would be: {'force': True, 'message': '', 'rev': '', 'user': '', 'date': '', 'local': None, 'remove': None, 'mq': None} ['v1.1']
author Chad Dombrova <chadrik@gmail.com>
date Thu, 10 Jun 2010 09:32:19 -0700
parents d4cafcb63f77
children 2347513f562a d8d0fc3988ca
line wrap: on
line diff
--- a/mercurial/dispatch.py	Wed Jun 09 16:25:28 2010 -0500
+++ b/mercurial/dispatch.py	Thu Jun 10 09:32:19 2010 -0700
@@ -342,15 +342,16 @@
             pos += 1
     return values
 
-def runcommand(lui, repo, cmd, fullargs, ui, options, d):
+def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions):
     # run pre-hook, and abort if it fails
-    ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs))
+    ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs),
+                    pats=cmdpats, opts=cmdoptions)
     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)
+              result=ret, pats=cmdpats, opts=cmdoptions)
     return ret
 
 _loaded = set()
@@ -454,6 +455,7 @@
         return commands.help_(ui, 'shortlist')
 
     repo = None
+    cmdpats = args[:]
     if cmd not in commands.norepo.split():
         try:
             repo = hg.repository(ui, path=path)
@@ -477,7 +479,8 @@
         ui.warn("warning: --repository ignored\n")
 
     d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
-    return runcommand(lui, repo, cmd, fullargs, ui, options, d)
+    return runcommand(lui, repo, cmd, fullargs, ui, options, d,
+                      cmdpats, cmdoptions)
 
 def _runcommand(ui, options, cmd, cmdfunc):
     def checkargs():