Show More
@@ -61,6 +61,10 b' from . import (' | |||||
61 | util, |
|
61 | util, | |
62 | ) |
|
62 | ) | |
63 |
|
63 | |||
|
64 | from .utils import ( | |||
|
65 | procutil, | |||
|
66 | ) | |||
|
67 | ||||
64 | _log = commandserver.log |
|
68 | _log = commandserver.log | |
65 |
|
69 | |||
66 | def _hashlist(items): |
|
70 | def _hashlist(items): | |
@@ -200,7 +204,7 b' def _newchgui(srcui, csystem, attachio):' | |||||
200 | # these situations and will behave differently (write to stdout). |
|
204 | # these situations and will behave differently (write to stdout). | |
201 | if (out is not self.fout |
|
205 | if (out is not self.fout | |
202 | or not util.safehasattr(self.fout, 'fileno') |
|
206 | or not util.safehasattr(self.fout, 'fileno') | |
203 | or self.fout.fileno() != util.stdout.fileno()): |
|
207 | or self.fout.fileno() != procutil.stdout.fileno()): | |
204 | return util.system(cmd, environ=environ, cwd=cwd, out=out) |
|
208 | return util.system(cmd, environ=environ, cwd=cwd, out=out) | |
205 | self.flush() |
|
209 | self.flush() | |
206 | return self._csystem(cmd, util.shellenviron(environ), cwd) |
|
210 | return self._csystem(cmd, util.shellenviron(environ), cwd) |
@@ -29,6 +29,9 b' from . import (' | |||||
29 | pycompat, |
|
29 | pycompat, | |
30 | util, |
|
30 | util, | |
31 | ) |
|
31 | ) | |
|
32 | from .utils import ( | |||
|
33 | procutil, | |||
|
34 | ) | |||
32 |
|
35 | |||
33 | logfile = None |
|
36 | logfile = None | |
34 |
|
37 | |||
@@ -308,8 +311,8 b' def _protectio(ui):' | |||||
308 | ui.flush() |
|
311 | ui.flush() | |
309 | newfiles = [] |
|
312 | newfiles = [] | |
310 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
313 | nullfd = os.open(os.devnull, os.O_RDWR) | |
311 | for f, sysf, mode in [(ui.fin, util.stdin, r'rb'), |
|
314 | for f, sysf, mode in [(ui.fin, procutil.stdin, r'rb'), | |
312 | (ui.fout, util.stdout, r'wb')]: |
|
315 | (ui.fout, procutil.stdout, r'wb')]: | |
313 | if f is sysf: |
|
316 | if f is sysf: | |
314 | newfd = os.dup(f.fileno()) |
|
317 | newfd = os.dup(f.fileno()) | |
315 | os.dup2(nullfd, f.fileno()) |
|
318 | os.dup2(nullfd, f.fileno()) |
@@ -42,6 +42,7 b' from . import (' | |||||
42 | ) |
|
42 | ) | |
43 |
|
43 | |||
44 | from .utils import ( |
|
44 | from .utils import ( | |
|
45 | procutil, | |||
45 | stringutil, |
|
46 | stringutil, | |
46 | ) |
|
47 | ) | |
47 |
|
48 | |||
@@ -127,8 +128,8 b' if pycompat.ispy3:' | |||||
127 | pass |
|
128 | pass | |
128 | # Otherwise mark it as closed to silence "Exception ignored in" |
|
129 | # Otherwise mark it as closed to silence "Exception ignored in" | |
129 | # message emitted by the interpreter finalizer. Be careful to |
|
130 | # message emitted by the interpreter finalizer. Be careful to | |
130 |
# not close util.stdout, which may be a fdopen-ed file object |
|
131 | # not close procutil.stdout, which may be a fdopen-ed file object | |
131 | # its close() actually closes the underlying file descriptor. |
|
132 | # and its close() actually closes the underlying file descriptor. | |
132 | try: |
|
133 | try: | |
133 | fp.close() |
|
134 | fp.close() | |
134 | except IOError: |
|
135 | except IOError: | |
@@ -180,7 +181,7 b' def dispatch(req):' | |||||
180 | elif req.ui: |
|
181 | elif req.ui: | |
181 | ferr = req.ui.ferr |
|
182 | ferr = req.ui.ferr | |
182 | else: |
|
183 | else: | |
183 | ferr = util.stderr |
|
184 | ferr = procutil.stderr | |
184 |
|
185 | |||
185 | try: |
|
186 | try: | |
186 | if not req.ui: |
|
187 | if not req.ui: |
@@ -15,13 +15,17 b' from .. import (' | |||||
15 | util, |
|
15 | util, | |
16 | ) |
|
16 | ) | |
17 |
|
17 | |||
|
18 | from ..utils import ( | |||
|
19 | procutil, | |||
|
20 | ) | |||
|
21 | ||||
18 | from . import ( |
|
22 | from . import ( | |
19 | common, |
|
23 | common, | |
20 | ) |
|
24 | ) | |
21 |
|
25 | |||
22 | def launch(application): |
|
26 | def launch(application): | |
23 | util.setbinary(util.stdin) |
|
27 | util.setbinary(procutil.stdin) | |
24 | util.setbinary(util.stdout) |
|
28 | util.setbinary(procutil.stdout) | |
25 |
|
29 | |||
26 | environ = dict(encoding.environ.iteritems()) |
|
30 | environ = dict(encoding.environ.iteritems()) | |
27 | environ.setdefault(r'PATH_INFO', '') |
|
31 | environ.setdefault(r'PATH_INFO', '') | |
@@ -31,12 +35,12 b' def launch(application):' | |||||
31 | if environ[r'PATH_INFO'].startswith(scriptname): |
|
35 | if environ[r'PATH_INFO'].startswith(scriptname): | |
32 | environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname):] |
|
36 | environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname):] | |
33 |
|
37 | |||
34 | stdin = util.stdin |
|
38 | stdin = procutil.stdin | |
35 | if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue': |
|
39 | if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue': | |
36 | stdin = common.continuereader(stdin, util.stdout.write) |
|
40 | stdin = common.continuereader(stdin, procutil.stdout.write) | |
37 |
|
41 | |||
38 | environ[r'wsgi.input'] = stdin |
|
42 | environ[r'wsgi.input'] = stdin | |
39 | environ[r'wsgi.errors'] = util.stderr |
|
43 | environ[r'wsgi.errors'] = procutil.stderr | |
40 | environ[r'wsgi.version'] = (1, 0) |
|
44 | environ[r'wsgi.version'] = (1, 0) | |
41 | environ[r'wsgi.multithread'] = False |
|
45 | environ[r'wsgi.multithread'] = False | |
42 | environ[r'wsgi.multiprocess'] = True |
|
46 | environ[r'wsgi.multiprocess'] = True | |
@@ -49,7 +53,7 b' def launch(application):' | |||||
49 |
|
53 | |||
50 | headers_set = [] |
|
54 | headers_set = [] | |
51 | headers_sent = [] |
|
55 | headers_sent = [] | |
52 | out = util.stdout |
|
56 | out = procutil.stdout | |
53 |
|
57 | |||
54 | def write(data): |
|
58 | def write(data): | |
55 | if not headers_set: |
|
59 | if not headers_set: |
@@ -19,6 +19,9 b' from . import (' | |||||
19 | pycompat, |
|
19 | pycompat, | |
20 | util, |
|
20 | util, | |
21 | ) |
|
21 | ) | |
|
22 | from .utils import ( | |||
|
23 | procutil, | |||
|
24 | ) | |||
22 |
|
25 | |||
23 | def _pythonhook(ui, repo, htype, hname, funcname, args, throw): |
|
26 | def _pythonhook(ui, repo, htype, hname, funcname, args, throw): | |
24 | '''call python hook. hook is callable object, looked up as |
|
27 | '''call python hook. hook is callable object, looked up as | |
@@ -222,11 +225,11 b' def runhooks(ui, repo, htype, hooks, thr' | |||||
222 | for hname, cmd in hooks: |
|
225 | for hname, cmd in hooks: | |
223 | if oldstdout == -1 and _redirect: |
|
226 | if oldstdout == -1 and _redirect: | |
224 | try: |
|
227 | try: | |
225 | stdoutno = util.stdout.fileno() |
|
228 | stdoutno = procutil.stdout.fileno() | |
226 | stderrno = util.stderr.fileno() |
|
229 | stderrno = procutil.stderr.fileno() | |
227 | # temporarily redirect stdout to stderr, if possible |
|
230 | # temporarily redirect stdout to stderr, if possible | |
228 | if stdoutno >= 0 and stderrno >= 0: |
|
231 | if stdoutno >= 0 and stderrno >= 0: | |
229 | util.stdout.flush() |
|
232 | procutil.stdout.flush() | |
230 | oldstdout = os.dup(stdoutno) |
|
233 | oldstdout = os.dup(stdoutno) | |
231 | os.dup2(stderrno, stdoutno) |
|
234 | os.dup2(stderrno, stdoutno) | |
232 | except (OSError, AttributeError): |
|
235 | except (OSError, AttributeError): | |
@@ -269,10 +272,10 b' def runhooks(ui, repo, htype, hooks, thr' | |||||
269 | # The stderr is fully buffered on Windows when connected to a pipe. |
|
272 | # The stderr is fully buffered on Windows when connected to a pipe. | |
270 | # A forcible flush is required to make small stderr data in the |
|
273 | # A forcible flush is required to make small stderr data in the | |
271 | # remote side available to the client immediately. |
|
274 | # remote side available to the client immediately. | |
272 | util.stderr.flush() |
|
275 | procutil.stderr.flush() | |
273 |
|
276 | |||
274 | if _redirect and oldstdout >= 0: |
|
277 | if _redirect and oldstdout >= 0: | |
275 | util.stdout.flush() # write hook output to stderr fd |
|
278 | procutil.stdout.flush() # write hook output to stderr fd | |
276 | os.dup2(oldstdout, stdoutno) |
|
279 | os.dup2(oldstdout, stdoutno) | |
277 | os.close(oldstdout) |
|
280 | os.close(oldstdout) | |
278 |
|
281 |
@@ -97,6 +97,9 b' from . import (' | |||||
97 | urllibcompat, |
|
97 | urllibcompat, | |
98 | util, |
|
98 | util, | |
99 | ) |
|
99 | ) | |
|
100 | from .utils import ( | |||
|
101 | procutil, | |||
|
102 | ) | |||
100 |
|
103 | |||
101 | httplib = util.httplib |
|
104 | httplib = util.httplib | |
102 | urlerr = util.urlerr |
|
105 | urlerr = util.urlerr | |
@@ -635,14 +638,14 b' def continuity(url):' | |||||
635 | def comp(N, url): |
|
638 | def comp(N, url): | |
636 | print(' making %i connections to:\n %s' % (N, url)) |
|
639 | print(' making %i connections to:\n %s' % (N, url)) | |
637 |
|
640 | |||
638 | util.stdout.write(' first using the normal urllib handlers') |
|
641 | procutil.stdout.write(' first using the normal urllib handlers') | |
639 | # first use normal opener |
|
642 | # first use normal opener | |
640 | opener = urlreq.buildopener() |
|
643 | opener = urlreq.buildopener() | |
641 | urlreq.installopener(opener) |
|
644 | urlreq.installopener(opener) | |
642 | t1 = fetch(N, url) |
|
645 | t1 = fetch(N, url) | |
643 | print(' TIME: %.3f s' % t1) |
|
646 | print(' TIME: %.3f s' % t1) | |
644 |
|
647 | |||
645 | util.stdout.write(' now using the keepalive handler ') |
|
648 | procutil.stdout.write(' now using the keepalive handler ') | |
646 | # now install the keepalive handler and try again |
|
649 | # now install the keepalive handler and try again | |
647 | opener = urlreq.buildopener(HTTPHandler()) |
|
650 | opener = urlreq.buildopener(HTTPHandler()) | |
648 | urlreq.installopener(opener) |
|
651 | urlreq.installopener(opener) | |
@@ -687,11 +690,11 b' def test_timeout(url):' | |||||
687 | i = 20 |
|
690 | i = 20 | |
688 | print(" waiting %i seconds for the server to close the connection" % i) |
|
691 | print(" waiting %i seconds for the server to close the connection" % i) | |
689 | while i > 0: |
|
692 | while i > 0: | |
690 | util.stdout.write('\r %2i' % i) |
|
693 | procutil.stdout.write('\r %2i' % i) | |
691 | util.stdout.flush() |
|
694 | procutil.stdout.flush() | |
692 | time.sleep(1) |
|
695 | time.sleep(1) | |
693 | i -= 1 |
|
696 | i -= 1 | |
694 | util.stderr.write('\r') |
|
697 | procutil.stderr.write('\r') | |
695 |
|
698 | |||
696 | print(" fetching the file a second time") |
|
699 | print(" fetching the file a second time") | |
697 | fo = urlreq.urlopen(url) |
|
700 | fo = urlreq.urlopen(url) |
@@ -22,6 +22,10 b' from . import (' | |||||
22 | util, |
|
22 | util, | |
23 | ) |
|
23 | ) | |
24 |
|
24 | |||
|
25 | from .utils import ( | |||
|
26 | procutil, | |||
|
27 | ) | |||
|
28 | ||||
25 | def runservice(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
|
29 | def runservice(opts, parentfn=None, initfn=None, runfn=None, logfile=None, | |
26 | runargs=None, appendpid=False): |
|
30 | runargs=None, appendpid=False): | |
27 | '''Run a command as a service.''' |
|
31 | '''Run a command as a service.''' | |
@@ -87,8 +91,8 b' def runservice(opts, parentfn=None, init' | |||||
87 | raise error.Abort(_('invalid value for --daemon-postexec: %s') |
|
91 | raise error.Abort(_('invalid value for --daemon-postexec: %s') | |
88 | % inst) |
|
92 | % inst) | |
89 | util.hidewindow() |
|
93 | util.hidewindow() | |
90 | util.stdout.flush() |
|
94 | procutil.stdout.flush() | |
91 | util.stderr.flush() |
|
95 | procutil.stderr.flush() | |
92 |
|
96 | |||
93 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
97 | nullfd = os.open(os.devnull, os.O_RDWR) | |
94 | logfilefd = nullfd |
|
98 | logfilefd = nullfd |
@@ -39,6 +39,7 b' from . import (' | |||||
39 | ) |
|
39 | ) | |
40 | from .utils import ( |
|
40 | from .utils import ( | |
41 | dateutil, |
|
41 | dateutil, | |
|
42 | procutil, | |||
42 | stringutil, |
|
43 | stringutil, | |
43 | ) |
|
44 | ) | |
44 |
|
45 | |||
@@ -250,9 +251,9 b' class ui(object):' | |||||
250 | self.httppasswordmgrdb = src.httppasswordmgrdb |
|
251 | self.httppasswordmgrdb = src.httppasswordmgrdb | |
251 | self._blockedtimes = src._blockedtimes |
|
252 | self._blockedtimes = src._blockedtimes | |
252 | else: |
|
253 | else: | |
253 | self.fout = util.stdout |
|
254 | self.fout = procutil.stdout | |
254 | self.ferr = util.stderr |
|
255 | self.ferr = procutil.stderr | |
255 | self.fin = util.stdin |
|
256 | self.fin = procutil.stdin | |
256 | self.pageractive = False |
|
257 | self.pageractive = False | |
257 | self._disablepager = False |
|
258 | self._disablepager = False | |
258 | self._tweaked = False |
|
259 | self._tweaked = False | |
@@ -1099,7 +1100,7 b' class ui(object):' | |||||
1099 | pager = subprocess.Popen( |
|
1100 | pager = subprocess.Popen( | |
1100 | command, shell=shell, bufsize=-1, |
|
1101 | command, shell=shell, bufsize=-1, | |
1101 | close_fds=util.closefds, stdin=subprocess.PIPE, |
|
1102 | close_fds=util.closefds, stdin=subprocess.PIPE, | |
1102 | stdout=util.stdout, stderr=util.stderr, |
|
1103 | stdout=procutil.stdout, stderr=procutil.stderr, | |
1103 | env=util.shellenviron(env)) |
|
1104 | env=util.shellenviron(env)) | |
1104 | except OSError as e: |
|
1105 | except OSError as e: | |
1105 | if e.errno == errno.ENOENT and not shell: |
|
1106 | if e.errno == errno.ENOENT and not shell: | |
@@ -1109,20 +1110,20 b' class ui(object):' | |||||
1109 | raise |
|
1110 | raise | |
1110 |
|
1111 | |||
1111 | # back up original file descriptors |
|
1112 | # back up original file descriptors | |
1112 | stdoutfd = os.dup(util.stdout.fileno()) |
|
1113 | stdoutfd = os.dup(procutil.stdout.fileno()) | |
1113 | stderrfd = os.dup(util.stderr.fileno()) |
|
1114 | stderrfd = os.dup(procutil.stderr.fileno()) | |
1114 |
|
1115 | |||
1115 | os.dup2(pager.stdin.fileno(), util.stdout.fileno()) |
|
1116 | os.dup2(pager.stdin.fileno(), procutil.stdout.fileno()) | |
1116 | if self._isatty(util.stderr): |
|
1117 | if self._isatty(procutil.stderr): | |
1117 | os.dup2(pager.stdin.fileno(), util.stderr.fileno()) |
|
1118 | os.dup2(pager.stdin.fileno(), procutil.stderr.fileno()) | |
1118 |
|
1119 | |||
1119 | @self.atexit |
|
1120 | @self.atexit | |
1120 | def killpager(): |
|
1121 | def killpager(): | |
1121 | if util.safehasattr(signal, "SIGINT"): |
|
1122 | if util.safehasattr(signal, "SIGINT"): | |
1122 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
|
1123 | signal.signal(signal.SIGINT, signal.SIG_IGN) | |
1123 | # restore original fds, closing pager.stdin copies in the process |
|
1124 | # restore original fds, closing pager.stdin copies in the process | |
1124 | os.dup2(stdoutfd, util.stdout.fileno()) |
|
1125 | os.dup2(stdoutfd, procutil.stdout.fileno()) | |
1125 | os.dup2(stderrfd, util.stderr.fileno()) |
|
1126 | os.dup2(stderrfd, procutil.stderr.fileno()) | |
1126 | pager.stdin.close() |
|
1127 | pager.stdin.close() | |
1127 | pager.wait() |
|
1128 | pager.wait() | |
1128 |
|
1129 |
@@ -35,6 +35,7 b' from . import (' | |||||
35 | ) |
|
35 | ) | |
36 |
|
36 | |||
37 | from .utils import ( |
|
37 | from .utils import ( | |
|
38 | procutil, | |||
38 | stringutil, |
|
39 | stringutil, | |
39 | ) |
|
40 | ) | |
40 |
|
41 | |||
@@ -519,8 +520,8 b' def options(cmd, keys, others):' | |||||
519 | opts[k] = others[k] |
|
520 | opts[k] = others[k] | |
520 | del others[k] |
|
521 | del others[k] | |
521 | if others: |
|
522 | if others: | |
522 | util.stderr.write("warning: %s ignored unexpected arguments %s\n" |
|
523 | procutil.stderr.write("warning: %s ignored unexpected arguments %s\n" | |
523 | % (cmd, ",".join(others))) |
|
524 | % (cmd, ",".join(others))) | |
524 | return opts |
|
525 | return opts | |
525 |
|
526 | |||
526 | def bundle1allowed(repo, action): |
|
527 | def bundle1allowed(repo, action): | |
@@ -1081,14 +1082,14 b' def unbundle(repo, proto, heads):' | |||||
1081 | try: |
|
1082 | try: | |
1082 | raise |
|
1083 | raise | |
1083 | except error.Abort: |
|
1084 | except error.Abort: | |
1084 | # The old code we moved used util.stderr directly. |
|
1085 | # The old code we moved used procutil.stderr directly. | |
1085 | # We did not change it to minimise code change. |
|
1086 | # We did not change it to minimise code change. | |
1086 | # This need to be moved to something proper. |
|
1087 | # This need to be moved to something proper. | |
1087 | # Feel free to do it. |
|
1088 | # Feel free to do it. | |
1088 | util.stderr.write("abort: %s\n" % exc) |
|
1089 | procutil.stderr.write("abort: %s\n" % exc) | |
1089 | if exc.hint is not None: |
|
1090 | if exc.hint is not None: | |
1090 | util.stderr.write("(%s)\n" % exc.hint) |
|
1091 | procutil.stderr.write("(%s)\n" % exc.hint) | |
1091 | util.stderr.flush() |
|
1092 | procutil.stderr.flush() | |
1092 | return pushres(0, output.getvalue() if output else '') |
|
1093 | return pushres(0, output.getvalue() if output else '') | |
1093 | except error.PushRaced: |
|
1094 | except error.PushRaced: | |
1094 | return pusherr(pycompat.bytestr(exc), |
|
1095 | return pusherr(pycompat.bytestr(exc), |
@@ -900,7 +900,9 b' This tests that translated help message ' | |||||
900 | > from __future__ import absolute_import |
|
900 | > from __future__ import absolute_import | |
901 | > from mercurial import ( |
|
901 | > from mercurial import ( | |
902 | > pycompat, |
|
902 | > pycompat, | |
903 | > util, |
|
903 | > ) | |
|
904 | > from mercurial.utils import ( | |||
|
905 | > procutil, | |||
904 | > ) |
|
906 | > ) | |
905 | > def escape(c): |
|
907 | > def escape(c): | |
906 | > o = ord(c) |
|
908 | > o = ord(c) | |
@@ -908,8 +910,9 b' This tests that translated help message ' | |||||
908 | > return c |
|
910 | > return c | |
909 | > else: |
|
911 | > else: | |
910 | > return br'\x%02x' % o # escape char setting MSB |
|
912 | > return br'\x%02x' % o # escape char setting MSB | |
911 | > for l in util.stdin: |
|
913 | > for l in procutil.stdin: | |
912 | > util.stdout.write(b''.join(escape(c) for c in pycompat.iterbytestr(l))) |
|
914 | > procutil.stdout.write( | |
|
915 | > b''.join(escape(c) for c in pycompat.iterbytestr(l))) | |||
913 | > EOF |
|
916 | > EOF | |
914 |
|
917 | |||
915 | $ hg commit -i --encoding cp932 2>&1 <<EOF | $PYTHON $TESTTMP/escape.py | grep '^y - ' |
|
918 | $ hg commit -i --encoding cp932 2>&1 <<EOF | $PYTHON $TESTTMP/escape.py | grep '^y - ' |
@@ -11,6 +11,10 b' from mercurial import (' | |||||
11 | util, |
|
11 | util, | |
12 | ) |
|
12 | ) | |
13 |
|
13 | |||
|
14 | from mercurial.utils import ( | |||
|
15 | procutil, | |||
|
16 | ) | |||
|
17 | ||||
14 | testtmp = encoding.environ[b'TESTTMP'] |
|
18 | testtmp = encoding.environ[b'TESTTMP'] | |
15 |
|
19 | |||
16 | # prepare hgrc files |
|
20 | # prepare hgrc files | |
@@ -41,9 +45,9 b' def printconfigs(env):' | |||||
41 | ui = uimod.ui.load() |
|
45 | ui = uimod.ui.load() | |
42 | for section, name, value in ui.walkconfig(): |
|
46 | for section, name, value in ui.walkconfig(): | |
43 | source = ui.configsource(section, name) |
|
47 | source = ui.configsource(section, name) | |
44 | util.stdout.write(b'%s.%s=%s # %s\n' |
|
48 | procutil.stdout.write(b'%s.%s=%s # %s\n' | |
45 | % (section, name, value, util.pconvert(source))) |
|
49 | % (section, name, value, util.pconvert(source))) | |
46 | util.stdout.write(b'\n') |
|
50 | procutil.stdout.write(b'\n') | |
47 |
|
51 | |||
48 | # environment variable overrides |
|
52 | # environment variable overrides | |
49 | printconfigs({}) |
|
53 | printconfigs({}) |
General Comments 0
You need to be logged in to leave comments.
Login now