ssh: add capability detection at startup
authorMatt Mackall <mpm@selenic.com>
Fri, 09 Jun 2006 18:03:35 -0500
changeset 2421 a1cfe679192c
parent 2420 144280f1578f
child 2423 f328e8aeff8b
ssh: add capability detection at startup Because older servers don't return any output for unknown commands, it's tricky to add new commands. The approach is this: we add a "hello" command that reports any interesting capabilities (and other things that might be of interest in the future). To detect whether this new command is supported, we issue both it and our startup detection command ("between") at the beginning of a connection.
mercurial/sshrepo.py
--- a/mercurial/sshrepo.py	Fri Jun 09 17:48:14 2006 -0500
+++ b/mercurial/sshrepo.py	Fri Jun 09 18:03:35 2006 -0500
@@ -37,6 +37,7 @@
         self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
 
         # skip any noise generated by remote shell
+        self.do_cmd("hello")
         r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
         lines = ["", "dummy"]
         max_noise = 500
@@ -54,6 +55,13 @@
                 ui.debug(_("remote: "), l1)
             raise hg.RepoError(_("no response from remote hg"))
 
+        self.capabilities = ()
+        lines.reverse()
+        for l in lines:
+            if l.startswith("capabilities:"):
+                self.capabilities = l[:-1].split(":")[1].split()
+                break
+
     def readerr(self):
         while 1:
             size = util.fstat(self.pipee).st_size