icasefs: use util.normcase() instead of lower() or os.path.normcase in fspath stable
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 16 Dec 2011 21:09:40 +0900
branchstable
changeset 15669 390bcd01775a
parent 15668 8e020155e76c
child 15670 d6c19cfa03ce
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.
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)