mercurial/windows.py
changeset 38725 c382c19ce9bd
parent 38724 02b5b5c1bba8
child 39659 47ac5d93d708
equal deleted inserted replaced
38724:02b5b5c1bba8 38725:c382c19ce9bd
   274     >>> shelltocmdexe(b"cmd $$ %% %var1%%var2%", e)
   274     >>> shelltocmdexe(b"cmd $$ %% %var1%%var2%", e)
   275     'cmd $$ %% %var1%%var2%'
   275     'cmd $$ %% %var1%%var2%'
   276     >>> # No double substitution
   276     >>> # No double substitution
   277     >>> shelltocmdexe(b"$var1 %var1%", {b'var1': b'%var2%', b'var2': b'boom'})
   277     >>> shelltocmdexe(b"$var1 %var1%", {b'var1': b'%var2%', b'var2': b'boom'})
   278     '%var1% %var1%'
   278     '%var1% %var1%'
       
   279     >>> # Tilde expansion
       
   280     >>> shelltocmdexe(b"~/dir ~\dir2 ~tmpfile \~/", {})
       
   281     '%USERPROFILE%/dir %USERPROFILE%\\dir2 ~tmpfile ~/'
   279     """
   282     """
   280     if not any(c in path for c in b"$'"):
   283     if not any(c in path for c in b"$'~"):
   281         return path
   284         return path
   282 
   285 
   283     varchars = pycompat.sysbytes(string.ascii_letters + string.digits) + b'_-'
   286     varchars = pycompat.sysbytes(string.ascii_letters + string.digits) + b'_-'
   284 
   287 
   285     res = b''
   288     res = b''
   342                 else:
   345                 else:
   343                     res += b'$' + var
   346                     res += b'$' + var
   344 
   347 
   345                 if c != '':
   348                 if c != '':
   346                     index -= 1
   349                     index -= 1
   347         elif c == b'\\' and index + 1 < pathlen and path[index + 1] == b'$':
   350         elif (c == b'~' and index + 1 < pathlen
   348             # Skip '\', but only if it is escaping $
   351               and path[index + 1] in (b'\\', b'/')):
   349             res += b'$'
   352             res += "%USERPROFILE%"
       
   353         elif (c == b'\\' and index + 1 < pathlen
       
   354               and path[index + 1] in (b'$', b'~')):
       
   355             # Skip '\', but only if it is escaping $ or ~
       
   356             res += path[index + 1]
   350             index += 1
   357             index += 1
   351         else:
   358         else:
   352             res += c
   359             res += c
   353 
   360 
   354         index += 1
   361         index += 1