~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2006-06-09 15:34:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20060609153426-803129580b26d89f
Add a replacement for os.listdir which returns file kind information from readdir when it is available. This drops our osutils.walkdirs time further, down to 77ms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
                           PathNotChild,
47
47
                           IllegalPath,
48
48
                           )
 
49
from bzrlib.readdir import read_dir
49
50
from bzrlib.symbol_versioning import *
50
51
from bzrlib.trace import mutter
51
52
import bzrlib.win32console
818
819
    lstat = os.lstat
819
820
    pending = []
820
821
    _directory = _directory_kind
821
 
    _listdir = listdir
 
822
    _listdir = read_dir
822
823
    pending = [("", "", _directory, None, top)]
823
824
    while pending:
824
825
        dirblock = []
829
830
            relroot = currentdir[0] + '/'
830
831
        else:
831
832
            relroot = ""
832
 
        for name in sorted(_listdir(top)):
 
833
        for name, kind in sorted(_listdir(top)):
833
834
            abspath = top + '/' + name
834
 
            statvalue = lstat(abspath)
835
 
            dirblock.append ((relroot + name, name, file_kind_from_stat_mode(statvalue.st_mode), statvalue, abspath))
 
835
            if kind == 'unknown':
 
836
                statvalue = lstat(abspath)
 
837
                kind = file_kind_from_stat_mode(statvalue.st_mode)
 
838
            else:
 
839
                statvalue = None
 
840
            dirblock.append ((relroot + name, name, kind, statvalue, abspath))
836
841
        yield dirblock
837
842
        # push the user specified dirs from dirblock
838
843
        for dir in reversed(dirblock):