Mercurial > public > mercurial-scm > hg
comparison mercurial/windows.py @ 36415: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 |
comparison
equal
deleted
inserted
replaced
36414:44c4a38bf563 | 36415:0cb09c322647 |
---|---|
294 if s and not _needsshellquote(s) and not _quotere.search(s): | 294 if s and not _needsshellquote(s) and not _quotere.search(s): |
295 # "s" shouldn't have to be quoted | 295 # "s" shouldn't have to be quoted |
296 return s | 296 return s |
297 return '"%s"' % _quotere.sub(r'\1\1\\\2', s) | 297 return '"%s"' % _quotere.sub(r'\1\1\\\2', s) |
298 | 298 |
299 def _unquote(s): | |
300 if s.startswith(b'"') and s.endswith(b'"'): | |
301 return s[1:-1] | |
302 return s | |
303 | |
304 def shellsplit(s): | |
305 """Parse a command string in cmd.exe way (best-effort)""" | |
306 return pycompat.maplist(_unquote, pycompat.shlexsplit(s, posix=False)) | |
307 | |
299 def quotecommand(cmd): | 308 def quotecommand(cmd): |
300 """Build a command string suitable for os.popen* calls.""" | 309 """Build a command string suitable for os.popen* calls.""" |
301 if sys.version_info < (2, 7, 1): | 310 if sys.version_info < (2, 7, 1): |
302 # Python versions since 2.7.1 do this extra quoting themselves | 311 # Python versions since 2.7.1 do this extra quoting themselves |
303 return '"' + cmd + '"' | 312 return '"' + cmd + '"' |