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