Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 13108:dcaad69cfd6a
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()'
author | Eric Eisner <ede@mit.edu> |
---|---|
date | Thu, 09 Dec 2010 16:52:14 -0500 |
parents | 3bc237b0eaea |
children | 53341289eaf8 |
comparison
equal
deleted
inserted
replaced
13107:3bc237b0eaea | 13108:dcaad69cfd6a |
---|---|
482 self._ui = ctx._repo.ui | 482 self._ui = ctx._repo.ui |
483 | 483 |
484 def _svncommand(self, commands, filename=''): | 484 def _svncommand(self, commands, filename=''): |
485 path = os.path.join(self._ctx._repo.origroot, self._path, filename) | 485 path = os.path.join(self._ctx._repo.origroot, self._path, filename) |
486 cmd = ['svn'] + commands + [path] | 486 cmd = ['svn'] + commands + [path] |
487 cmd = [util.shellquote(arg) for arg in cmd] | |
488 cmd = util.quotecommand(' '.join(cmd)) | |
489 env = dict(os.environ) | 487 env = dict(os.environ) |
490 # Avoid localized output, preserve current locale for everything else. | 488 # Avoid localized output, preserve current locale for everything else. |
491 env['LC_MESSAGES'] = 'C' | 489 env['LC_MESSAGES'] = 'C' |
492 p = subprocess.Popen(cmd, shell=True, bufsize=-1, | 490 p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds, |
493 close_fds=util.closefds, | |
494 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 491 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
495 universal_newlines=True, env=env) | 492 universal_newlines=True, env=env) |
496 stdout, stderr = p.communicate() | 493 stdout, stderr = p.communicate() |
497 stderr = stderr.strip() | 494 stderr = stderr.strip() |
498 if stderr: | 495 if stderr: |
624 """Calls the git command | 621 """Calls the git command |
625 | 622 |
626 The methods tries to call the git command. versions previor to 1.6.0 | 623 The methods tries to call the git command. versions previor to 1.6.0 |
627 are not supported and very probably fail. | 624 are not supported and very probably fail. |
628 """ | 625 """ |
629 cmd = ['git'] + commands | |
630 cmd = [util.shellquote(arg) for arg in cmd] | |
631 cmd = util.quotecommand(' '.join(cmd)) | |
632 | |
633 # print git's stderr, which is mostly progress and useful info | 626 # print git's stderr, which is mostly progress and useful info |
634 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=cwd, env=env, | 627 p = subprocess.Popen(['git'] + commands, bufsize=-1, cwd=cwd, env=env, |
635 close_fds=util.closefds, | 628 close_fds=util.closefds, |
636 stdout=subprocess.PIPE) | 629 stdout=subprocess.PIPE) |
637 if stream: | 630 if stream: |
638 return p.stdout, None | 631 return p.stdout, None |
639 | 632 |