Mercurial > hg-stable
changeset 4087:587c6c652f82
Fix util.shellquote on windows.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Thu, 15 Feb 2007 05:38:00 -0200 |
parents | cc8a52229620 |
children | 18dcc22666a0 |
files | mercurial/util.py |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Thu Feb 15 05:18:23 2007 -0200 +++ b/mercurial/util.py Thu Feb 15 05:38:00 2007 -0200 @@ -798,8 +798,23 @@ def samestat(s1, s2): return False + # A sequence of backslashes is special iff it precedes a double quote: + # - if there's an even number of backslashes, the double quote is not + # quoted (i.e. it ends the quoted region) + # - if there's an odd number of backslashes, the double quote is quoted + # - in both cases, every pair of backslashes is unquoted into a single + # backslash + # (See http://msdn2.microsoft.com/en-us/library/a1y7w461.aspx ) + # So, to quote a string, we must surround it in double quotes, double + # the number of backslashes that preceed double quotes and add another + # backslash before every double quote (being careful with the double + # quote we've appended to the end) + _quotere = None def shellquote(s): - return '"%s"' % s.replace('"', '\\"') + global _quotere + if _quotere is None: + _quotere = re.compile(r'(\\*)("|\\$)') + return '"%s"' % _quotere.sub(r'\1\1\\\2', s) def explain_exit(code): return _("exited with status %d") % code, code