[PATCH] hooks with pats and opts

Chad Dombrova chadrik at gmail.com
Mon May 24 17:38:12 CDT 2010


# HG changeset patch
# User Chad Dombrova <chadrik at gmail.com>
# Date 1274740669 25200
# Branch stable
# Node ID 2b11002ec5cec933968cf8228c3d4b77ef55eb3e
# Parent  00b7d5e53be99a784ccd6e0bd1bc64c275316a57
provide parsed python patterns and options to pre- and post- hooks.

python hooks receive two new keyword arguments:
- pats: a list of parsed patterns
- opts: a dictionary of parsed options; unsepcified options are set to their defaults

shell hooks receive two new variables containing the string reprentations of the above data:
- $HG_PATS
- $HG_OPTS

diff -r 00b7d5e53be9 -r 2b11002ec5ce mercurial/dispatch.py
--- a/mercurial/dispatch.py	Mon May 24 10:33:11 2010 -0700
+++ b/mercurial/dispatch.py	Mon May 24 15:37:49 2010 -0700
@@ -333,15 +333,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()
@@ -445,6 +446,7 @@
         return commands.help_(ui, 'shortlist')
 
     repo = None
+    cmdpats = args[:]
     if cmd not in commands.norepo.split():
         try:
             repo = hg.repository(ui, path=path)
@@ -468,7 +470,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():


More information about the Mercurial-devel mailing list