##// END OF EJS Templates
hook: redirect stdout to stderr for ssh and http servers
Matt Mackall -
r5833:323b9c55 default
parent child Browse files
Show More
@@ -8,7 +8,7
8 8
9 9 import os, mimetypes, re, mimetools, cStringIO
10 10 from mercurial.node import *
11 from mercurial import mdiff, ui, hg, util, archival, patch
11 from mercurial import mdiff, ui, hg, util, archival, patch, hook
12 12 from mercurial import revlog, templater
13 13 from common import ErrorResponse, get_mtime, style_map, paritygen, get_contact
14 14 from request import wsgirequest
@@ -85,6 +85,7 class hgweb(object):
85 85 else:
86 86 self.repo = repo
87 87
88 hook.redirect(True)
88 89 self.mtime = -1
89 90 self.reponame = name
90 91 self.archives = 'zip', 'gz', 'bz2'
@@ -6,7 +6,7
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from i18n import _
9 import util
9 import util, os, sys
10 10
11 11 def _pythonhook(ui, repo, name, hname, funcname, args, throw):
12 12 '''call python hook. hook is callable object, looked up as
@@ -79,8 +79,18 def _exthook(ui, repo, name, cmd, args,
79 79 ui.warn(_('warning: %s hook %s\n') % (name, desc))
80 80 return r
81 81
82 _redirect = False
83 def redirect(state):
84 _redirect = state
85
82 86 def hook(ui, repo, name, throw=False, **args):
83 87 r = False
88
89 if _redirect:
90 # temporarily redirect stdout to stderr
91 oldstdout = os.dup(sys.stdout.fileno())
92 os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
93
84 94 hooks = [(hname, cmd) for hname, cmd in ui.configitems("hooks")
85 95 if hname.split(".", 1)[0] == name and cmd]
86 96 hooks.sort()
@@ -94,3 +104,6 def hook(ui, repo, name, throw=False, **
94 104 r = _exthook(ui, repo, hname, cmd, args, throw) or r
95 105 return r
96 106
107 if _redirect:
108 os.dup2(oldstdout, sys.stdout.fileno())
109 os.close(oldstdout)
@@ -8,7 +8,7
8 8
9 9 from i18n import _
10 10 from node import *
11 import os, streamclone, sys, tempfile, util
11 import os, streamclone, sys, tempfile, util, hook
12 12
13 13 class sshserver(object):
14 14 def __init__(self, ui, repo):
@@ -18,6 +18,7 class sshserver(object):
18 18 self.fin = sys.stdin
19 19 self.fout = sys.stdout
20 20
21 hook.redirect(True)
21 22 sys.stdout = sys.stderr
22 23
23 24 # Prevent insertion/deletion of CRs
General Comments 0
You need to be logged in to leave comments. Login now