[PATCH] ssh: use shlex to parse command line

Steve Borho steve at borho.org
Fri Sep 7 12:32:32 CDT 2007


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1189185768 18000
# Node ID 8d00421f54e5ae492bbf1906a713394aee4f134c
# Parent  f8c36b215281a7e8f3aaed632206d3627ee21e6e
ssh: use shlex to parse command line
Works on linux and windows, but requires subprocess module introduced in python 2.4

diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshrepo.py
@@ -8,7 +8,7 @@ from node import *
 from node import *
 from remoterepo import *
 from i18n import _
-import repo, os, re, stat, util
+import repo, os, re, shlex, stat, subprocess, util
 
 class sshrepository(remoterepository):
     def __init__(self, ui, path, create=0):
@@ -35,8 +35,10 @@ class sshrepository(remoterepository):
             cmd = cmd % (sshcmd, args, remotecmd, self.path)
 
             ui.note('running %s\n' % cmd)
-            res = os.system(cmd)
-            if res != 0:
+            vargs = shlex.split(cmd)
+            path = util.find_exe(vargs[0], vargs[0])
+            ret = subprocess.Popen([path] + vargs[1:]).wait()
+            if ret != 0:
                 self.raise_(repo.RepoError(_("could not create remote repo")))
 
         self.validate_repo(ui, sshcmd, args, remotecmd)
@@ -52,7 +54,9 @@ class sshrepository(remoterepository):
         cmd = cmd % (sshcmd, args, remotecmd, self.path)
 
         ui.note('running %s\n' % cmd)
-        self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
+        p = subprocess.Popen(shlex.split(cmd), stdin=subprocess.PIPE,
+                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        (self.pipei, self.pipeo, self.pipee) = (p.stdout, p.stdin, p.stderr)
 
         # skip any noise generated by remote shell
         self.do_cmd("hello")


More information about the Mercurial-devel mailing list