Mercurial > hg-stable
changeset 18019:e248bff2d8dd
osutil: factor out creation and init of listdir_stat
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Fri, 30 Nov 2012 15:55:09 -0800 |
parents | 0fed3fe45ea7 |
children | ec02eef0b686 |
files | mercurial/osutil.c |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/osutil.c Fri Nov 30 15:55:08 2012 -0800 +++ b/mercurial/osutil.c Fri Nov 30 15:55:09 2012 -0800 @@ -276,6 +276,16 @@ return -1; } +static PyObject *makestat(const struct stat *st) +{ + PyObject *stat; + + stat = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL); + if (stat) + memcpy(&((struct listdir_stat *)stat)->st, st, sizeof(*st)); + return stat; +} + static PyObject *_listdir(char *path, int pathlen, int keepstat, char *skip) { PyObject *list, *elem, *stat, *ret = NULL; @@ -351,10 +361,9 @@ } if (keepstat) { - stat = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL); + stat = makestat(&st); if (!stat) goto error; - memcpy(&((struct listdir_stat *)stat)->st, &st, sizeof(st)); elem = Py_BuildValue("siN", ent->d_name, kind, stat); } else elem = Py_BuildValue("si", ent->d_name, kind);