From patchwork Mon Jul 9 15:27:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 4] windows: don't consider '$$' to be an escaped '$' when translating to cmd.exe From: Matt Harbison X-Patchwork-Id: 32711 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Mon, 09 Jul 2018 11:27:44 -0400 # HG changeset patch # User Matt Harbison # 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: