subrepo: use subprocess.Popen without the shell
As well as simplifying the code, this makes subprocess calls about 25% faster.
Tested on a couple linux boxes.
python -mtimeit -s'import subprocess' 'subprocess.Popen(
"git version", shell=True, stdout=subprocess.PIPE).wait()'
python -mtimeit -s'import subprocess' 'subprocess.Popen(
["git","version"], stdout=subprocess.PIPE).wait()'
--- a/mercurial/subrepo.py Thu Dec 09 16:52:14 2010 -0500
+++ b/mercurial/subrepo.py Thu Dec 09 16:52:14 2010 -0500
@@ -484,13 +484,10 @@
def _svncommand(self, commands, filename=''):
path = os.path.join(self._ctx._repo.origroot, self._path, filename)
cmd = ['svn'] + commands + [path]
- cmd = [util.shellquote(arg) for arg in cmd]
- cmd = util.quotecommand(' '.join(cmd))
env = dict(os.environ)
# Avoid localized output, preserve current locale for everything else.
env['LC_MESSAGES'] = 'C'
- p = subprocess.Popen(cmd, shell=True, bufsize=-1,
- close_fds=util.closefds,
+ p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, env=env)
stdout, stderr = p.communicate()
@@ -626,12 +623,8 @@
The methods tries to call the git command. versions previor to 1.6.0
are not supported and very probably fail.
"""
- cmd = ['git'] + commands
- cmd = [util.shellquote(arg) for arg in cmd]
- cmd = util.quotecommand(' '.join(cmd))
-
# print git's stderr, which is mostly progress and useful info
- p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=cwd, env=env,
+ p = subprocess.Popen(['git'] + commands, bufsize=-1, cwd=cwd, env=env,
close_fds=util.closefds,
stdout=subprocess.PIPE)
if stream: