comparison hgext/inotify/server.py @ 8322:3c6c21eb3416

inotify: inotify.server.walkrepodirs() simplify walking Do not 'yield tuple, boolean' to filter later on the boolean. Test the boolean first, and yield tuple only if needed.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 04 May 2009 17:11:49 +0900
parents ec985dcfd7da
children 589a82fb02a2
comparison
equal deleted inserted replaced
8321:ec985dcfd7da 8322:3c6c21eb3416
30 30
31 def walkrepodirs(repo): 31 def walkrepodirs(repo):
32 '''Iterate over all subdirectories of this repo. 32 '''Iterate over all subdirectories of this repo.
33 Exclude the .hg directory, any nested repos, and ignored dirs.''' 33 Exclude the .hg directory, any nested repos, and ignored dirs.'''
34 rootslash = repo.root + os.sep 34 rootslash = repo.root + os.sep
35
35 def walkit(dirname, top): 36 def walkit(dirname, top):
36 fullpath = rootslash + dirname 37 fullpath = rootslash + dirname
37 hginside = False 38 hginside = False
38 try: 39 try:
39 for name, kind in osutil.listdir(fullpath): 40 for name, kind in osutil.listdir(fullpath):
43 if not top: break 44 if not top: break
44 else: 45 else:
45 d = join(dirname, name) 46 d = join(dirname, name)
46 if repo.dirstate._ignore(d): 47 if repo.dirstate._ignore(d):
47 continue 48 continue
48 for subdir, hginsub in walkit(d, False): 49 for subdir in walkit(d, False):
49 if not hginsub: 50 yield subdir
50 yield subdir, False
51 except OSError, err: 51 except OSError, err:
52 if err.errno not in walk_ignored_errors: 52 if err.errno not in walk_ignored_errors:
53 raise 53 raise
54 yield fullpath, hginside 54 if top or not hginside:
55 for dirname, hginside in walkit('', True): 55 yield fullpath
56 yield dirname 56
57 return walkit('', True)
57 58
58 def walk(repo, root): 59 def walk(repo, root):
59 '''Like os.walk, but only yields regular files.''' 60 '''Like os.walk, but only yields regular files.'''
60 61
61 # This function is critical to performance during startup. 62 # This function is critical to performance during startup.