Mercurial > public > mercurial-scm > hg-stable
diff mercurial/osutil.c @ 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 | 892d27fb04a5 |
children | 2c1f18b88b6a |
line wrap: on
line diff
--- a/mercurial/osutil.c Sat Sep 13 10:44:44 2008 -0500 +++ b/mercurial/osutil.c Sat Sep 13 10:46:47 2008 -0500 @@ -114,17 +114,18 @@ static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = { "path", "stat", NULL }; + static char *kwlist[] = { "path", "stat", "skip", NULL }; PyObject *statflag = NULL, *list, *elem, *stat, *ret = NULL; - char fullpath[PATH_MAX + 10], *path; + char fullpath[PATH_MAX + 10], *path, *skip = NULL; int pathlen, keepstat, kind, dfd = -1, err; struct stat st; struct dirent *ent; DIR *dir; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:listdir", kwlist, - &path, &pathlen, &statflag)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|Os:listdir", kwlist, + &path, &pathlen, &statflag, &skip)) goto error_parse; + if (pathlen >= PATH_MAX) goto error_parse; @@ -177,6 +178,12 @@ kind = st.st_mode & S_IFMT; } + /* quit early? */ + if (skip && kind == S_IFDIR && !strcmp(ent->d_name, skip)) { + ret = PyList_New(0); + goto error; + } + if (keepstat) { stat = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL); if (!stat) @@ -192,7 +199,6 @@ Py_DECREF(elem); } - PyList_Sort(list); ret = list; Py_INCREF(ret);