comparison mercurial/dirstate.py @ 5396:5105b119edd2

Add osutil module, containing a listdir function. This is similar to os.listdir, only it returns a sorted list of tuples.
author Bryan O'Sullivan <bos@serpentine.com>
date Fri, 05 Oct 2007 15:01:06 -0700
parents f46ab9cacd3c
children 0c43f87baba3
comparison
equal deleted inserted replaced
5395:e73a83af7926 5396:5105b119edd2
8 """ 8 """
9 9
10 from node import * 10 from node import *
11 from i18n import _ 11 from i18n import _
12 import struct, os, time, bisect, stat, strutil, util, re, errno, ignore 12 import struct, os, time, bisect, stat, strutil, util, re, errno, ignore
13 import cStringIO 13 import cStringIO, osutil
14 14
15 _unknown = ('?', 0, 0, 0) 15 _unknown = ('?', 0, 0, 0)
16 _format = ">cllll" 16 _format = ">cllll"
17 17
18 class dirstate(object): 18 class dirstate(object):
387 common_prefix_len = len(self._root) 387 common_prefix_len = len(self._root)
388 if not self._root.endswith(os.sep): 388 if not self._root.endswith(os.sep):
389 common_prefix_len += 1 389 common_prefix_len += 1
390 390
391 normpath = util.normpath 391 normpath = util.normpath
392 listdir = os.listdir 392 listdir = osutil.listdir
393 lstat = os.lstat 393 lstat = os.lstat
394 bisect_left = bisect.bisect_left 394 bisect_left = bisect.bisect_left
395 isdir = os.path.isdir 395 isdir = os.path.isdir
396 pconvert = util.pconvert 396 pconvert = util.pconvert
397 join = os.path.join 397 join = os.path.join
408 add = found.append 408 add = found.append
409 if directories: 409 if directories:
410 add((normpath(s[common_prefix_len:]), 'd', lstat(s))) 410 add((normpath(s[common_prefix_len:]), 'd', lstat(s)))
411 while work: 411 while work:
412 top = work.pop() 412 top = work.pop()
413 names = listdir(top) 413 entries = listdir(top, stat=True)
414 names.sort()
415 # nd is the top of the repository dir tree 414 # nd is the top of the repository dir tree
416 nd = normpath(top[common_prefix_len:]) 415 nd = normpath(top[common_prefix_len:])
417 if nd == '.': 416 if nd == '.':
418 nd = '' 417 nd = ''
419 else: 418 else:
420 # do not recurse into a repo contained in this 419 # do not recurse into a repo contained in this
421 # one. use bisect to find .hg directory so speed 420 # one. use bisect to find .hg directory so speed
422 # is good on big directory. 421 # is good on big directory.
422 names = [e[0] for e in entries]
423 hg = bisect_left(names, '.hg') 423 hg = bisect_left(names, '.hg')
424 if hg < len(names) and names[hg] == '.hg': 424 if hg < len(names) and names[hg] == '.hg':
425 if isdir(join(top, '.hg')): 425 if isdir(join(top, '.hg')):
426 continue 426 continue
427 for f in names: 427 for f, kind, st in entries:
428 np = pconvert(join(nd, f)) 428 np = pconvert(join(nd, f))
429 if np in known: 429 if np in known:
430 continue 430 continue
431 known[np] = 1 431 known[np] = 1
432 p = join(top, f) 432 p = join(top, f)
433 # don't trip over symlinks 433 # don't trip over symlinks
434 st = lstat(p) 434 if kind == stat.S_IFDIR:
435 if s_isdir(st.st_mode):
436 if not ignore(np): 435 if not ignore(np):
437 wadd(p) 436 wadd(p)
438 if directories: 437 if directories:
439 add((np, 'd', st)) 438 add((np, 'd', st))
440 if np in dc and match(np): 439 if np in dc and match(np):