[PATCH] Allow ssh.cmd, ssh.opts to be used in [ui]

Steve Borho steve at borho.org
Thu Sep 6 15:06:38 CDT 2007


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1189108606 18000
# Node ID f2eca1509bde4a3b1990781c07274ae6de2e3a0b
# Parent  f8c36b215281a7e8f3aaed632206d3627ee21e6e
Allow ssh.cmd, ssh.opts to be used in [ui]

Example .hgrc section:

[ui]
ssh.cmd = C:\Program Files\Mercurial\plink.exe
ssh.opts = -ssh -i \path\to\key

diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshrepo.py
@@ -27,16 +27,23 @@ class sshrepository(remoterepository):
         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")
+        sshcmd = self.ui.config("ui", "ssh.cmd")
+        if sshcmd:
+            sshopts = self.ui.config("ui", "ssh.opts")
+        else:
+            sshstr = self.ui.config("ui", "ssh", "ssh")
+            sshcmd = sshstr.split(' ', 1)[0]
+            sshopts = sshstr[len(sshcmd)+1:]
+        if sshopts:
+            args = sshopts + " " + args
+
         remotecmd = self.ui.config("ui", "remotecmd", "hg")
 
         if create:
-            cmd = '%s %s "%s init %s"'
-            cmd = cmd % (sshcmd, args, remotecmd, self.path)
-
-            ui.note('running %s\n' % cmd)
-            res = os.system(cmd)
-            if res != 0:
+            cmd = [sshcmd] + args.split() + [remotecmd, 'init', self.path]
+            ui.note('running %s\n' % ' '.join(cmd))
+            i, o = os.popen2(cmd, 'b')
+            if i.close():
                 self.raise_(repo.RepoError(_("could not create remote repo")))
 
         self.validate_repo(ui, sshcmd, args, remotecmd)
@@ -48,10 +55,10 @@ class sshrepository(remoterepository):
         # cleanup up previous run
         self.cleanup()
 
-        cmd = '%s %s "%s -R %s serve --stdio"'
-        cmd = cmd % (sshcmd, args, remotecmd, self.path)
-
-        ui.note('running %s\n' % cmd)
+        cmd = [sshcmd] + args.split() 
+        cmd = cmd + [remotecmd, '-R', self.path, 'serve', '--stdio']
+
+        ui.note('running %s\n' % ' '.join(cmd))
         self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
 
         # skip any noise generated by remote shell


More information about the Mercurial-devel mailing list