[PATCH 5 of 6 v2] run_tests: know how to match Windows //?/C:\Something paths

Kostia Balytskyi ikostia at fb.com
Tue Sep 19 12:57:49 EDT 2017


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1505837708 25200
#      Tue Sep 19 09:15:08 2017 -0700
# Node ID 29007a29700f107b7fd5bf139fa192f9528d6349
# Parent  59578c527e95704396e044444e77435cbab6a966
run_tests: know how to match Windows //?/C:\Something paths

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -964,7 +964,19 @@ class Test(unittest.TestCase):
 
     def _escapepath(self, p):
         if os.name == 'nt':
+            # Explanation of the clowntown below:
+            # We want to match NT prefix \\?\ (see MSDN on Windows File Names).
+            # In order to match a signle \ in re, we need to escape it with
+            # another \, thus re has to receive \\ for each \ we want to match.
+            # Also, to match ?, re has to receive \?. But since we're
+            # concatenating strings, we can't use r'', so we have to also
+            # python-string-escape everything. Therefore:
+            # Want to match  |  re must receive  |  python str must contain
+            #       /        |         //        |         ////
+            #       ?        |         /?        |         //?
+            #     //?/       |      /////?//     |    //////////?////
             return (
+                b'(\\\\\\\\\\?\\\\){0,1}' +
                 (b''.join(c.isalpha() and b'[%s%s]' % (c.lower(), c.upper()) or
                     c in b'/\\' and br'[/\\]' or c.isdigit() and c or b'\\' + c
                     for c in p))


More information about the Mercurial-devel mailing list