##// END OF EJS Templates
dirstate.walk: fold findfiles into main walk loop
Matt Mackall -
r6820:639d9cb9 default
parent child Browse files
Show More
@@ -474,16 +474,50 b' class dirstate(object):'
474 s_isdir = stat.S_ISDIR
474 s_isdir = stat.S_ISDIR
475 supported = self._supported
475 supported = self._supported
476 _join = self._join
476 _join = self._join
477 work = []
478 wadd = work.append
479 found = []
480 add = found.append
481
477 known = {'.hg': 1}
482 known = {'.hg': 1}
478
483
479 # recursion free walker, faster than os.walk.
484 # step one, find all files that match our criteria
480 def findfiles(s):
485 for ff in util.sort(files):
481 work = [s]
486 nf = normpath(ff)
482 wadd = work.append
487 nn = self.normalize(nf)
483 found = []
488 f = _join(ff)
484 add = found.append
489 if nn in known:
490 continue
491
492 try:
493 st = lstat(f)
494 except OSError, inst:
495 keep = False
496 for fn in dc:
497 if nf == fn or (fn.startswith(nf) and fn[len(nf)] == '/'):
498 keep = True
499 break
500 if not keep:
501 if inst.errno != errno.ENOENT:
502 fwarn(ff, inst.strerror)
503 elif badfn(ff, inst.strerror) and imatch(nf):
504 yield ff, None
505 continue
506
507 if not s_isdir(st.st_mode):
508 known[nn] = 1
509 if supported(ff, st.st_mode, verbose=True):
510 yield self.normalize(nf), st
511 elif ff in dc:
512 yield nf, None
513 continue
514
515 if dirignore(nf):
516 continue
517
485 if hasattr(match, 'dir'):
518 if hasattr(match, 'dir'):
486 match.dir(normpath(s[common_prefix_len:]))
519 match.dir(normpath(f[common_prefix_len:]))
520 wadd(f)
487 while work:
521 while work:
488 top = work.pop()
522 top = work.pop()
489 entries = listdir(top, stat=True)
523 entries = listdir(top, stat=True)
@@ -520,39 +554,8 b' class dirstate(object):'
520 add((nn, st))
554 add((nn, st))
521 elif np in dc:
555 elif np in dc:
522 add((nn, None))
556 add((nn, None))
523 return util.sort(found)
557 for e in util.sort(found):
524
558 yield e
525 # step one, find all files that match our criteria
526 for ff in util.sort(files):
527 nf = normpath(ff)
528 nn = self.normalize(nf)
529 f = _join(ff)
530 try:
531 st = lstat(f)
532 except OSError, inst:
533 found = False
534 for fn in dc:
535 if nf == fn or (fn.startswith(nf) and fn[len(nf)] == '/'):
536 found = True
537 break
538 if not found:
539 if inst.errno != errno.ENOENT:
540 fwarn(ff, inst.strerror)
541 elif badfn(ff, inst.strerror) and imatch(nf):
542 yield ff, None
543 continue
544 if s_isdir(st.st_mode):
545 if not dirignore(nf):
546 for e in findfiles(f):
547 yield e
548 else:
549 if nn in known:
550 continue
551 known[nn] = 1
552 if supported(ff, st.st_mode, verbose=True):
553 yield self.normalize(nf), st
554 elif ff in dc:
555 yield nf, None
556
559
557 # step two run through anything left in the dc hash and yield
560 # step two run through anything left in the dc hash and yield
558 # if we haven't already seen it
561 # if we haven't already seen it
General Comments 0
You need to be logged in to leave comments. Login now