sshrepo: fix Windows command quoting
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 10 Sep 2007 23:34:33 +0200
changeset 5292 5a65d870871d
parent 5291 23651848d638
child 5293 32ec518ee3cb
child 5296 c8efd19e248c
sshrepo: fix Windows command quoting
mercurial/sshrepo.py
mercurial/util.py
--- a/mercurial/sshrepo.py	Mon Sep 10 23:36:01 2007 +0200
+++ b/mercurial/sshrepo.py	Mon Sep 10 23:34:33 2007 +0200
@@ -35,7 +35,7 @@
             cmd = cmd % (sshcmd, args, remotecmd, self.path)
 
             ui.note('running %s\n' % cmd)
-            res = os.system(cmd)
+            res = util.system(cmd)
             if res != 0:
                 self.raise_(hg.RepoError(_("could not create remote repo")))
 
@@ -51,6 +51,7 @@
         cmd = '%s %s "%s -R %s serve --stdio"'
         cmd = cmd % (sshcmd, args, remotecmd, self.path)
 
+        cmd = util.quotecommand(cmd)
         ui.note('running %s\n' % cmd)
         self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
 
--- a/mercurial/util.py	Mon Sep 10 23:36:01 2007 +0200
+++ b/mercurial/util.py	Mon Sep 10 23:34:33 2007 +0200
@@ -953,6 +953,12 @@
             _quotere = re.compile(r'(\\*)("|\\$)')
         return '"%s"' % _quotere.sub(r'\1\1\\\2', s)
 
+    def quotecommand(cmd):
+        """Build a command string suitable for os.popen* calls."""
+        # The extra quotes are needed because popen* runs the command
+        # through the current COMSPEC. cmd.exe suppress enclosing quotes.
+        return '"' + cmd + '"'
+
     def explain_exit(code):
         return _("exited with status %d") % code, code
 
@@ -1106,6 +1112,9 @@
         else:
             return "'%s'" % s.replace("'", "'\\''")
 
+    def quotecommand(cmd):
+        return cmd
+
     def testpid(pid):
         '''return False if pid dead, True if running or not sure'''
         if os.sys.platform == 'OpenVMS':