diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -567,3 +567,16 @@ def statislink(st): def statisexec(st): '''check whether a stat result is an executable file''' return st and (st.st_mode & 0100 != 0) + +def readpipe(pipe): + """Read all available data from a pipe.""" + chunks = [] + while True: + size = os.fstat(pipe.fileno()).st_size + if not size: + break + + s = pipe.read(size) + if not s: + break + chunks.append(s) diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py --- a/mercurial/sshpeer.py +++ b/mercurial/sshpeer.py @@ -103,13 +103,8 @@ class sshpeer(wireproto.wirepeer): return self._caps def readerr(self): - while True: - size = util.fstat(self.pipee).st_size - if size == 0: - break - s = self.pipee.read(size) - if not s: - break + s = util.readpipe(self.pipee) + if s: for l in s.splitlines(): self.ui.status(_("remote: "), l, '\n') diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -53,6 +53,7 @@ pconvert = platform.pconvert popen = platform.popen posixfile = platform.posixfile quotecommand = platform.quotecommand +readpipe = platform.readpipe rename = platform.rename samedevice = platform.samedevice samefile = platform.samefile diff --git a/mercurial/windows.py b/mercurial/windows.py --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -336,3 +336,18 @@ def statislink(st): def statisexec(st): '''check whether a stat result is an executable file''' return False + +def readpipe(pipe): + """Read all available data from a pipe.""" + chunks = [] + while True: + size = os.fstat(pipe.fileno()).st_size + if not size: + break + + s = pipe.read(size) + if not s: + break + chunks.append(s) + + return ''.join(chunks)