[PATCH 06 of 13 STABLE V4] icasefs: use util.normcase() instead of lower() or os.path.normcase in fspath

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Dec 16 06:27:14 CST 2011


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1324037380 -32400
# Branch stable
# Node ID 748694149821b3356563a7e12b51f22b1dfdf269
# Parent  38bc7e88a2b9a62d60913acc7c596322b34e5d68
icasefs: use util.normcase() instead of lower() or os.path.normcase in fspath

this also avoids lower()-ing on each path components by reuse the path
normcase()-ed at beginning of function.

diff -r 38bc7e88a2b9 -r 748694149821 mercurial/util.py
--- a/mercurial/util.py	Fri Dec 16 21:09:40 2011 +0900
+++ b/mercurial/util.py	Fri Dec 16 21:09:40 2011 +0900
@@ -618,7 +618,9 @@
     called, for case-sensitive filesystems (simply because it's expensive).
     '''
     # If name is absolute, make it relative
-    if name.lower().startswith(root.lower()):
+    name = normcase(name)
+    root = normcase(root)
+    if name.startswith(root):
         l = len(root)
         if name[l] == os.sep or name[l] == os.altsep:
             l = l + 1
@@ -633,7 +635,7 @@
     # Protect backslashes. This gets silly very quickly.
     seps.replace('\\','\\\\')
     pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps))
-    dir = os.path.normcase(os.path.normpath(root))
+    dir = os.path.normpath(root)
     result = []
     for part, sep in pattern.findall(name):
         if sep:
@@ -644,16 +646,15 @@
             _fspathcache[dir] = os.listdir(dir)
         contents = _fspathcache[dir]
 
-        lpart = part.lower()
         lenp = len(part)
         for n in contents:
-            if lenp == len(n) and n.lower() == lpart:
+            if lenp == len(n) and normcase(n) == part:
                 result.append(n)
                 break
         else:
             # Cannot happen, as the file exists!
             result.append(part)
-        dir = os.path.join(dir, lpart)
+        dir = os.path.join(dir, part)
 
     return ''.join(result)
 


More information about the Mercurial-devel mailing list