[PATCH 1 of 5 V2] pack_dirstate: in C version, for invalidation set dict to what we write to disk

Siddharth Agarwal sid0 at fb.com
Thu May 29 23:19:16 UTC 2014


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1401229058 25200
#      Tue May 27 15:17:38 2014 -0700
# Node ID 2c2127948317ee1615b4d3f2bbd458937b2bc08a
# Parent  9bafe09285f22661f13494a2037b7f0508523cfd
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.

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


More information about the Mercurial-devel mailing list