# HG changeset patch # User Matt Mackall # Date 1200078398 21600 # Node ID 323b9c55b328a88efe34be917d6ce1d77eef3e9f # Parent 2192ed1873190d4ce621f50867a15a4357a21a2c hook: redirect stdout to stderr for ssh and http servers diff -r 2192ed187319 -r 323b9c55b328 mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Fri Jan 11 06:07:43 2008 +0300 +++ b/mercurial/hgweb/hgweb_mod.py Fri Jan 11 13:06:38 2008 -0600 @@ -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 @@ else: self.repo = repo + hook.redirect(True) self.mtime = -1 self.reponame = name self.archives = 'zip', 'gz', 'bz2' diff -r 2192ed187319 -r 323b9c55b328 mercurial/hook.py --- a/mercurial/hook.py Fri Jan 11 06:07:43 2008 +0300 +++ b/mercurial/hook.py Fri Jan 11 13:06:38 2008 -0600 @@ -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 @@ 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 @@ r = _exthook(ui, repo, hname, cmd, args, throw) or r return r + if _redirect: + os.dup2(oldstdout, sys.stdout.fileno()) + os.close(oldstdout) diff -r 2192ed187319 -r 323b9c55b328 mercurial/sshserver.py --- a/mercurial/sshserver.py Fri Jan 11 06:07:43 2008 +0300 +++ b/mercurial/sshserver.py Fri Jan 11 13:06:38 2008 -0600 @@ -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 @@ self.fin = sys.stdin self.fout = sys.stdout + hook.redirect(True) sys.stdout = sys.stderr # Prevent insertion/deletion of CRs