mercurial/util.py
branchstable
changeset 15669 390bcd01775a
parent 15667 eacfd851cb9e
child 15670 d6c19cfa03ce
equal deleted inserted replaced
15668:8e020155e76c 15669:390bcd01775a
   616     The name is either relative to root, or it is an absolute path starting
   616     The name is either relative to root, or it is an absolute path starting
   617     with root. Note that this function is unnecessary, and should not be
   617     with root. Note that this function is unnecessary, and should not be
   618     called, for case-sensitive filesystems (simply because it's expensive).
   618     called, for case-sensitive filesystems (simply because it's expensive).
   619     '''
   619     '''
   620     # If name is absolute, make it relative
   620     # If name is absolute, make it relative
   621     if name.lower().startswith(root.lower()):
   621     name = normcase(name)
       
   622     root = normcase(root)
       
   623     if name.startswith(root):
   622         l = len(root)
   624         l = len(root)
   623         if name[l] == os.sep or name[l] == os.altsep:
   625         if name[l] == os.sep or name[l] == os.altsep:
   624             l = l + 1
   626             l = l + 1
   625         name = name[l:]
   627         name = name[l:]
   626 
   628 
   631     if os.altsep:
   633     if os.altsep:
   632         seps = seps + os.altsep
   634         seps = seps + os.altsep
   633     # Protect backslashes. This gets silly very quickly.
   635     # Protect backslashes. This gets silly very quickly.
   634     seps.replace('\\','\\\\')
   636     seps.replace('\\','\\\\')
   635     pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps))
   637     pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps))
   636     dir = os.path.normcase(os.path.normpath(root))
   638     dir = os.path.normpath(root)
   637     result = []
   639     result = []
   638     for part, sep in pattern.findall(name):
   640     for part, sep in pattern.findall(name):
   639         if sep:
   641         if sep:
   640             result.append(sep)
   642             result.append(sep)
   641             continue
   643             continue
   642 
   644 
   643         if dir not in _fspathcache:
   645         if dir not in _fspathcache:
   644             _fspathcache[dir] = os.listdir(dir)
   646             _fspathcache[dir] = os.listdir(dir)
   645         contents = _fspathcache[dir]
   647         contents = _fspathcache[dir]
   646 
   648 
   647         lpart = part.lower()
       
   648         lenp = len(part)
   649         lenp = len(part)
   649         for n in contents:
   650         for n in contents:
   650             if lenp == len(n) and n.lower() == lpart:
   651             if lenp == len(n) and normcase(n) == part:
   651                 result.append(n)
   652                 result.append(n)
   652                 break
   653                 break
   653         else:
   654         else:
   654             # Cannot happen, as the file exists!
   655             # Cannot happen, as the file exists!
   655             result.append(part)
   656             result.append(part)
   656         dir = os.path.join(dir, lpart)
   657         dir = os.path.join(dir, part)
   657 
   658 
   658     return ''.join(result)
   659     return ''.join(result)
   659 
   660 
   660 def checknlink(testfile):
   661 def checknlink(testfile):
   661     '''check whether hardlink count reporting works properly'''
   662     '''check whether hardlink count reporting works properly'''