diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -8,7 +8,7 @@ import os, mimetypes, re, mimetools, cStringIO from mercurial.node import * -from mercurial import mdiff, ui, hg, util, archival, patch +from mercurial import mdiff, ui, hg, util, archival, patch, hook from mercurial import revlog, templater from common import ErrorResponse, get_mtime, style_map, paritygen, get_contact from request import wsgirequest @@ -85,6 +85,7 @@ class hgweb(object): else: self.repo = repo + hook.redirect(True) self.mtime = -1 self.reponame = name self.archives = 'zip', 'gz', 'bz2' diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -6,7 +6,7 @@ # of the GNU General Public License, incorporated herein by reference. from i18n import _ -import util +import util, os, sys def _pythonhook(ui, repo, name, hname, funcname, args, throw): '''call python hook. hook is callable object, looked up as @@ -79,8 +79,18 @@ def _exthook(ui, repo, name, cmd, args, ui.warn(_('warning: %s hook %s\n') % (name, desc)) return r +_redirect = False +def redirect(state): + _redirect = state + def hook(ui, repo, name, throw=False, **args): r = False + + if _redirect: + # temporarily redirect stdout to stderr + oldstdout = os.dup(sys.stdout.fileno()) + os.dup2(sys.stderr.fileno(), sys.stdout.fileno()) + hooks = [(hname, cmd) for hname, cmd in ui.configitems("hooks") if hname.split(".", 1)[0] == name and cmd] hooks.sort() @@ -94,3 +104,6 @@ def hook(ui, repo, name, throw=False, ** r = _exthook(ui, repo, hname, cmd, args, throw) or r return r + if _redirect: + os.dup2(oldstdout, sys.stdout.fileno()) + os.close(oldstdout) diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py --- a/mercurial/sshserver.py +++ b/mercurial/sshserver.py @@ -8,7 +8,7 @@ from i18n import _ from node import * -import os, streamclone, sys, tempfile, util +import os, streamclone, sys, tempfile, util, hook class sshserver(object): def __init__(self, ui, repo): @@ -18,6 +18,7 @@ class sshserver(object): self.fin = sys.stdin self.fout = sys.stdout + hook.redirect(True) sys.stdout = sys.stderr # Prevent insertion/deletion of CRs