pack_dirstate: in C version, for invalidation set dict to what we write to disk
authorSiddharth Agarwal <sid0@fb.com>
Tue, 27 May 2014 15:17:38 -0700
changeset 21806 05bd2667df4d
parent 21805 23f3241406ff
child 21807 a96a3d1261c6
pack_dirstate: in C version, for invalidation set dict to what we write to disk For files written out in the last second, Mercurial used to invalidate all the stat data (state, size, mode, mtime) while persisting to disk. This included invalidating the data in the dirstate dict as well. In commit 187bf2dde7c1, this was found to be unnecessary, and Mercurial switched to invalidating only the mtime. However, in the C version of pack_dirstate the value set in the dict was still the fully invalidated one. Switch to invalidating just the mtime in the dict as well.
mercurial/parsers.c
--- a/mercurial/parsers.c	Thu Jun 26 11:10:28 2014 -0400
+++ b/mercurial/parsers.c	Tue May 27 15:17:38 2014 -0700
@@ -261,7 +261,7 @@
 static PyObject *pack_dirstate(PyObject *self, PyObject *args)
 {
 	PyObject *packobj = NULL;
-	PyObject *map, *copymap, *pl;
+	PyObject *map, *copymap, *pl, *mtime_unset = NULL;
 	Py_ssize_t nbytes, pos, l;
 	PyObject *k, *v, *pn;
 	char *p, *s;
@@ -342,9 +342,15 @@
 		if (*s == 'n' && mtime == (uint32_t)now) {
 			/* See pure/parsers.py:pack_dirstate for why we do
 			 * this. */
-			if (PyDict_SetItem(map, k, dirstate_unset) == -1)
+			mtime = -1;
+			mtime_unset = Py_BuildValue(
+				"ciii", *s, mode, size, mtime);
+			if (!mtime_unset)
 				goto bail;
-			mtime = -1;
+			if (PyDict_SetItem(map, k, mtime_unset) == -1)
+				goto bail;
+			Py_DECREF(mtime_unset);
+			mtime_unset = NULL;
 		}
 		putbe32(mode, p);
 		putbe32(size, p + 4);
@@ -374,6 +380,7 @@
 
 	return packobj;
 bail:
+	Py_XDECREF(mtime_unset);
 	Py_XDECREF(packobj);
 	return NULL;
 }