Show More
@@ -978,20 +978,12 b' def pushkey(repo, proto, namespace, key,' | |||
|
978 | 978 | else: |
|
979 | 979 | new = encoding.tolocal(new) # normal path |
|
980 | 980 | |
|
981 | if util.safehasattr(proto, 'restore'): | |
|
982 | ||
|
983 | proto.redirect() | |
|
984 | ||
|
981 | with proto.mayberedirectstdio() as output: | |
|
985 | 982 | r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), |
|
986 | 983 | encoding.tolocal(old), new) or False |
|
987 | 984 | |
|
988 | output = proto.restore() | |
|
989 | ||
|
990 | return '%s\n%s' % (int(r), output) | |
|
991 | ||
|
992 | r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), | |
|
993 | encoding.tolocal(old), new) | |
|
994 | return '%s\n' % int(r) | |
|
985 | output = output.getvalue() if output else '' | |
|
986 | return '%s\n%s' % (int(r), output) | |
|
995 | 987 | |
|
996 | 988 | @wireprotocommand('stream_out') |
|
997 | 989 | def stream(repo, proto): |
@@ -8,6 +8,7 b' from __future__ import absolute_import' | |||
|
8 | 8 | |
|
9 | 9 | import abc |
|
10 | 10 | import cgi |
|
11 | import contextlib | |
|
11 | 12 | import struct |
|
12 | 13 | import sys |
|
13 | 14 | |
@@ -74,6 +75,20 b' class baseprotocolhandler(object):' | |||
|
74 | 75 | """ |
|
75 | 76 | |
|
76 | 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 | 92 | def redirect(self): |
|
78 | 93 | """may setup interception for stdout and stderr |
|
79 | 94 | |
@@ -151,6 +166,21 b' class webproto(baseprotocolhandler):' | |||
|
151 | 166 | for s in util.filechunkiter(self._req, limit=length): |
|
152 | 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 | 184 | def redirect(self): |
|
155 | 185 | self._oldio = self._ui.fout, self._ui.ferr |
|
156 | 186 | self._ui.ferr = self._ui.fout = stringio() |
@@ -393,6 +423,10 b' class sshv1protocolhandler(baseprotocolh' | |||
|
393 | 423 | fpout.write(self._fin.read(count)) |
|
394 | 424 | count = int(self._fin.readline()) |
|
395 | 425 | |
|
426 | @contextlib.contextmanager | |
|
427 | def mayberedirectstdio(self): | |
|
428 | yield None | |
|
429 | ||
|
396 | 430 | def redirect(self): |
|
397 | 431 | pass |
|
398 | 432 |
General Comments 0
You need to be logged in to leave comments.
Login now