changeset 3386:8770b4870e22

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.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Thu, 12 Oct 2006 20:45:25 -0300
parents 1106e00e6847
children bb9852b3bf06
files mercurial/sshrepo.py tests/test-ssh.out
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/sshrepo.py	Thu Oct 12 16:34:32 2006 -0700
+++ b/mercurial/sshrepo.py	Thu Oct 12 20:45:25 2006 -0300
@@ -18,7 +18,7 @@
 
         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 @@
             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 @@
             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 @@
             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 @@
         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 @@
         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 @@
             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 @@
             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 @@
     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 @@
     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
--- a/tests/test-ssh.out	Thu Oct 12 16:34:32 2006 -0700
+++ b/tests/test-ssh.out	Thu Oct 12 20:45:25 2006 -0300
@@ -1,7 +1,7 @@
 # creating 'remote'
 # repo not found error
+remote: abort: repository nonexistent not found!
 abort: no suitable response from remote hg!
-remote: abort: repository nonexistent not found!
 # clone remote via stream
 streaming all changes
 XXX files to transfer, XXX bytes of data