# HG changeset patch # User Eric Eisner # Date 1291931534 18000 # Node ID dcaad69cfd6a44e777e633b470b6448c385d3487 # Parent 3bc237b0eaeacdd7099efd3a8f84f191e6c63c43 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()' diff -r 3bc237b0eaea -r dcaad69cfd6a mercurial/subrepo.py --- 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: