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

login
register
mail settings
Submitter Matt Harbison
Date July 9, 2018, 3:27 p.m.
Message ID <b028d7427a3d87bed191.1531150064@Envy>
Download mbox | patch
Permalink /patch/32711/
State Accepted
Headers show

Comments

Matt Harbison - July 9, 2018, 3:27 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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.
Yuya Nishihara - July 10, 2018, 12:26 p.m.
On Mon, 09 Jul 2018 11:27:44 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@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

Queued the first two, thanks.

Patch

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: