Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 4630:e6d105a51ec7
dispatch: add generic pre- and post-command hooks
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 18 Jun 2007 17:49:56 -0500 |
parents | 6fc26982f203 |
children | 8d46056960ab |
line wrap: on
line diff
--- 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():