portability fix for test-ssh

The __del__ method of sshrepo reads the stderr of the remote process
until EOF and prints it.

If an exception is raised, this method ends up being called:
- on Linux: after the "abort: ..." message is printed
- on OS X: before the "abort: ..." message is printed

This patch explicitly flushes the stderr of the remote process before
raising a RepoError.
This commit is contained in:
Alexis S. L. Carvalho 2006-10-12 20:45:25 -03:00
parent 2b2122f24a
commit 189bc7b5b8
2 changed files with 14 additions and 10 deletions

View File

@ -18,7 +18,7 @@ class sshrepository(remoterepository):
m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path)
if not m:
raise hg.RepoError(_("couldn't parse location %s") % path)
self.repoerror(_("couldn't parse location %s") % path)
self.user = m.group(2)
self.host = m.group(3)
@ -38,7 +38,7 @@ class sshrepository(remoterepository):
ui.note('running %s\n' % cmd)
res = os.system(cmd)
if res != 0:
raise hg.RepoError(_("could not create remote repo"))
self.repoerror(_("could not create remote repo"))
self.validate_repo(ui, sshcmd, args, remotecmd)
@ -70,7 +70,7 @@ class sshrepository(remoterepository):
lines.append(l)
max_noise -= 1
else:
raise hg.RepoError(_("no suitable response from remote hg"))
self.repoerror(_("no suitable response from remote hg"))
self.capabilities = ()
lines.reverse()
@ -87,6 +87,10 @@ class sshrepository(remoterepository):
if not l: break
self.ui.status(_("remote: "), l)
def repoerror(self, msg):
self.cleanup()
raise hg.RepoError(msg)
def cleanup(self):
try:
self.pipeo.close()
@ -117,7 +121,7 @@ class sshrepository(remoterepository):
try:
l = int(l)
except:
raise hg.RepoError(_("unexpected response '%s'") % l)
self.repoerror(_("unexpected response '%s'") % l)
return r.read(l)
def lock(self):
@ -132,7 +136,7 @@ class sshrepository(remoterepository):
try:
return map(bin, d[:-1].split(" "))
except:
raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
self.repoerror(_("unexpected response '%s'") % (d[:400] + "..."))
def branches(self, nodes):
n = " ".join(map(hex, nodes))
@ -141,7 +145,7 @@ class sshrepository(remoterepository):
br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
return br
except:
raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
self.repoerror(_("unexpected response '%s'") % (d[:400] + "..."))
def between(self, pairs):
n = "\n".join(["-".join(map(hex, p)) for p in pairs])
@ -150,7 +154,7 @@ class sshrepository(remoterepository):
p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
return p
except:
raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
self.repoerror(_("unexpected response '%s'") % (d[:400] + "..."))
def changegroup(self, nodes, kind):
n = " ".join(map(hex, nodes))
@ -159,7 +163,7 @@ class sshrepository(remoterepository):
def unbundle(self, cg, heads, source):
d = self.call("unbundle", heads=' '.join(map(hex, heads)))
if d:
raise hg.RepoError(_("push refused: %s") % d)
self.repoerror(_("push refused: %s") % d)
while 1:
d = cg.read(4096)
@ -185,7 +189,7 @@ class sshrepository(remoterepository):
def addchangegroup(self, cg, source, url):
d = self.call("addchangegroup")
if d:
raise hg.RepoError(_("push refused: %s") % d)
self.repoerror(_("push refused: %s") % d)
while 1:
d = cg.read(4096)
if not d: break

View File

@ -1,7 +1,7 @@
# creating 'remote'
# repo not found error
abort: no suitable response from remote hg!
remote: abort: repository nonexistent not found!
abort: no suitable response from remote hg!
# clone remote via stream
streaming all changes
XXX files to transfer, XXX bytes of data