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

login
register
mail settings
Submitter Siddharth Agarwal
Date May 28, 2014, 5:05 a.m.
Message ID <56c3003308932542cb37.1401253517@dev1738.prn1.facebook.com>
Download mbox | patch
Permalink /patch/4876/
State Superseded
Headers show

Comments

Siddharth Agarwal - May 28, 2014, 5:05 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1401229058 25200
#      Tue May 27 15:17:38 2014 -0700
# Node ID 56c3003308932542cb37fc905aade2d489712162
# Parent  652e07debf10193f4973a48ead96a95e81d0a55b
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.

Patch

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;
 }