[PATCH 2 of 4] osutil: factor out creation and init of listdir_stat

Bryan O'Sullivan bos at serpentine.com
Fri Nov 30 16:20:04 CST 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1354313913 28800
# Node ID 47fa8e968f748579eda76bec9f897a31e54acacf
# Parent  874a5aac379f0798c758797f24abf1f7be9f05d7
osutil: factor out creation and init of listdir_stat

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -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);


More information about the Mercurial-devel mailing list