Show More
@@ -978,21 +978,13 b' def pushkey(repo, proto, namespace, key,' | |||||
978 | else: |
|
978 | else: | |
979 | new = encoding.tolocal(new) # normal path |
|
979 | new = encoding.tolocal(new) # normal path | |
980 |
|
980 | |||
981 | if util.safehasattr(proto, 'restore'): |
|
981 | with proto.mayberedirectstdio() as output: | |
982 |
|
||||
983 | proto.redirect() |
|
|||
984 |
|
||||
985 | r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), |
|
982 | r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), | |
986 | encoding.tolocal(old), new) or False |
|
983 | encoding.tolocal(old), new) or False | |
987 |
|
984 | |||
988 | output = proto.restore() |
|
985 | output = output.getvalue() if output else '' | |
989 |
|
||||
990 |
|
|
986 | return '%s\n%s' % (int(r), output) | |
991 |
|
987 | |||
992 | r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), |
|
|||
993 | encoding.tolocal(old), new) |
|
|||
994 | return '%s\n' % int(r) |
|
|||
995 |
|
||||
996 | @wireprotocommand('stream_out') |
|
988 | @wireprotocommand('stream_out') | |
997 | def stream(repo, proto): |
|
989 | def stream(repo, proto): | |
998 | '''If the server supports streaming clone, it advertises the "stream" |
|
990 | '''If the server supports streaming clone, it advertises the "stream" |
@@ -8,6 +8,7 b' from __future__ import absolute_import' | |||||
8 |
|
8 | |||
9 | import abc |
|
9 | import abc | |
10 | import cgi |
|
10 | import cgi | |
|
11 | import contextlib | |||
11 | import struct |
|
12 | import struct | |
12 | import sys |
|
13 | import sys | |
13 |
|
14 | |||
@@ -74,6 +75,20 b' class baseprotocolhandler(object):' | |||||
74 | """ |
|
75 | """ | |
75 |
|
76 | |||
76 | @abc.abstractmethod |
|
77 | @abc.abstractmethod | |
|
78 | def mayberedirectstdio(self): | |||
|
79 | """Context manager to possibly redirect stdio. | |||
|
80 | ||||
|
81 | The context manager yields a file-object like object that receives | |||
|
82 | stdout and stderr output when the context manager is active. Or it | |||
|
83 | yields ``None`` if no I/O redirection occurs. | |||
|
84 | ||||
|
85 | The intent of this context manager is to capture stdio output | |||
|
86 | so it may be sent in the response. Some transports support streaming | |||
|
87 | stdio to the client in real time. For these transports, stdio output | |||
|
88 | won't be captured. | |||
|
89 | """ | |||
|
90 | ||||
|
91 | @abc.abstractmethod | |||
77 | def redirect(self): |
|
92 | def redirect(self): | |
78 | """may setup interception for stdout and stderr |
|
93 | """may setup interception for stdout and stderr | |
79 |
|
94 | |||
@@ -151,6 +166,21 b' class webproto(baseprotocolhandler):' | |||||
151 | for s in util.filechunkiter(self._req, limit=length): |
|
166 | for s in util.filechunkiter(self._req, limit=length): | |
152 | fp.write(s) |
|
167 | fp.write(s) | |
153 |
|
168 | |||
|
169 | @contextlib.contextmanager | |||
|
170 | def mayberedirectstdio(self): | |||
|
171 | oldout = self._ui.fout | |||
|
172 | olderr = self._ui.ferr | |||
|
173 | ||||
|
174 | out = util.stringio() | |||
|
175 | ||||
|
176 | try: | |||
|
177 | self._ui.fout = out | |||
|
178 | self._ui.ferr = out | |||
|
179 | yield out | |||
|
180 | finally: | |||
|
181 | self._ui.fout = oldout | |||
|
182 | self._ui.ferr = olderr | |||
|
183 | ||||
154 | def redirect(self): |
|
184 | def redirect(self): | |
155 | self._oldio = self._ui.fout, self._ui.ferr |
|
185 | self._oldio = self._ui.fout, self._ui.ferr | |
156 | self._ui.ferr = self._ui.fout = stringio() |
|
186 | self._ui.ferr = self._ui.fout = stringio() | |
@@ -393,6 +423,10 b' class sshv1protocolhandler(baseprotocolh' | |||||
393 | fpout.write(self._fin.read(count)) |
|
423 | fpout.write(self._fin.read(count)) | |
394 | count = int(self._fin.readline()) |
|
424 | count = int(self._fin.readline()) | |
395 |
|
425 | |||
|
426 | @contextlib.contextmanager | |||
|
427 | def mayberedirectstdio(self): | |||
|
428 | yield None | |||
|
429 | ||||
396 | def redirect(self): |
|
430 | def redirect(self): | |
397 | pass |
|
431 | pass | |
398 |
|
432 |
General Comments 0
You need to be logged in to leave comments.
Login now