comparison mercurial/windows.py @ 39644:3b421154d2ca

py3: fix str vs bytes in enough places to run `hg version` on Windows I don't have Visual Studio 2015 at home, but this now works with a handful of extensions (blackbox, extdiff, patchbomb, phabricator and rebase, but not evolve): $ HGMODULEPOLICY=py py -3 ../hg version Enabling the evolve extension causes the usual "failed to import ..." line, but then print this before the usual version output: ('commit', '[b'debugancestor', b'debugapplystreamclonebundle', ..., b'verify', b'version']') ... where the elided part seems to be every command and alias known.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 13 Sep 2018 22:07:00 -0400
parents 47ac5d93d708
children 255d1885c7f8
comparison
equal deleted inserted replaced
39643:47ac5d93d708 39644:3b421154d2ca
387 >>> shellquote(br'C:\\Users\\xyz/abc') 387 >>> shellquote(br'C:\\Users\\xyz/abc')
388 '"C:\\\\Users\\\\xyz/abc"' 388 '"C:\\\\Users\\\\xyz/abc"'
389 """ 389 """
390 global _quotere 390 global _quotere
391 if _quotere is None: 391 if _quotere is None:
392 _quotere = re.compile(r'(\\*)("|\\$)') 392 _quotere = re.compile(br'(\\*)("|\\$)')
393 global _needsshellquote 393 global _needsshellquote
394 if _needsshellquote is None: 394 if _needsshellquote is None:
395 # ":" is also treated as "safe character", because it is used as a part 395 # ":" is also treated as "safe character", because it is used as a part
396 # of path name on Windows. "\" is also part of a path name, but isn't 396 # of path name on Windows. "\" is also part of a path name, but isn't
397 # safe because shlex.split() (kind of) treats it as an escape char and 397 # safe because shlex.split() (kind of) treats it as an escape char and
398 # drops it. It will leave the next character, even if it is another 398 # drops it. It will leave the next character, even if it is another
399 # "\". 399 # "\".
400 _needsshellquote = re.compile(r'[^a-zA-Z0-9._:/-]').search 400 _needsshellquote = re.compile(br'[^a-zA-Z0-9._:/-]').search
401 if s and not _needsshellquote(s) and not _quotere.search(s): 401 if s and not _needsshellquote(s) and not _quotere.search(s):
402 # "s" shouldn't have to be quoted 402 # "s" shouldn't have to be quoted
403 return s 403 return s
404 return '"%s"' % _quotere.sub(r'\1\1\\\2', s) 404 return b'"%s"' % _quotere.sub(br'\1\1\\\2', s)
405 405
406 def _unquote(s): 406 def _unquote(s):
407 if s.startswith(b'"') and s.endswith(b'"'): 407 if s.startswith(b'"') and s.endswith(b'"'):
408 return s[1:-1] 408 return s[1:-1]
409 return s 409 return s