diff mercurial/windows.py @ 36445:0cb09c322647

util: factor out shellsplit() function It turned out to be more than the simple posix=True|False flag, so let's introduce a platform function. I also made it py3 ready.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 21 Feb 2018 22:20:27 +0900
parents c4caf530b1c7
children 0e8b76644e20
line wrap: on
line diff
--- a/mercurial/windows.py	Fri Feb 23 23:09:58 2018 +0900
+++ b/mercurial/windows.py	Wed Feb 21 22:20:27 2018 +0900
@@ -296,6 +296,15 @@
         return s
     return '"%s"' % _quotere.sub(r'\1\1\\\2', s)
 
+def _unquote(s):
+    if s.startswith(b'"') and s.endswith(b'"'):
+        return s[1:-1]
+    return s
+
+def shellsplit(s):
+    """Parse a command string in cmd.exe way (best-effort)"""
+    return pycompat.maplist(_unquote, pycompat.shlexsplit(s, posix=False))
+
 def quotecommand(cmd):
     """Build a command string suitable for os.popen* calls."""
     if sys.version_info < (2, 7, 1):