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