[PATCH 3 of 6] subrepo: use subprocess.Popen without the shell

Eric Eisner ede at MIT.EDU
Thu Dec 9 15:53:26 CST 2010


# HG changeset patch
# User Eric Eisner <ede at mit.edu>
# 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 --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -484,13 +484,10 @@ class svnsubrepo(abstractsubrepo):
     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 @@ class gitsubrepo(abstractsubrepo):
         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:


More information about the Mercurial-devel mailing list