Mercurial > hg-stable
changeset 5423:e5f238a8b0d2
osutil: more cleanups
- eliminate a level of nesting
- untab targets of gotos
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 08 Oct 2007 18:47:14 -0500 |
parents | a3ba7ef98c94 |
children | 005638db9d0c |
files | mercurial/osutil.c |
diffstat | 1 files changed, 74 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/osutil.c Mon Oct 08 18:47:12 2007 -0500 +++ b/mercurial/osutil.c Mon Oct 08 18:47:14 2007 -0500 @@ -215,94 +215,94 @@ dfd = dirfd(dir); #endif - if (do_stat || !all_kinds) { - for (i = 0; i < size; i++) { - PyObject *elt = PyList_GetItem(list, i); - char *name = PyString_AsString(PyTuple_GET_ITEM(elt, 0)); - PyObject *py_st = NULL; - PyObject *py_kind = PyTuple_GET_ITEM(elt, 1); - int kind; - - kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind); - - if (kind != -1 && !do_stat) - continue; + if (!(do_stat || !all_kinds)) + goto done; - strncat(full_path + path_len + 1, name, - PATH_MAX - path_len); - full_path[PATH_MAX] = 0; - - if (do_stat) { - struct listdir_stat *st; + for (i = 0; i < size; i++) { + PyObject *elt = PyList_GetItem(list, i); + char *name = PyString_AsString(PyTuple_GET_ITEM(elt, 0)); + PyObject *py_st = NULL; + PyObject *py_kind = PyTuple_GET_ITEM(elt, 1); + int kind; - if (!ctor_args) { - ctor_args = PyTuple_New(0); - if (!ctor_args) - goto bail; - } - - st = (struct listdir_stat *) - PyObject_CallObject((PyObject *)&listdir_stat_type, - ctor_args); + kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind); - if (!st) - goto bail; -#ifdef AT_SYMLINK_NOFOLLOW - ret = fstatat(dfd, name, &st->st, AT_SYMLINK_NOFOLLOW); -#else - ret = lstat(full_path, &st->st); -#endif - if (ret == -1) { - list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, - full_path); + if (kind != -1 && !do_stat) + continue; + + strncat(full_path + path_len + 1, name, PATH_MAX - path_len); + full_path[PATH_MAX] = 0; + + if (do_stat) { + struct listdir_stat *st; + + if (!ctor_args) { + ctor_args = PyTuple_New(0); + if (!ctor_args) goto bail; - } - if (kind == -1) - kind = mode_to_kind(st->st.st_mode); - py_st = (PyObject *)st; - } else { - struct stat buf; -#ifdef AT_SYMLINK_NOFOLLOW - ret = fstatat(dfd, ent->d_name, &buf, AT_SYMLINK_NOFOLLOW); -#else - ret = lstat(full_path, &buf); -#endif - if (ret == -1) { - list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, - full_path); - goto bail; - } - if (kind == -1) - kind = mode_to_kind(buf.st_mode); } - if (py_kind == Py_None && kind != -1) { - py_kind = PyInt_FromLong(kind); - if (!py_kind) - goto bail; - Py_XDECREF(Py_None); - PyTuple_SET_ITEM(elt, 1, py_kind); - } + st = (struct listdir_stat *) + PyObject_CallObject((PyObject *)&listdir_stat_type, + ctor_args); - if (do_stat) { - if (!py_st) { - py_st = Py_None; - Py_INCREF(Py_None); - } - PyTuple_SET_ITEM(elt, 2, py_st); + if (!st) + goto bail; +#ifdef AT_SYMLINK_NOFOLLOW + ret = fstatat(dfd, name, &st->st, AT_SYMLINK_NOFOLLOW); +#else + ret = lstat(full_path, &st->st); +#endif + if (ret == -1) { + list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, + full_path); + goto bail; } + if (kind == -1) + kind = mode_to_kind(st->st.st_mode); + py_st = (PyObject *)st; + } else { + struct stat buf; +#ifdef AT_SYMLINK_NOFOLLOW + ret = fstatat(dfd, ent->d_name, &buf, AT_SYMLINK_NOFOLLOW); +#else + ret = lstat(full_path, &buf); +#endif + if (ret == -1) { + list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, + full_path); + goto bail; + } + if (kind == -1) + kind = mode_to_kind(buf.st_mode); + } + + if (py_kind == Py_None && kind != -1) { + py_kind = PyInt_FromLong(kind); + if (!py_kind) + goto bail; + Py_XDECREF(Py_None); + PyTuple_SET_ITEM(elt, 1, py_kind); + } + + if (do_stat) { + if (!py_st) { + py_st = Py_None; + Py_INCREF(Py_None); + } + PyTuple_SET_ITEM(elt, 2, py_st); } } goto done; - bail: - Py_XDECREF(list); + bail: + Py_XDECREF(list); - done: - Py_XDECREF(ctor_args); - if (dir) - closedir(dir); + done: + Py_XDECREF(ctor_args); + if (dir) + closedir(dir); return list; }