mercurial/windows.py
changeset 18017 74912fe3d718
parent 17560 9ee25d7b1aed
child 18041 f0cfa27c712a
equal deleted inserted replaced
18014:a39fe76c4c65 18017:74912fe3d718
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 import osutil, encoding
     9 import osutil, encoding
    10 import errno, msvcrt, os, re, sys, _winreg
    10 import errno, msvcrt, os, re, stat, sys, _winreg
    11 
    11 
    12 import win32
    12 import win32
    13 executablepath = win32.executablepath
    13 executablepath = win32.executablepath
    14 getuser = win32.getuser
    14 getuser = win32.getuser
    15 hidewindow = win32.hidewindow
    15 hidewindow = win32.hidewindow
   211         executable = findexisting(os.path.join(path, command))
   211         executable = findexisting(os.path.join(path, command))
   212         if executable is not None:
   212         if executable is not None:
   213             return executable
   213             return executable
   214     return findexisting(os.path.expanduser(os.path.expandvars(command)))
   214     return findexisting(os.path.expanduser(os.path.expandvars(command)))
   215 
   215 
       
   216 _wantedkinds = set([stat.S_IFREG, stat.S_IFLNK])
       
   217 
   216 def statfiles(files):
   218 def statfiles(files):
   217     '''Stat each file in files and yield stat or None if file does not exist.
   219     '''Stat each file in files. Yield each stat, or None if a file
       
   220     does not exist or has a type we don't care about.
       
   221 
   218     Cluster and cache stat per directory to minimize number of OS stat calls.'''
   222     Cluster and cache stat per directory to minimize number of OS stat calls.'''
   219     dircache = {} # dirname -> filename -> status | None if file does not exist
   223     dircache = {} # dirname -> filename -> status | None if file does not exist
       
   224     getkind = stat.S_IFMT
   220     for nf in files:
   225     for nf in files:
   221         nf  = normcase(nf)
   226         nf  = normcase(nf)
   222         dir, base = os.path.split(nf)
   227         dir, base = os.path.split(nf)
   223         if not dir:
   228         if not dir:
   224             dir = '.'
   229             dir = '.'
   225         cache = dircache.get(dir, None)
   230         cache = dircache.get(dir, None)
   226         if cache is None:
   231         if cache is None:
   227             try:
   232             try:
   228                 dmap = dict([(normcase(n), s)
   233                 dmap = dict([(normcase(n), s)
   229                     for n, k, s in osutil.listdir(dir, True)])
   234                              for n, k, s in osutil.listdir(dir, True)
       
   235                              if getkind(s) in _wantedkinds])
   230             except OSError, err:
   236             except OSError, err:
   231                 # handle directory not found in Python version prior to 2.5
   237                 # handle directory not found in Python version prior to 2.5
   232                 # Python <= 2.4 returns native Windows code 3 in errno
   238                 # Python <= 2.4 returns native Windows code 3 in errno
   233                 # Python >= 2.5 returns ENOENT and adds winerror field
   239                 # Python >= 2.5 returns ENOENT and adds winerror field
   234                 # EINVAL is raised if dir is not a directory.
   240                 # EINVAL is raised if dir is not a directory.