##// END OF EJS Templates
listdir: add support for aborting if a certain path is found...
Matt Mackall -
r7034:0d513661 default
parent child Browse files
Show More
@@ -9,7 +9,7 b' of the GNU General Public License, incor'
9 9
10 10 from node import nullid
11 11 from i18n import _
12 import struct, os, bisect, stat, util, errno, ignore
12 import struct, os, stat, util, errno, ignore
13 13 import cStringIO, osutil, sys
14 14
15 15 _unknown = ('?', 0, 0, 0)
@@ -458,7 +458,6 b' class dirstate(object):'
458 458 normalize = self.normalize
459 459 listdir = osutil.listdir
460 460 lstat = os.lstat
461 bisect_left = bisect.bisect_left
462 461 pconvert = util.pconvert
463 462 getkind = stat.S_IFMT
464 463 dirkind = stat.S_IFDIR
@@ -510,17 +509,11 b' class dirstate(object):'
510 509 nd = work.pop()
511 510 if hasattr(match, 'dir'):
512 511 match.dir(nd)
513 entries = listdir(join(nd), stat=True)
514 512 if nd == '.':
515 513 nd = ''
514 entries = listdir(join(nd), stat=True)
516 515 else:
517 # do not recurse into a repo contained in this
518 # one. use bisect to find .hg directory so speed
519 # is good on big directory.
520 hg = bisect_left(entries, ('.hg'))
521 if hg < len(entries) and entries[hg][0] == '.hg' \
522 and entries[hg][1] == dirkind:
523 continue
516 entries = listdir(join(nd), stat=True, skip ='.hg')
524 517 for f, kind, st in entries:
525 518 nf = normalize(nd and (nd + "/" + f) or f)
526 519 if nf not in results:
@@ -114,17 +114,18 b' int entkind(struct dirent *ent)'
114 114
115 115 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
116 116 {
117 static char *kwlist[] = { "path", "stat", NULL };
117 static char *kwlist[] = { "path", "stat", "skip", NULL };
118 118 PyObject *statflag = NULL, *list, *elem, *stat, *ret = NULL;
119 char fullpath[PATH_MAX + 10], *path;
119 char fullpath[PATH_MAX + 10], *path, *skip = NULL;
120 120 int pathlen, keepstat, kind, dfd = -1, err;
121 121 struct stat st;
122 122 struct dirent *ent;
123 123 DIR *dir;
124 124
125 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:listdir", kwlist,
126 &path, &pathlen, &statflag))
125 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|Os:listdir", kwlist,
126 &path, &pathlen, &statflag, &skip))
127 127 goto error_parse;
128
128 129 if (pathlen >= PATH_MAX)
129 130 goto error_parse;
130 131
@@ -177,6 +178,12 b' static PyObject *listdir(PyObject *self,'
177 178 kind = st.st_mode & S_IFMT;
178 179 }
179 180
181 /* quit early? */
182 if (skip && kind == S_IFDIR && !strcmp(ent->d_name, skip)) {
183 ret = PyList_New(0);
184 goto error;
185 }
186
180 187 if (keepstat) {
181 188 stat = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL);
182 189 if (!stat)
@@ -192,7 +199,6 b' static PyObject *listdir(PyObject *self,'
192 199 Py_DECREF(elem);
193 200 }
194 201
195 PyList_Sort(list);
196 202 ret = list;
197 203 Py_INCREF(ret);
198 204
@@ -10,7 +10,7 b' def _mode_to_kind(mode):'
10 10 if stat.S_ISSOCK(mode): return stat.S_IFSOCK
11 11 return mode
12 12
13 def listdir(path, stat=False):
13 def listdir(path, stat=False, skip=None):
14 14 '''listdir(path, stat=False) -> list_of_tuples
15 15
16 16 Return a sorted list containing information about the entries
@@ -30,6 +30,8 b' def listdir(path, stat=False):'
30 30 names.sort()
31 31 for fn in names:
32 32 st = os.lstat(prefix + fn)
33 if fn == skip and stat.S_ISDIR(st.st_mode):
34 return []
33 35 if stat:
34 36 result.append((fn, _mode_to_kind(st.st_mode), st))
35 37 else:
General Comments 0
You need to be logged in to leave comments. Login now