--- a/hgext/convert/common.py Sat Sep 01 14:31:31 2012 +0200
+++ b/hgext/convert/common.py Sat Sep 01 12:48:08 2012 -0500
@@ -5,8 +5,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import base64, errno
-import os
+import base64, errno, subprocess, os
import cPickle as pickle
from mercurial import util
from mercurial.i18n import _
@@ -260,7 +259,7 @@
def postrun(self):
pass
- def _cmdline(self, cmd, closestdin, *args, **kwargs):
+ def _cmdline(self, cmd, *args, **kwargs):
cmdline = [self.command, cmd] + list(args)
for k, v in kwargs.iteritems():
if len(k) == 1:
@@ -277,19 +276,22 @@
cmdline = [util.shellquote(arg) for arg in cmdline]
if not self.ui.debugflag:
cmdline += ['2>', os.devnull]
- if closestdin:
- cmdline += ['<', os.devnull]
cmdline = ' '.join(cmdline)
return cmdline
def _run(self, cmd, *args, **kwargs):
- return self._dorun(util.popen, cmd, True, *args, **kwargs)
+ def popen(cmdline):
+ p = subprocess.Popen(cmdline, shell=True, bufsize=-1,
+ close_fds=util.closefds,
+ stdout=subprocess.PIPE)
+ return p
+ return self._dorun(popen, cmd, *args, **kwargs)
def _run2(self, cmd, *args, **kwargs):
- return self._dorun(util.popen2, cmd, False, *args, **kwargs)
+ return self._dorun(util.popen2, cmd, *args, **kwargs)
- def _dorun(self, openfunc, cmd, closestdin, *args, **kwargs):
- cmdline = self._cmdline(cmd, closestdin, *args, **kwargs)
+ def _dorun(self, openfunc, cmd, *args, **kwargs):
+ cmdline = self._cmdline(cmd, *args, **kwargs)
self.ui.debug('running: %s\n' % (cmdline,))
self.prerun()
try:
@@ -298,16 +300,17 @@
self.postrun()
def run(self, cmd, *args, **kwargs):
- fp = self._run(cmd, *args, **kwargs)
- output = fp.read()
+ p = self._run(cmd, *args, **kwargs)
+ output = p.communicate()[0]
self.ui.debug(output)
- return output, fp.close()
+ return output, p.returncode
def runlines(self, cmd, *args, **kwargs):
- fp = self._run(cmd, *args, **kwargs)
- output = fp.readlines()
+ p = self._run(cmd, *args, **kwargs)
+ output = p.stdout.readlines()
+ p.wait()
self.ui.debug(''.join(output))
- return output, fp.close()
+ return output, p.returncode
def checkexit(self, status, output=''):
if status:
@@ -345,8 +348,8 @@
# (and make happy Windows shells while doing this).
return argmax // 2 - 1
- def limit_arglist(self, arglist, cmd, closestdin, *args, **kwargs):
- cmdlen = len(self._cmdline(cmd, closestdin, *args, **kwargs))
+ def _limit_arglist(self, arglist, cmd, *args, **kwargs):
+ cmdlen = len(self._cmdline(cmd, *args, **kwargs))
limit = self.argmax - cmdlen
bytes = 0
fl = []
@@ -363,7 +366,7 @@
yield fl
def xargs(self, arglist, cmd, *args, **kwargs):
- for l in self.limit_arglist(arglist, cmd, True, *args, **kwargs):
+ for l in self._limit_arglist(arglist, cmd, *args, **kwargs):
self.run0(cmd, *(list(args) + l), **kwargs)
class mapfile(dict):