Mercurial > hg > mercurial-crew-with-dirclash
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 +++ b/mercurial/cmdutil.py @@ -9,7 +9,7 @@ from node import * 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 @@ def dispatch(ui, args): if fallback: util._fallbackencoding = fallback + fullargs = args cmd, func, args, options, cmdoptions = parse(ui, args) if options["encoding"]: @@ -302,8 +303,8 @@ def dispatch(ui, args): 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 @@ def dispatch(ui, args): 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():