[PATCH 1 of 4] windows: don't consider '$$' to be an escaped '$' when translating to cmd.exe

Matt Harbison mharbison72 at gmail.com
Mon Jul 9 15:27:44 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1531016036 14400
#      Sat Jul 07 22:13:56 2018 -0400
# Node ID b028d7427a3d87bed191b1b56c51f87c56b51d0e
# Parent  f068495a1c28358c22695545ed15a00b54da0d45
windows: don't consider '$$' to be an escaped '$' when translating to cmd.exe

This functionality was inherited from `os.path.expandvars()`.  But the point of
adding this translating code is to be able to write a portable hook, and bash
wouldn't replace '$$' with '$'.  Escaping with '\' works, and is portable.

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -269,9 +269,10 @@ def shelltocmdexe(path, env):
     >>> # Single quote prevents expansion, as does \$ escaping
     >>> shelltocmdexe(b"cmd '$var1 ${var2} %var3%' \$var1 \${var2} \\", e)
     "cmd '$var1 ${var2} %var3%' $var1 ${var2} \\"
-    >>> # $$ -> $, %% is not special, but can be the end and start of variables
+    >>> # $$ is not special. %% is not special either, but can be the end and
+    >>> # start of consecutive variables
     >>> shelltocmdexe(b"cmd $$ %% %var1%%var2%", e)
-    'cmd $ %% %var1%%var2%'
+    'cmd $$ %% %var1%%var2%'
     >>> # No double substitution
     >>> shelltocmdexe(b"$var1 %var1%", {b'var1': b'%var2%', b'var2': b'boom'})
     '%var1% %var1%'
@@ -306,11 +307,8 @@ def shelltocmdexe(path, env):
             else:
                 var = path[:index]
                 res += b'%' + var + b'%'
-        elif c == b'$':  # variable or '$$'
-            if path[index + 1:index + 2] == b'$':
-                res += c
-                index += 1
-            elif path[index + 1:index + 2] == b'{':
+        elif c == b'$':  # variable
+            if path[index + 1:index + 2] == b'{':
                 path = path[index + 2:]
                 pathlen = len(path)
                 try:


More information about the Mercurial-devel mailing list