changeset 47157:47ffc754989a

revlog: always "append" full size tuple Same reasoning as the previous patch. Differential Revision: https://phab.mercurial-scm.org/D10569
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:21:25 +0200
parents 4292bed8da7c
children b6e1fe7ac24b
files mercurial/bundlerepo.py mercurial/cext/revlog.c mercurial/pure/parsers.py mercurial/revlog.py mercurial/unionrepo.py tests/test-parseindex2.py
diffstat 6 files changed, 27 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlerepo.py	Mon May 03 12:21:15 2021 +0200
+++ b/mercurial/bundlerepo.py	Mon May 03 12:21:25 2021 +0200
@@ -93,7 +93,7 @@
                 )
 
             baserev = self.rev(deltabase)
-            # start, size, full unc. size, base (unused), link, p1, p2, node
+            # start, size, full unc. size, base (unused), link, p1, p2, node, sidedata_offset (unused), sidedata_size (unused)
             e = (
                 revlog.offset_type(start, flags),
                 size,
@@ -103,6 +103,8 @@
                 self.rev(p1),
                 self.rev(p2),
                 node,
+                0,
+                0,
             )
             self.index.append(e)
             self.bundlerevs.add(n)
--- a/mercurial/cext/revlog.c	Mon May 03 12:21:15 2021 +0200
+++ b/mercurial/cext/revlog.c	Mon May 03 12:21:25 2021 +0200
@@ -118,11 +118,9 @@
 static int index_find_node(indexObject *self, const char *node);
 
 #if LONG_MAX == 0x7fffffffL
-static const char *const v1_tuple_format = PY23("Kiiiiiis#", "Kiiiiiiy#");
-static const char *const v2_tuple_format = PY23("Kiiiiiis#Ki", "Kiiiiiiy#Ki");
+static const char *const tuple_format = PY23("Kiiiiiis#Ki", "Kiiiiiiy#Ki");
 #else
-static const char *const v1_tuple_format = PY23("kiiiiiis#", "kiiiiiiy#");
-static const char *const v2_tuple_format = PY23("kiiiiiis#ki", "kiiiiiiy#ki");
+static const char *const tuple_format = PY23("kiiiiiis#ki", "kiiiiiiy#ki");
 #endif
 
 /* A RevlogNG v1 index entry is 64 bytes long. */
@@ -342,10 +340,9 @@
 		sidedata_comp_len = getbe32(data + 72);
 	}
 
-	return Py_BuildValue(v2_tuple_format, offset_flags, comp_len,
-	                     uncomp_len, base_rev, link_rev, parent_1, parent_2,
-	                     c_node_id, self->nodelen, sidedata_offset,
-	                     sidedata_comp_len);
+	return Py_BuildValue(tuple_format, offset_flags, comp_len, uncomp_len,
+	                     base_rev, link_rev, parent_1, parent_2, c_node_id,
+	                     self->nodelen, sidedata_offset, sidedata_comp_len);
 }
 /*
  * Pack header information in binary
@@ -443,23 +440,12 @@
 	const char *c_node_id;
 	char *data;
 
-	if (self->entry_size == v1_entry_size) {
-		if (!PyArg_ParseTuple(obj, v1_tuple_format, &offset_flags,
-		                      &comp_len, &uncomp_len, &base_rev,
-		                      &link_rev, &parent_1, &parent_2,
-		                      &c_node_id, &c_node_id_len)) {
-			PyErr_SetString(PyExc_TypeError, "8-tuple required");
-			return NULL;
-		}
-	} else {
-		if (!PyArg_ParseTuple(obj, v2_tuple_format, &offset_flags,
-		                      &comp_len, &uncomp_len, &base_rev,
-		                      &link_rev, &parent_1, &parent_2,
-		                      &c_node_id, &c_node_id_len,
-		                      &sidedata_offset, &sidedata_comp_len)) {
-			PyErr_SetString(PyExc_TypeError, "10-tuple required");
-			return NULL;
-		}
+	if (!PyArg_ParseTuple(obj, tuple_format, &offset_flags, &comp_len,
+	                      &uncomp_len, &base_rev, &link_rev, &parent_1,
+	                      &parent_2, &c_node_id, &c_node_id_len,
+	                      &sidedata_offset, &sidedata_comp_len)) {
+		PyErr_SetString(PyExc_TypeError, "10-tuple required");
+		return NULL;
 	}
 
 	if (c_node_id_len != self->nodelen) {
@@ -490,7 +476,7 @@
 	memcpy(data + 32, c_node_id, c_node_id_len);
 	/* Padding since SHA-1 is only 20 bytes for now */
 	memset(data + 32 + c_node_id_len, 0, 32 - c_node_id_len);
-	if (self->entry_size != v1_entry_size) {
+	if (self->format_version == format_v2) {
 		putbe64(sidedata_offset, data + 64);
 		putbe32(sidedata_comp_len, data + 72);
 		/* Padding for 96 bytes alignment */
--- a/mercurial/pure/parsers.py	Mon May 03 12:21:15 2021 +0200
+++ b/mercurial/pure/parsers.py	Mon May 03 12:21:25 2021 +0200
@@ -104,9 +104,14 @@
     def append(self, tup):
         if '_nodemap' in vars(self):
             self._nodemap[tup[7]] = len(self)
-        data = self.index_format.pack(*tup)
+        data = self._pack_entry(tup)
         self._extra.append(data)
 
+    def _pack_entry(self, entry):
+        assert entry[8] == 0
+        assert entry[9] == 0
+        return self.index_format.pack(*entry[:8])
+
     def _check_index(self, i):
         if not isinstance(i, int):
             raise TypeError(b"expecting int indexes")
@@ -299,6 +304,9 @@
     def _unpack_entry(self, data):
         return self.index_format.unpack(data)
 
+    def _pack_entry(self, entry):
+        return self.index_format.pack(*entry)
+
     def entry_binary(self, rev):
         """return the raw binary string representing a revision"""
         entry = self[rev]
--- a/mercurial/revlog.py	Mon May 03 12:21:15 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 12:21:25 2021 +0200
@@ -2268,9 +2268,6 @@
             len(serialized_sidedata),
         )
 
-        if self._format_version != REVLOGV2:
-            e = e[:8]
-
         self.index.append(e)
         entry = self.index.entry_binary(curr)
         if curr == 0:
--- a/mercurial/unionrepo.py	Mon May 03 12:21:15 2021 +0200
+++ b/mercurial/unionrepo.py	Mon May 03 12:21:25 2021 +0200
@@ -97,6 +97,8 @@
                 self.rev(p1node),
                 self.rev(p2node),
                 node,
+                0,  # sidedata offset
+                0,  # sidedata size
             )
             self.index.append(e)
             self.bundlerevs.add(n)
--- a/tests/test-parseindex2.py	Mon May 03 12:21:15 2021 +0200
+++ b/tests/test-parseindex2.py	Mon May 03 12:21:25 2021 +0200
@@ -264,7 +264,7 @@
             # node won't matter for this test, let's just make sure
             # they don't collide. Other data don't matter either.
             node = hexrev(p1) + hexrev(p2) + b'.' * 12
-            index.append((0, 0, 12, 1, 34, p1, p2, node))
+            index.append((0, 0, 12, 1, 34, p1, p2, node, 0, 0))
 
         appendrev(4)
         appendrev(5)