[PATCH 1 of 2 STABLE] util: concentrate quoting knowledge to windows.py quotecommand()

Steve Borho steve at borho.org
Wed Dec 22 13:40:18 CST 2010


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1293045900 21600
# Branch stable
# Node ID 6c9345f9edca6d7ea4b368b1845f5f6896b9d529
# Parent  f9d29777b4eb88e87c9dca68a55e396ab63d8898
util: concentrate quoting knowledge to windows.py quotecommand()

This fixes all callers of util.quotecommand() and place special knowledge
of the bugfix in 2.7.1 in a single platform specific place.

diff -r f9d29777b4eb -r 6c9345f9edca mercurial/util.py
--- a/mercurial/util.py	Mon Dec 20 15:26:36 2010 -0600
+++ b/mercurial/util.py	Wed Dec 22 13:25:00 2010 -0600
@@ -391,9 +391,7 @@
             return '1'
         return str(val)
     origcmd = cmd
-    if os.name == 'nt' and sys.version_info < (2, 7, 1):
-        # Python versions since 2.7.1 do this extra quoting themselves
-        cmd = '"%s"' % cmd
+    cmd = quotecommand(cmd)
     env = dict(os.environ)
     env.update((k, py2shell(v)) for k, v in environ.iteritems())
     env['HG'] = hgexecutable()
diff -r f9d29777b4eb -r 6c9345f9edca mercurial/windows.py
--- a/mercurial/windows.py	Mon Dec 20 15:26:36 2010 -0600
+++ b/mercurial/windows.py	Wed Dec 22 13:25:00 2010 -0600
@@ -160,9 +160,10 @@
 
 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 + '"'
+    if sys.version_info < (2, 7, 1):
+        # Python versions since 2.7.1 do this extra quoting themselves
+        return '"' + cmd + '"'
+    return cmd
 
 def popen(command, mode='r'):
     # Work around "popen spawned process may not write to stdout


More information about the Mercurial-devel mailing list