[PATCH] win32: fix ssh://host:port when using Plink

Steve Borho steve at borho.org
Wed Dec 12 17:25:54 CST 2007


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1197501799 21600
# Node ID ca45b5ddb5eef27e6f8c3ccb03054d834d25bfbf
# Parent  6a8233c9abca666559fca0acd143356c2901bcd2
win32: fix ssh://host:port when using Plink

Moves ssh argument building to platform specific utils code.
The win32 version looks for plink in ssh command string and
uses '-P' in lieu of '-p' for specifying a port

diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshrepo.py
@@ -24,11 +24,10 @@ class sshrepository(remoterepository):
         self.port = m.group(5)
         self.path = m.group(7) or "."
 
-        args = self.user and ("%s@%s" % (self.user, self.host)) or self.host
-        args = self.port and ("%s -p %s") % (args, self.port) or args
-
         sshcmd = self.ui.config("ui", "ssh", "ssh")
         remotecmd = self.ui.config("ui", "remotecmd", "hg")
+
+        args = util.sshargs(sshcmd, self.host, self.user, self.port)
 
         if create:
             cmd = '%s %s "%s init %s"'
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -960,6 +960,12 @@ if os.name == 'nt':
             pf = pf[1:-1] # Remove the quotes
         return pf
 
+    def sshargs(sshcmd, host, user, port):
+        '''Build argument list for ssh or Plink'''
+        pflag = 'plink' in sshcmd.lower() and '-P' or '-p'
+        args = user and ("%s@%s" % (user, host)) or host
+        return port and ("%s %s %s" % (args, pflag, port)) or args
+
     def testpid(pid):
         '''return False if pid dead, True if running or not known'''
         return True
@@ -1101,6 +1107,11 @@ else:
            if pf.startswith("'") and pf.endswith("'") and " " in pf:
                 pf = pf[1:-1] # Remove the quotes
         return pf
+
+    def sshargs(sshcmd, host, user, port):
+        '''Build argument list for ssh'''
+        args = user and ("%s@%s" % (user, host)) or host
+        return port and ("%s -p %s" % (args, port)) or args
 
     def is_exec(f):
         """check whether a file is executable"""


More information about the Mercurial-devel mailing list