Show More
@@ -232,7 +232,7 b' def _newchgui(srcui, csystem):' | |||||
232 | # these situations and will behave differently (write to stdout). |
|
232 | # these situations and will behave differently (write to stdout). | |
233 | if (any(s[1] for s in self._bufferstates) |
|
233 | if (any(s[1] for s in self._bufferstates) | |
234 | or not util.safehasattr(self.fout, 'fileno') |
|
234 | or not util.safehasattr(self.fout, 'fileno') | |
235 |
or self.fout.fileno() != |
|
235 | or self.fout.fileno() != util.stdout.fileno()): | |
236 | return super(chgui, self).system(cmd, environ, cwd, onerr, |
|
236 | return super(chgui, self).system(cmd, environ, cwd, onerr, | |
237 | errprefix) |
|
237 | errprefix) | |
238 | # copied from mercurial/util.py:system() |
|
238 | # copied from mercurial/util.py:system() |
@@ -84,19 +84,19 b" testedwith = 'ships-with-hg-core'" | |||||
84 | def _runpager(ui, p): |
|
84 | def _runpager(ui, p): | |
85 | pager = subprocess.Popen(p, shell=True, bufsize=-1, |
|
85 | pager = subprocess.Popen(p, shell=True, bufsize=-1, | |
86 | close_fds=util.closefds, stdin=subprocess.PIPE, |
|
86 | close_fds=util.closefds, stdin=subprocess.PIPE, | |
87 |
stdout= |
|
87 | stdout=util.stdout, stderr=util.stderr) | |
88 |
|
88 | |||
89 | # back up original file objects and descriptors |
|
89 | # back up original file objects and descriptors | |
90 | olduifout = ui.fout |
|
90 | olduifout = ui.fout | |
91 |
oldstdout = |
|
91 | oldstdout = util.stdout | |
92 |
stdoutfd = os.dup( |
|
92 | stdoutfd = os.dup(util.stdout.fileno()) | |
93 |
stderrfd = os.dup( |
|
93 | stderrfd = os.dup(util.stderr.fileno()) | |
94 |
|
94 | |||
95 | # create new line-buffered stdout so that output can show up immediately |
|
95 | # create new line-buffered stdout so that output can show up immediately | |
96 |
ui.fout = |
|
96 | ui.fout = util.stdout = newstdout = os.fdopen(util.stdout.fileno(), 'wb', 1) | |
97 |
os.dup2(pager.stdin.fileno(), |
|
97 | os.dup2(pager.stdin.fileno(), util.stdout.fileno()) | |
98 |
if ui._isatty( |
|
98 | if ui._isatty(util.stderr): | |
99 |
os.dup2(pager.stdin.fileno(), |
|
99 | os.dup2(pager.stdin.fileno(), util.stderr.fileno()) | |
100 |
|
100 | |||
101 | @atexit.register |
|
101 | @atexit.register | |
102 | def killpager(): |
|
102 | def killpager(): | |
@@ -104,13 +104,13 b' def _runpager(ui, p):' | |||||
104 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
|
104 | signal.signal(signal.SIGINT, signal.SIG_IGN) | |
105 | pager.stdin.close() |
|
105 | pager.stdin.close() | |
106 | ui.fout = olduifout |
|
106 | ui.fout = olduifout | |
107 |
|
|
107 | util.stdout = oldstdout | |
108 | # close new stdout while it's associated with pager; otherwise stdout |
|
108 | # close new stdout while it's associated with pager; otherwise stdout | |
109 | # fd would be closed when newstdout is deleted |
|
109 | # fd would be closed when newstdout is deleted | |
110 | newstdout.close() |
|
110 | newstdout.close() | |
111 | # restore original fds: stdout is open again |
|
111 | # restore original fds: stdout is open again | |
112 |
os.dup2(stdoutfd, |
|
112 | os.dup2(stdoutfd, util.stdout.fileno()) | |
113 |
os.dup2(stderrfd, |
|
113 | os.dup2(stderrfd, util.stderr.fileno()) | |
114 | pager.wait() |
|
114 | pager.wait() | |
115 |
|
115 | |||
116 | def uisetup(ui): |
|
116 | def uisetup(ui): |
@@ -888,8 +888,8 b' def service(opts, parentfn=None, initfn=' | |||||
888 | raise error.Abort(_('invalid value for --daemon-postexec: %s') |
|
888 | raise error.Abort(_('invalid value for --daemon-postexec: %s') | |
889 | % inst) |
|
889 | % inst) | |
890 | util.hidewindow() |
|
890 | util.hidewindow() | |
891 |
|
|
891 | util.stdout.flush() | |
892 |
|
|
892 | util.stderr.flush() | |
893 |
|
893 | |||
894 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
894 | nullfd = os.open(os.devnull, os.O_RDWR) | |
895 | logfilefd = nullfd |
|
895 | logfilefd = nullfd |
@@ -15,7 +15,6 b' import select' | |||||
15 | import signal |
|
15 | import signal | |
16 | import socket |
|
16 | import socket | |
17 | import struct |
|
17 | import struct | |
18 | import sys |
|
|||
19 | import traceback |
|
18 | import traceback | |
20 |
|
19 | |||
21 | from .i18n import _ |
|
20 | from .i18n import _ | |
@@ -304,8 +303,8 b' def _protectio(ui):' | |||||
304 | ui.flush() |
|
303 | ui.flush() | |
305 | newfiles = [] |
|
304 | newfiles = [] | |
306 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
305 | nullfd = os.open(os.devnull, os.O_RDWR) | |
307 |
for f, sysf, mode in [(ui.fin, |
|
306 | for f, sysf, mode in [(ui.fin, util.stdin, 'rb'), | |
308 |
(ui.fout, |
|
307 | (ui.fout, util.stdout, 'wb')]: | |
309 | if f is sysf: |
|
308 | if f is sysf: | |
310 | newfd = os.dup(f.fileno()) |
|
309 | newfd = os.dup(f.fileno()) | |
311 | os.dup2(nullfd, f.fileno()) |
|
310 | os.dup2(nullfd, f.fileno()) |
@@ -97,7 +97,7 b' def dispatch(req):' | |||||
97 | elif req.ui: |
|
97 | elif req.ui: | |
98 | ferr = req.ui.ferr |
|
98 | ferr = req.ui.ferr | |
99 | else: |
|
99 | else: | |
100 |
ferr = |
|
100 | ferr = util.stderr | |
101 |
|
101 | |||
102 | try: |
|
102 | try: | |
103 | if not req.ui: |
|
103 | if not req.ui: |
@@ -11,7 +11,6 b'' | |||||
11 | from __future__ import absolute_import |
|
11 | from __future__ import absolute_import | |
12 |
|
12 | |||
13 | import os |
|
13 | import os | |
14 | import sys |
|
|||
15 |
|
14 | |||
16 | from .. import ( |
|
15 | from .. import ( | |
17 | util, |
|
16 | util, | |
@@ -22,8 +21,8 b' from . import (' | |||||
22 | ) |
|
21 | ) | |
23 |
|
22 | |||
24 | def launch(application): |
|
23 | def launch(application): | |
25 |
util.setbinary( |
|
24 | util.setbinary(util.stdin) | |
26 |
util.setbinary( |
|
25 | util.setbinary(util.stdout) | |
27 |
|
26 | |||
28 | environ = dict(os.environ.iteritems()) |
|
27 | environ = dict(os.environ.iteritems()) | |
29 | environ.setdefault('PATH_INFO', '') |
|
28 | environ.setdefault('PATH_INFO', '') | |
@@ -33,12 +32,12 b' def launch(application):' | |||||
33 | if environ['PATH_INFO'].startswith(scriptname): |
|
32 | if environ['PATH_INFO'].startswith(scriptname): | |
34 | environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):] |
|
33 | environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):] | |
35 |
|
34 | |||
36 |
stdin = |
|
35 | stdin = util.stdin | |
37 | if environ.get('HTTP_EXPECT', '').lower() == '100-continue': |
|
36 | if environ.get('HTTP_EXPECT', '').lower() == '100-continue': | |
38 |
stdin = common.continuereader(stdin, |
|
37 | stdin = common.continuereader(stdin, util.stdout.write) | |
39 |
|
38 | |||
40 | environ['wsgi.input'] = stdin |
|
39 | environ['wsgi.input'] = stdin | |
41 |
environ['wsgi.errors'] = |
|
40 | environ['wsgi.errors'] = util.stderr | |
42 | environ['wsgi.version'] = (1, 0) |
|
41 | environ['wsgi.version'] = (1, 0) | |
43 | environ['wsgi.multithread'] = False |
|
42 | environ['wsgi.multithread'] = False | |
44 | environ['wsgi.multiprocess'] = True |
|
43 | environ['wsgi.multiprocess'] = True | |
@@ -51,7 +50,7 b' def launch(application):' | |||||
51 |
|
50 | |||
52 | headers_set = [] |
|
51 | headers_set = [] | |
53 | headers_sent = [] |
|
52 | headers_sent = [] | |
54 |
out = |
|
53 | out = util.stdout | |
55 |
|
54 | |||
56 | def write(data): |
|
55 | def write(data): | |
57 | if not headers_set: |
|
56 | if not headers_set: |
@@ -209,11 +209,11 b' def runhooks(ui, repo, name, hooks, thro' | |||||
209 | for hname, cmd in hooks: |
|
209 | for hname, cmd in hooks: | |
210 | if oldstdout == -1 and _redirect: |
|
210 | if oldstdout == -1 and _redirect: | |
211 | try: |
|
211 | try: | |
212 |
stdoutno = |
|
212 | stdoutno = util.stdout.fileno() | |
213 |
stderrno = |
|
213 | stderrno = util.stderr.fileno() | |
214 | # temporarily redirect stdout to stderr, if possible |
|
214 | # temporarily redirect stdout to stderr, if possible | |
215 | if stdoutno >= 0 and stderrno >= 0: |
|
215 | if stdoutno >= 0 and stderrno >= 0: | |
216 |
|
|
216 | util.stdout.flush() | |
217 | oldstdout = os.dup(stdoutno) |
|
217 | oldstdout = os.dup(stdoutno) | |
218 | os.dup2(stderrno, stdoutno) |
|
218 | os.dup2(stderrno, stdoutno) | |
219 | except (OSError, AttributeError): |
|
219 | except (OSError, AttributeError): | |
@@ -255,10 +255,10 b' def runhooks(ui, repo, name, hooks, thro' | |||||
255 | # The stderr is fully buffered on Windows when connected to a pipe. |
|
255 | # The stderr is fully buffered on Windows when connected to a pipe. | |
256 | # A forcible flush is required to make small stderr data in the |
|
256 | # A forcible flush is required to make small stderr data in the | |
257 | # remote side available to the client immediately. |
|
257 | # remote side available to the client immediately. | |
258 |
|
|
258 | util.stderr.flush() | |
259 | finally: |
|
259 | finally: | |
260 | if _redirect and oldstdout >= 0: |
|
260 | if _redirect and oldstdout >= 0: | |
261 |
|
|
261 | util.stdout.flush() # write hook output to stderr fd | |
262 | os.dup2(oldstdout, stdoutno) |
|
262 | os.dup2(oldstdout, stdoutno) | |
263 | os.close(oldstdout) |
|
263 | os.close(oldstdout) | |
264 |
|
264 |
@@ -660,14 +660,14 b' def continuity(url):' | |||||
660 | def comp(N, url): |
|
660 | def comp(N, url): | |
661 | print(' making %i connections to:\n %s' % (N, url)) |
|
661 | print(' making %i connections to:\n %s' % (N, url)) | |
662 |
|
662 | |||
663 |
|
|
663 | util.stdout.write(' first using the normal urllib handlers') | |
664 | # first use normal opener |
|
664 | # first use normal opener | |
665 | opener = urlreq.buildopener() |
|
665 | opener = urlreq.buildopener() | |
666 | urlreq.installopener(opener) |
|
666 | urlreq.installopener(opener) | |
667 | t1 = fetch(N, url) |
|
667 | t1 = fetch(N, url) | |
668 | print(' TIME: %.3f s' % t1) |
|
668 | print(' TIME: %.3f s' % t1) | |
669 |
|
669 | |||
670 |
|
|
670 | util.stdout.write(' now using the keepalive handler ') | |
671 | # now install the keepalive handler and try again |
|
671 | # now install the keepalive handler and try again | |
672 | opener = urlreq.buildopener(HTTPHandler()) |
|
672 | opener = urlreq.buildopener(HTTPHandler()) | |
673 | urlreq.installopener(opener) |
|
673 | urlreq.installopener(opener) | |
@@ -712,11 +712,11 b' def test_timeout(url):' | |||||
712 | i = 20 |
|
712 | i = 20 | |
713 | print(" waiting %i seconds for the server to close the connection" % i) |
|
713 | print(" waiting %i seconds for the server to close the connection" % i) | |
714 | while i > 0: |
|
714 | while i > 0: | |
715 |
|
|
715 | util.stdout.write('\r %2i' % i) | |
716 |
|
|
716 | util.stdout.flush() | |
717 | time.sleep(1) |
|
717 | time.sleep(1) | |
718 | i -= 1 |
|
718 | i -= 1 | |
719 |
|
|
719 | util.stderr.write('\r') | |
720 |
|
720 | |||
721 | print(" fetching the file a second time") |
|
721 | print(" fetching the file a second time") | |
722 | fo = urlreq.urlopen(url) |
|
722 | fo = urlreq.urlopen(url) |
@@ -130,9 +130,9 b' class ui(object):' | |||||
130 |
|
130 | |||
131 | self.httppasswordmgrdb = src.httppasswordmgrdb |
|
131 | self.httppasswordmgrdb = src.httppasswordmgrdb | |
132 | else: |
|
132 | else: | |
133 |
self.fout = |
|
133 | self.fout = util.stdout | |
134 |
self.ferr = |
|
134 | self.ferr = util.stderr | |
135 |
self.fin = |
|
135 | self.fin = util.stdin | |
136 |
|
136 | |||
137 | # shared read-only environment |
|
137 | # shared read-only environment | |
138 | self.environ = os.environ |
|
138 | self.environ = os.environ |
@@ -986,7 +986,7 b' def system(cmd, environ=None, cwd=None, ' | |||||
986 | if environ is None: |
|
986 | if environ is None: | |
987 | environ = {} |
|
987 | environ = {} | |
988 | try: |
|
988 | try: | |
989 |
|
|
989 | stdout.flush() | |
990 | except Exception: |
|
990 | except Exception: | |
991 | pass |
|
991 | pass | |
992 | def py2shell(val): |
|
992 | def py2shell(val): | |
@@ -2759,9 +2759,9 b' def timed(func):' | |||||
2759 | finally: |
|
2759 | finally: | |
2760 | elapsed = time.time() - start |
|
2760 | elapsed = time.time() - start | |
2761 | _timenesting[0] -= indent |
|
2761 | _timenesting[0] -= indent | |
2762 |
|
|
2762 | stderr.write('%s%s: %s\n' % | |
2763 |
|
|
2763 | (' ' * _timenesting[0], func.__name__, | |
2764 |
|
|
2764 | timecount(elapsed))) | |
2765 | return wrapper |
|
2765 | return wrapper | |
2766 |
|
2766 | |||
2767 | _sizeunits = (('m', 2**20), ('k', 2**10), ('g', 2**30), |
|
2767 | _sizeunits = (('m', 2**20), ('k', 2**10), ('g', 2**30), | |
@@ -2826,7 +2826,7 b" def getstackframes(skip=0, line=' %-*s i" | |||||
2826 | else: |
|
2826 | else: | |
2827 | yield line % (fnmax, fnln, func) |
|
2827 | yield line % (fnmax, fnln, func) | |
2828 |
|
2828 | |||
2829 |
def debugstacktrace(msg='stacktrace', skip=0, f= |
|
2829 | def debugstacktrace(msg='stacktrace', skip=0, f=stderr, otherf=stdout): | |
2830 | '''Writes a message to f (stderr) with a nicely formatted stacktrace. |
|
2830 | '''Writes a message to f (stderr) with a nicely formatted stacktrace. | |
2831 | Skips the 'skip' last entries. By default it will flush stdout first. |
|
2831 | Skips the 'skip' last entries. By default it will flush stdout first. | |
2832 | It can be used everywhere and intentionally does not require an ui object. |
|
2832 | It can be used everywhere and intentionally does not require an ui object. |
@@ -10,7 +10,6 b' from __future__ import absolute_import' | |||||
10 | import hashlib |
|
10 | import hashlib | |
11 | import itertools |
|
11 | import itertools | |
12 | import os |
|
12 | import os | |
13 | import sys |
|
|||
14 | import tempfile |
|
13 | import tempfile | |
15 |
|
14 | |||
16 | from .i18n import _ |
|
15 | from .i18n import _ | |
@@ -575,8 +574,8 b' def options(cmd, keys, others):' | |||||
575 | opts[k] = others[k] |
|
574 | opts[k] = others[k] | |
576 | del others[k] |
|
575 | del others[k] | |
577 | if others: |
|
576 | if others: | |
578 |
|
|
577 | util.stderr.write("warning: %s ignored unexpected arguments %s\n" | |
579 | % (cmd, ",".join(others))) |
|
578 | % (cmd, ",".join(others))) | |
580 | return opts |
|
579 | return opts | |
581 |
|
580 | |||
582 | def bundle1allowed(repo, action): |
|
581 | def bundle1allowed(repo, action): | |
@@ -907,11 +906,11 b' def unbundle(repo, proto, heads):' | |||||
907 | try: |
|
906 | try: | |
908 | raise |
|
907 | raise | |
909 | except error.Abort: |
|
908 | except error.Abort: | |
910 |
# The old code we moved used |
|
909 | # The old code we moved used util.stderr directly. | |
911 | # We did not change it to minimise code change. |
|
910 | # We did not change it to minimise code change. | |
912 | # This need to be moved to something proper. |
|
911 | # This need to be moved to something proper. | |
913 | # Feel free to do it. |
|
912 | # Feel free to do it. | |
914 |
|
|
913 | util.stderr.write("abort: %s\n" % exc) | |
915 | return pushres(0) |
|
914 | return pushres(0) | |
916 | except error.PushRaced: |
|
915 | except error.PushRaced: | |
917 | return pusherr(str(exc)) |
|
916 | return pusherr(str(exc)) |
General Comments 0
You need to be logged in to leave comments.
Login now