comparison hgext/inotify/server.py @ 8324:b923d599c309

inotify: inotify.server.walk*() remove unnecessary var Remove hginside var and the test it relates to: not( top or not hginside ) == (not top) and hginside, so the only case when nothing will be yielded is when hginside is True and top is False. Because of the returns placed upstream, this case will not happen anymore. We can then safely remove hginside and the (if)s
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 04 May 2009 17:58:26 +0900
parents 589a82fb02a2
children f2559645643a
comparison
equal deleted inserted replaced
8323:589a82fb02a2 8324:b923d599c309
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
36 def walkit(dirname, top): 36 def walkit(dirname, top):
37 fullpath = rootslash + dirname 37 fullpath = rootslash + dirname
38 hginside = False
39 try: 38 try:
40 for name, kind in osutil.listdir(fullpath): 39 for name, kind in osutil.listdir(fullpath):
41 if kind == stat.S_IFDIR: 40 if kind == stat.S_IFDIR:
42 if name == '.hg': 41 if name == '.hg':
43 hginside = True
44 if not top: 42 if not top:
45 return 43 return
46 else: 44 else:
47 d = join(dirname, name) 45 d = join(dirname, name)
48 if repo.dirstate._ignore(d): 46 if repo.dirstate._ignore(d):
50 for subdir in walkit(d, False): 48 for subdir in walkit(d, False):
51 yield subdir 49 yield subdir
52 except OSError, err: 50 except OSError, err:
53 if err.errno not in walk_ignored_errors: 51 if err.errno not in walk_ignored_errors:
54 raise 52 raise
55 if top or not hginside: 53 yield fullpath
56 yield fullpath
57 54
58 return walkit('', True) 55 return walkit('', True)
59 56
60 def walk(repo, root): 57 def walk(repo, root):
61 '''Like os.walk, but only yields regular files.''' 58 '''Like os.walk, but only yields regular files.'''
64 61
65 rootslash = repo.root + os.sep 62 rootslash = repo.root + os.sep
66 63
67 def walkit(root, reporoot): 64 def walkit(root, reporoot):
68 files, dirs = [], [] 65 files, dirs = [], []
69 hginside = False
70 66
71 try: 67 try:
72 fullpath = rootslash + root 68 fullpath = rootslash + root
73 for name, kind in osutil.listdir(fullpath): 69 for name, kind in osutil.listdir(fullpath):
74 if kind == stat.S_IFDIR: 70 if kind == stat.S_IFDIR:
75 if name == '.hg': 71 if name == '.hg':
76 hginside = True
77 if reporoot: 72 if reporoot:
78 continue 73 continue
79 else: 74 else:
80 return 75 return
81 dirs.append(name) 76 dirs.append(name)
82 elif kind in (stat.S_IFREG, stat.S_IFLNK): 77 elif kind in (stat.S_IFREG, stat.S_IFLNK):
83 files.append((name, kind)) 78 files.append((name, kind))
84 if reporoot or not hginside: 79 yield fullpath, dirs, files
85 yield fullpath, dirs, files
86 80
87 for subdir in dirs: 81 for subdir in dirs:
88 path = join(root, subdir) 82 path = join(root, subdir)
89 if repo.dirstate._ignore(path): 83 if repo.dirstate._ignore(path):
90 continue 84 continue