Show More
@@ -402,7 +402,8 b' class commandline(object):' | |||||
402 |
|
402 | |||
403 | def _run(self, cmd, *args, **kwargs): |
|
403 | def _run(self, cmd, *args, **kwargs): | |
404 | def popen(cmdline): |
|
404 | def popen(cmdline): | |
405 | p = subprocess.Popen(cmdline, shell=True, bufsize=-1, |
|
405 | p = subprocess.Popen(pycompat.rapply(procutil.tonativestr, cmdline), | |
|
406 | shell=True, bufsize=-1, | |||
406 | close_fds=procutil.closefds, |
|
407 | close_fds=procutil.closefds, | |
407 | stdout=subprocess.PIPE) |
|
408 | stdout=subprocess.PIPE) | |
408 | return p |
|
409 | return p |
@@ -17,6 +17,7 b' from mercurial.i18n import _' | |||||
17 | from mercurial import ( |
|
17 | from mercurial import ( | |
18 | encoding, |
|
18 | encoding, | |
19 | error, |
|
19 | error, | |
|
20 | pycompat, | |||
20 | ) |
|
21 | ) | |
21 | from mercurial.utils import ( |
|
22 | from mercurial.utils import ( | |
22 | dateutil, |
|
23 | dateutil, | |
@@ -201,7 +202,7 b' class gnuarch_source(common.converter_so' | |||||
201 | cmdline += ['>', os.devnull, '2>', os.devnull] |
|
202 | cmdline += ['>', os.devnull, '2>', os.devnull] | |
202 | cmdline = procutil.quotecommand(' '.join(cmdline)) |
|
203 | cmdline = procutil.quotecommand(' '.join(cmdline)) | |
203 | self.ui.debug(cmdline, '\n') |
|
204 | self.ui.debug(cmdline, '\n') | |
204 | return os.system(cmdline) |
|
205 | return os.system(pycompat.rapply(procutil.tonativestr, cmdline)) | |
205 |
|
206 | |||
206 | def _update(self, rev): |
|
207 | def _update(self, rev): | |
207 | self.ui.debug('applying revision %s...\n' % rev) |
|
208 | self.ui.debug('applying revision %s...\n' % rev) |
@@ -49,6 +49,9 b' from __future__ import absolute_import' | |||||
49 |
|
49 | |||
50 | import os |
|
50 | import os | |
51 | from mercurial.i18n import _ |
|
51 | from mercurial.i18n import _ | |
|
52 | from mercurial.utils import ( | |||
|
53 | procutil, | |||
|
54 | ) | |||
52 | from mercurial import ( |
|
55 | from mercurial import ( | |
53 | error, |
|
56 | error, | |
54 | httpconnection, |
|
57 | httpconnection, | |
@@ -83,7 +86,7 b' def auth_getkey(self, params):' | |||||
83 | if 'user=' not in params: |
|
86 | if 'user=' not in params: | |
84 | params = '%s user?' % params |
|
87 | params = '%s user?' % params | |
85 | params = '%s !password?' % params |
|
88 | params = '%s !password?' % params | |
86 | os.system("%s -g '%s'" % (_executable, params)) |
|
89 | os.system(procutil.tonativestr("%s -g '%s'" % (_executable, params))) | |
87 |
|
90 | |||
88 | def auth_getuserpasswd(self, getkey, params): |
|
91 | def auth_getuserpasswd(self, getkey, params): | |
89 | params = 'proto=pass %s' % params |
|
92 | params = 'proto=pass %s' % params |
@@ -58,6 +58,10 b' from mercurial.i18n import _' | |||||
58 | from mercurial.node import nullrev |
|
58 | from mercurial.node import nullrev | |
59 | from mercurial.node import wdirrev |
|
59 | from mercurial.node import wdirrev | |
60 |
|
60 | |||
|
61 | from mercurial.utils import ( | |||
|
62 | procutil, | |||
|
63 | ) | |||
|
64 | ||||
61 | from mercurial import ( |
|
65 | from mercurial import ( | |
62 | cmdutil, |
|
66 | cmdutil, | |
63 | context, |
|
67 | context, | |
@@ -448,9 +452,9 b' def fixfile(ui, opts, fixers, fixctx, pa' | |||||
448 | continue |
|
452 | continue | |
449 | ui.debug('subprocess: %s\n' % (command,)) |
|
453 | ui.debug('subprocess: %s\n' % (command,)) | |
450 | proc = subprocess.Popen( |
|
454 | proc = subprocess.Popen( | |
451 | command, |
|
455 | pycompat.rapply(procutil.tonativestr, command), | |
452 | shell=True, |
|
456 | shell=True, | |
453 | cwd='/', |
|
457 | cwd=procutil.tonativestr(b'/'), | |
454 | stdin=subprocess.PIPE, |
|
458 | stdin=subprocess.PIPE, | |
455 | stdout=subprocess.PIPE, |
|
459 | stdout=subprocess.PIPE, | |
456 | stderr=subprocess.PIPE) |
|
460 | stderr=subprocess.PIPE) |
@@ -48,6 +48,14 b' try:' | |||||
48 | except ImportError: |
|
48 | except ImportError: | |
49 | from . import pybser as bser |
|
49 | from . import pybser as bser | |
50 |
|
50 | |||
|
51 | from mercurial.utils import ( | |||
|
52 | procutil, | |||
|
53 | ) | |||
|
54 | ||||
|
55 | from mercurial import ( | |||
|
56 | pycompat, | |||
|
57 | ) | |||
|
58 | ||||
51 | from . import ( |
|
59 | from . import ( | |
52 | capabilities, |
|
60 | capabilities, | |
53 | compat, |
|
61 | compat, | |
@@ -580,7 +588,8 b' class CLIProcessTransport(Transport):' | |||||
580 | '--no-pretty', |
|
588 | '--no-pretty', | |
581 | '-j', |
|
589 | '-j', | |
582 | ] |
|
590 | ] | |
583 |
self.proc = subprocess.Popen( |
|
591 | self.proc = subprocess.Popen(pycompat.rapply(procutil.tonativestr, | |
|
592 | args), | |||
584 | stdin=subprocess.PIPE, |
|
593 | stdin=subprocess.PIPE, | |
585 | stdout=subprocess.PIPE) |
|
594 | stdout=subprocess.PIPE) | |
586 | return self.proc |
|
595 | return self.proc | |
@@ -822,7 +831,8 b' class client(object):' | |||||
822 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
|
831 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW | |
823 | args['startupinfo'] = startupinfo |
|
832 | args['startupinfo'] = startupinfo | |
824 |
|
833 | |||
825 |
p = subprocess.Popen( |
|
834 | p = subprocess.Popen(pycompat.rapply(procutil.tonativestr, cmd), | |
|
835 | **args) | |||
826 |
|
836 | |||
827 | except OSError as e: |
|
837 | except OSError as e: | |
828 | raise WatchmanError('"watchman" executable not in PATH (%s)' % e) |
|
838 | raise WatchmanError('"watchman" executable not in PATH (%s)' % e) |
@@ -1182,5 +1182,6 b' def _asyncsavemetadata(root, nodes):' | |||||
1182 | cmdline = [util.hgexecutable(), 'debugfillinfinitepushmetadata', |
|
1182 | cmdline = [util.hgexecutable(), 'debugfillinfinitepushmetadata', | |
1183 | '-R', root] + nodesargs |
|
1183 | '-R', root] + nodesargs | |
1184 | # Process will run in background. We don't care about the return code |
|
1184 | # Process will run in background. We don't care about the return code | |
1185 | subprocess.Popen(cmdline, close_fds=True, shell=False, |
|
1185 | subprocess.Popen(pycompat.rapply(procutil.tonativestr, cmdline), | |
|
1186 | close_fds=True, shell=False, | |||
1186 | stdin=devnull, stdout=devnull, stderr=devnull) |
|
1187 | stdin=devnull, stdout=devnull, stderr=devnull) |
@@ -11,6 +11,13 b' import os' | |||||
11 | import subprocess |
|
11 | import subprocess | |
12 | import tempfile |
|
12 | import tempfile | |
13 |
|
13 | |||
|
14 | from mercurial import ( | |||
|
15 | pycompat, | |||
|
16 | ) | |||
|
17 | from mercurial.utils import ( | |||
|
18 | procutil, | |||
|
19 | ) | |||
|
20 | ||||
14 | NamedTemporaryFile = tempfile.NamedTemporaryFile |
|
21 | NamedTemporaryFile = tempfile.NamedTemporaryFile | |
15 |
|
22 | |||
16 | class BundleWriteException(Exception): |
|
23 | class BundleWriteException(Exception): | |
@@ -111,7 +118,8 b' class externalbundlestore(abstractbundle' | |||||
111 |
|
118 | |||
112 | def _call_binary(self, args): |
|
119 | def _call_binary(self, args): | |
113 | p = subprocess.Popen( |
|
120 | p = subprocess.Popen( | |
114 | args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
|
121 | pycompat.rapply(procutil.tonativestr, args), | |
|
122 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |||
115 | close_fds=True) |
|
123 | close_fds=True) | |
116 | stdout, stderr = p.communicate() |
|
124 | stdout, stderr = p.communicate() | |
117 | returncode = p.returncode |
|
125 | returncode = p.returncode |
@@ -44,6 +44,10 b' from mercurial import (' | |||||
44 | pycompat, |
|
44 | pycompat, | |
45 | ) |
|
45 | ) | |
46 |
|
46 | |||
|
47 | from mercurial.utils import ( | |||
|
48 | procutil, | |||
|
49 | ) | |||
|
50 | ||||
47 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
|
51 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | |
48 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
52 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | |
49 | # be specifying the version(s) of Mercurial they are tested with, or |
|
53 | # be specifying the version(s) of Mercurial they are tested with, or | |
@@ -62,7 +66,8 b' def uisetup(ui):' | |||||
62 | # we can't use close_fds *and* redirect stdin. I'm not sure that we |
|
66 | # we can't use close_fds *and* redirect stdin. I'm not sure that we | |
63 | # need to because the detached process has no console connection. |
|
67 | # need to because the detached process has no console connection. | |
64 | subprocess.Popen( |
|
68 | subprocess.Popen( | |
65 | script, shell=True, env=env, close_fds=True, |
|
69 | pycompat.rapply(procutil.tonativestr, script), | |
|
70 | shell=True, env=procutil.tonativeenv(env), close_fds=True, | |||
66 | creationflags=_creationflags) |
|
71 | creationflags=_creationflags) | |
67 | else: |
|
72 | else: | |
68 | def runshellcommand(script, env): |
|
73 | def runshellcommand(script, env): | |
@@ -82,7 +87,9 b' def uisetup(ui):' | |||||
82 | # connect stdin to devnull to make sure the subprocess can't |
|
87 | # connect stdin to devnull to make sure the subprocess can't | |
83 | # muck up that stream for mercurial. |
|
88 | # muck up that stream for mercurial. | |
84 | subprocess.Popen( |
|
89 | subprocess.Popen( | |
85 | script, shell=True, stdin=open(os.devnull, 'r'), env=env, |
|
90 | pycompat.rapply(procutil.tonativestr, script), | |
|
91 | shell=True, stdin=open(os.devnull, 'r'), | |||
|
92 | env=procutil.tonativeenv(env), | |||
86 | close_fds=True, **newsession) |
|
93 | close_fds=True, **newsession) | |
87 | finally: |
|
94 | finally: | |
88 | # mission accomplished, this child needs to exit and not |
|
95 | # mission accomplished, this child needs to exit and not |
@@ -3074,7 +3074,8 b' def debugwireproto(ui, repo, path=None, ' | |||||
3074 | '-R', repo.root, |
|
3074 | '-R', repo.root, | |
3075 | 'debugserve', '--sshstdio', |
|
3075 | 'debugserve', '--sshstdio', | |
3076 | ] |
|
3076 | ] | |
3077 | proc = subprocess.Popen(args, stdin=subprocess.PIPE, |
|
3077 | proc = subprocess.Popen(pycompat.rapply(procutil.tonativestr, args), | |
|
3078 | stdin=subprocess.PIPE, | |||
3078 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
|
3079 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |
3079 | bufsize=0) |
|
3080 | bufsize=0) | |
3080 |
|
3081 |
@@ -1339,9 +1339,11 b' def extdatasource(repo, source):' | |||||
1339 | if spec.startswith("shell:"): |
|
1339 | if spec.startswith("shell:"): | |
1340 | # external commands should be run relative to the repo root |
|
1340 | # external commands should be run relative to the repo root | |
1341 | cmd = spec[6:] |
|
1341 | cmd = spec[6:] | |
1342 | proc = subprocess.Popen(cmd, shell=True, bufsize=-1, |
|
1342 | proc = subprocess.Popen(pycompat.rapply(procutil.tonativestr, cmd), | |
|
1343 | shell=True, bufsize=-1, | |||
1343 | close_fds=procutil.closefds, |
|
1344 | close_fds=procutil.closefds, | |
1344 |
stdout=subprocess.PIPE, |
|
1345 | stdout=subprocess.PIPE, | |
|
1346 | cwd=procutil.tonativestr(repo.root)) | |||
1345 | src = proc.stdout |
|
1347 | src = proc.stdout | |
1346 | else: |
|
1348 | else: | |
1347 | # treat as a URL or file |
|
1349 | # treat as a URL or file |
@@ -951,9 +951,11 b' class svnsubrepo(abstractsubrepo):' | |||||
951 | env['LANG'] = lc_all |
|
951 | env['LANG'] = lc_all | |
952 | del env['LC_ALL'] |
|
952 | del env['LC_ALL'] | |
953 | env['LC_MESSAGES'] = 'C' |
|
953 | env['LC_MESSAGES'] = 'C' | |
954 |
p = subprocess.Popen( |
|
954 | p = subprocess.Popen(pycompat.rapply(procutil.tonativestr, cmd), | |
|
955 | bufsize=-1, close_fds=procutil.closefds, | |||
955 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
|
956 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |
956 |
|
|
957 | universal_newlines=True, | |
|
958 | env=procutil.tonativeenv(env), **extrakw) | |||
957 | stdout, stderr = p.communicate() |
|
959 | stdout, stderr = p.communicate() | |
958 | stderr = stderr.strip() |
|
960 | stderr = stderr.strip() | |
959 | if not failok: |
|
961 | if not failok: | |
@@ -1268,8 +1270,12 b' class gitsubrepo(abstractsubrepo):' | |||||
1268 | # insert the argument in the front, |
|
1270 | # insert the argument in the front, | |
1269 | # the end of git diff arguments is used for paths |
|
1271 | # the end of git diff arguments is used for paths | |
1270 | commands.insert(1, '--color') |
|
1272 | commands.insert(1, '--color') | |
1271 | p = subprocess.Popen([self._gitexecutable] + commands, bufsize=-1, |
|
1273 | p = subprocess.Popen(pycompat.rapply(procutil.tonativestr, | |
1272 | cwd=cwd, env=env, close_fds=procutil.closefds, |
|
1274 | [self._gitexecutable] + commands), | |
|
1275 | bufsize=-1, | |||
|
1276 | cwd=pycompat.rapply(procutil.tonativestr, cwd), | |||
|
1277 | env=procutil.tonativeenv(env), | |||
|
1278 | close_fds=procutil.closefds, | |||
1273 | stdout=subprocess.PIPE, stderr=errpipe) |
|
1279 | stdout=subprocess.PIPE, stderr=errpipe) | |
1274 | if stream: |
|
1280 | if stream: | |
1275 | return p.stdout, None |
|
1281 | return p.stdout, None |
@@ -120,13 +120,15 b" def popen(cmd, mode='rb', bufsize=-1):" | |||||
120 | raise error.ProgrammingError('unsupported mode: %r' % mode) |
|
120 | raise error.ProgrammingError('unsupported mode: %r' % mode) | |
121 |
|
121 | |||
122 | def _popenreader(cmd, bufsize): |
|
122 | def _popenreader(cmd, bufsize): | |
123 |
p = subprocess.Popen(quotecommand(cmd) |
|
123 | p = subprocess.Popen(tonativestr(quotecommand(cmd)), | |
|
124 | shell=True, bufsize=bufsize, | |||
124 | close_fds=closefds, |
|
125 | close_fds=closefds, | |
125 | stdout=subprocess.PIPE) |
|
126 | stdout=subprocess.PIPE) | |
126 | return _pfile(p, p.stdout) |
|
127 | return _pfile(p, p.stdout) | |
127 |
|
128 | |||
128 | def _popenwriter(cmd, bufsize): |
|
129 | def _popenwriter(cmd, bufsize): | |
129 |
p = subprocess.Popen(quotecommand(cmd) |
|
130 | p = subprocess.Popen(tonativestr(quotecommand(cmd)), | |
|
131 | shell=True, bufsize=bufsize, | |||
130 | close_fds=closefds, |
|
132 | close_fds=closefds, | |
131 | stdin=subprocess.PIPE) |
|
133 | stdin=subprocess.PIPE) | |
132 | return _pfile(p, p.stdin) |
|
134 | return _pfile(p, p.stdin) | |
@@ -135,10 +137,11 b' def popen2(cmd, env=None):' | |||||
135 | # Setting bufsize to -1 lets the system decide the buffer size. |
|
137 | # Setting bufsize to -1 lets the system decide the buffer size. | |
136 | # The default for bufsize is 0, meaning unbuffered. This leads to |
|
138 | # The default for bufsize is 0, meaning unbuffered. This leads to | |
137 | # poor performance on Mac OS X: http://bugs.python.org/issue4194 |
|
139 | # poor performance on Mac OS X: http://bugs.python.org/issue4194 | |
138 | p = subprocess.Popen(cmd, shell=True, bufsize=-1, |
|
140 | p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), | |
|
141 | shell=True, bufsize=-1, | |||
139 | close_fds=closefds, |
|
142 | close_fds=closefds, | |
140 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
|
143 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, | |
141 | env=env) |
|
144 | env=tonativeenv(env)) | |
142 | return p.stdin, p.stdout |
|
145 | return p.stdin, p.stdout | |
143 |
|
146 | |||
144 | def popen3(cmd, env=None): |
|
147 | def popen3(cmd, env=None): | |
@@ -146,16 +149,18 b' def popen3(cmd, env=None):' | |||||
146 | return stdin, stdout, stderr |
|
149 | return stdin, stdout, stderr | |
147 |
|
150 | |||
148 | def popen4(cmd, env=None, bufsize=-1): |
|
151 | def popen4(cmd, env=None, bufsize=-1): | |
149 | p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, |
|
152 | p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), | |
|
153 | shell=True, bufsize=bufsize, | |||
150 | close_fds=closefds, |
|
154 | close_fds=closefds, | |
151 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
|
155 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, | |
152 | stderr=subprocess.PIPE, |
|
156 | stderr=subprocess.PIPE, | |
153 | env=env) |
|
157 | env=tonativeenv(env)) | |
154 | return p.stdin, p.stdout, p.stderr, p |
|
158 | return p.stdin, p.stdout, p.stderr, p | |
155 |
|
159 | |||
156 | def pipefilter(s, cmd): |
|
160 | def pipefilter(s, cmd): | |
157 | '''filter string S through command CMD, returning its output''' |
|
161 | '''filter string S through command CMD, returning its output''' | |
158 | p = subprocess.Popen(cmd, shell=True, close_fds=closefds, |
|
162 | p = subprocess.Popen(pycompat.rapply(tonativestr, cmd), | |
|
163 | shell=True, close_fds=closefds, | |||
159 | stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
|
164 | stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
160 | pout, perr = p.communicate(s) |
|
165 | pout, perr = p.communicate(s) | |
161 | return pout |
|
166 | return pout | |
@@ -346,11 +351,16 b' def system(cmd, environ=None, cwd=None, ' | |||||
346 | cmd = quotecommand(cmd) |
|
351 | cmd = quotecommand(cmd) | |
347 | env = shellenviron(environ) |
|
352 | env = shellenviron(environ) | |
348 | if out is None or isstdout(out): |
|
353 | if out is None or isstdout(out): | |
349 | rc = subprocess.call(cmd, shell=True, close_fds=closefds, |
|
354 | rc = subprocess.call(pycompat.rapply(tonativestr, cmd), | |
350 |
|
|
355 | shell=True, close_fds=closefds, | |
|
356 | env=tonativeenv(env), | |||
|
357 | cwd=pycompat.rapply(tonativestr, cwd)) | |||
351 | else: |
|
358 | else: | |
352 | proc = subprocess.Popen(cmd, shell=True, close_fds=closefds, |
|
359 | proc = subprocess.Popen(pycompat.rapply(tonativestr, cmd), | |
353 |
|
|
360 | shell=True, close_fds=closefds, | |
|
361 | env=tonativeenv(env), | |||
|
362 | cwd=pycompat.rapply(tonativestr, cwd), | |||
|
363 | stdout=subprocess.PIPE, | |||
354 | stderr=subprocess.STDOUT) |
|
364 | stderr=subprocess.STDOUT) | |
355 | for line in iter(proc.stdout.readline, ''): |
|
365 | for line in iter(proc.stdout.readline, ''): | |
356 | out.write(line) |
|
366 | out.write(line) |
General Comments 0
You need to be logged in to leave comments.
Login now