Mercurial > hg
changeset 5481:003d1f174fe1
Fix Windows os.popen bug with interleaved stdout/stderr output
See python bug 1366 "popen spawned process may not write to stdout under windows" for more details.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 01 Nov 2007 12:05:14 +0100 |
parents | 81bef3c355c5 |
children | e5eedd74e70f 4d38e6970b8c |
files | hgext/convert/cvs.py hgext/convert/darcs.py hgext/convert/git.py mercurial/patch.py mercurial/util.py mercurial/version.py |
diffstat | 6 files changed, 19 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/cvs.py Tue Oct 30 16:54:25 2007 -0700 +++ b/hgext/convert/cvs.py Thu Nov 01 12:05:14 2007 +0100 @@ -43,14 +43,13 @@ cmd = '%s -d "1970/01/01 00:00:01" -d "%s"' % (cmd, self.rev) except util.Abort: raise util.Abort('revision %s is not a patchset number or date' % self.rev) - cmd += " 2>&1" d = os.getcwd() try: os.chdir(self.path) id = None state = 0 - for l in os.popen(cmd): + for l in util.popen(cmd): if state == 0: # header if l.startswith("PatchSet"): id = l[9:-2]
--- a/hgext/convert/darcs.py Tue Oct 30 16:54:25 2007 -0700 +++ b/hgext/convert/darcs.py Thu Nov 01 12:05:14 2007 +0100 @@ -65,9 +65,9 @@ cmdline += args cmdline = [util.shellquote(arg) for arg in cmdline] cmdline += ['<', util.nulldev] - cmdline = util.quotecommand(' '.join(cmdline)) + cmdline = ' '.join(cmdline) self.ui.debug(cmdline, '\n') - return os.popen(cmdline, 'r') + return util.popen(cmdline) def run(self, cmd, *args, **kwargs): fp = self._run(cmd, *args, **kwargs)
--- a/hgext/convert/git.py Tue Oct 30 16:54:25 2007 -0700 +++ b/hgext/convert/git.py Thu Nov 01 12:05:14 2007 +0100 @@ -14,7 +14,7 @@ prevgitdir = os.environ.get('GIT_DIR') os.environ['GIT_DIR'] = self.path try: - return os.popen(s) + return util.popen(s) finally: if prevgitdir is None: del os.environ['GIT_DIR'] @@ -22,7 +22,7 @@ os.environ['GIT_DIR'] = prevgitdir else: def gitcmd(self, s): - return os.popen('GIT_DIR=%s %s' % (self.path, s)) + return util.popen('GIT_DIR=%s %s' % (self.path, s)) def __init__(self, ui, path, rev=None): super(convert_git, self).__init__(ui, path, rev=rev) @@ -42,8 +42,7 @@ def catfile(self, rev, type): if rev == "0" * 40: raise IOError() - fh = self.gitcmd("git-cat-file %s %s 2>%s" % (type, rev, - util.nulldev)) + fh = self.gitcmd("git-cat-file %s %s" % (type, rev)) return fh.read() def getfile(self, name, rev): @@ -108,8 +107,7 @@ def gettags(self): tags = {} - fh = self.gitcmd('git-ls-remote --tags "%s" 2>%s' % (self.path, - util.nulldev)) + fh = self.gitcmd('git-ls-remote --tags "%s"' % self.path) prefix = 'refs/tags/' for line in fh: line = line.strip()
--- a/mercurial/patch.py Tue Oct 30 16:54:25 2007 -0700 +++ b/mercurial/patch.py Thu Nov 01 12:05:14 2007 +0100 @@ -249,7 +249,7 @@ fuzz = False if cwd: args.append('-d %s' % util.shellquote(cwd)) - fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, + fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, util.shellquote(patchname))) for line in fp:
--- a/mercurial/util.py Tue Oct 30 16:54:25 2007 -0700 +++ b/mercurial/util.py Thu Nov 01 12:05:14 2007 +0100 @@ -1011,6 +1011,13 @@ # through the current COMSPEC. cmd.exe suppress enclosing quotes. return '"' + cmd + '"' + def popen(command): + # Work around "popen spawned process may not write to stdout + # under windows" + # http://bugs.python.org/issue1366 + command += " 2> %s" % nulldev + return os.popen(quotecommand(command)) + def explain_exit(code): return _("exited with status %d") % code, code @@ -1168,6 +1175,9 @@ def quotecommand(cmd): return cmd + def popen(command): + return os.popen(command) + def testpid(pid): '''return False if pid dead, True if running or not sure''' if os.sys.platform == 'OpenVMS':
--- a/mercurial/version.py Tue Oct 30 16:54:25 2007 -0700 +++ b/mercurial/version.py Thu Nov 01 12:05:14 2007 +0100 @@ -50,7 +50,7 @@ """Store version information.""" global remembered_version if not version and os.path.isdir(".hg"): - f = os.popen("hg identify 2> %s" % util.nulldev) # use real hg installation + f = util.popen("hg identify") # use real hg installation ident = f.read()[:-1] if not f.close() and ident: ids = ident.split(' ', 1)