Mercurial > public > mercurial-scm > hg
comparison mercurial/osutil.py @ 7034:0d513661d6c2
listdir: add support for aborting if a certain path is found
This lets us bail out early if we find '.hg', letting us skip sorting
and bisecting for it.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 13 Sep 2008 10:46:47 -0500 |
parents | 5105b119edd2 |
children | 094af6eeb7d7 |
comparison
equal
deleted
inserted
replaced
7033:892d27fb04a5 | 7034:0d513661d6c2 |
---|---|
8 if stat.S_ISCHR(mode): return stat.S_IFCHR | 8 if stat.S_ISCHR(mode): return stat.S_IFCHR |
9 if stat.S_ISFIFO(mode): return stat.S_IFIFO | 9 if stat.S_ISFIFO(mode): return stat.S_IFIFO |
10 if stat.S_ISSOCK(mode): return stat.S_IFSOCK | 10 if stat.S_ISSOCK(mode): return stat.S_IFSOCK |
11 return mode | 11 return mode |
12 | 12 |
13 def listdir(path, stat=False): | 13 def listdir(path, stat=False, skip=None): |
14 '''listdir(path, stat=False) -> list_of_tuples | 14 '''listdir(path, stat=False) -> list_of_tuples |
15 | 15 |
16 Return a sorted list containing information about the entries | 16 Return a sorted list containing information about the entries |
17 in the directory. | 17 in the directory. |
18 | 18 |
28 prefix = path + os.sep | 28 prefix = path + os.sep |
29 names = os.listdir(path) | 29 names = os.listdir(path) |
30 names.sort() | 30 names.sort() |
31 for fn in names: | 31 for fn in names: |
32 st = os.lstat(prefix + fn) | 32 st = os.lstat(prefix + fn) |
33 if fn == skip and stat.S_ISDIR(st.st_mode): | |
34 return [] | |
33 if stat: | 35 if stat: |
34 result.append((fn, _mode_to_kind(st.st_mode), st)) | 36 result.append((fn, _mode_to_kind(st.st_mode), st)) |
35 else: | 37 else: |
36 result.append((fn, _mode_to_kind(st.st_mode))) | 38 result.append((fn, _mode_to_kind(st.st_mode))) |
37 return result | 39 return result |