Add portable shell-quoting function; teach mq to use it.
authorBrendan Cully <brendan@kublai.com>
Sat, 05 Aug 2006 15:23:26 -0700
changeset 2786 f4d916351366
parent 2785 58a679745b38
child 2787 8ec1b1f0a5f7
Add portable shell-quoting function; teach mq to use it.
hgext/mq.py
mercurial/util.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -272,8 +272,8 @@ class queue:
         patchfile: file name of patch'''
         try:
             pp = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
-            f = os.popen("%s -d '%s' -p1 --no-backup-if-mismatch < '%s'" %
-                         (pp, repo.root, patchfile))
+            f = os.popen("%s -d %s -p1 --no-backup-if-mismatch < %s" %
+                         (pp, util.shellquote(repo.root), util.shellquote(patchfile)))
         except:
             self.ui.warn("patch failed, unable to continue (try -v)\n")
             return (None, [], False)
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -611,6 +611,9 @@ if os.name == 'nt':
     def samestat(s1, s2):
         return False
 
+    def shellquote(s):
+        return '"%s"' % s.replace('"', '\\"')
+
     def explain_exit(code):
         return _("exited with status %d") % code, code
 
@@ -700,6 +703,9 @@ else:
             else:
                 raise
 
+    def shellquote(s):
+        return "'%s'" % s.replace("'", "'\\''")
+
     def testpid(pid):
         '''return False if pid dead, True if running or not sure'''
         try: