[PATCH] Fix qpush fail on windows at drive root

Alexis S. L. Carvalho alexis at cecm.usp.br
Tue Feb 13 14:26:59 CST 2007


Thus spake Andrei Vermel:
> Here's hopefully a safer path tweak.

This will still mangle some filenames on Unix (but not as many...).  I
think the problem is in the util.shellquote function.  Can you test this
patch?

(I'm not even sure the URL below is the relevant bit of documentation
for this...)

regexps that deal with backslashes == not nice

Alexis


diff -r ef14fdb675da mercurial/util.py
--- a/mercurial/util.py	Tue Feb 13 10:02:07 2007 -0200
+++ b/mercurial/util.py	Tue Feb 13 18:23:24 2007 -0200
@@ -795,8 +795,20 @@ if os.name == 'nt':
     def samestat(s1, s2):
         return False
 
+    # - if a sequence of N backslashes precedes a double quote, 
+    #   turn it into a sequence of 2N backslashes
+    # - add a backslash before every double quote
+    # - if the string ends with a sequence of N backslashes,
+    #   turn it into a sequence of 2N backslashes
+    # - surround the result with double quotes
+    # See http://msdn2.microsoft.com/en-us/library/a1y7w461.aspx for
+    # details.
+    _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




More information about the Mercurial-devel mailing list