Patchwork D10569: revlog: always "append" full size tuple

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 11:56 a.m.
Message ID <differential-rev-PHID-DREV-bdvi3vkzz7witmt3vgkq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48890/
State Superseded
Headers show

Comments

phabricator - May 3, 2021, 11:56 a.m.
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Same reasoning as the previous patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10569

AFFECTED FILES
  mercurial/bundlerepo.py
  mercurial/cext/revlog.c
  mercurial/pure/parsers.py
  mercurial/revlog.py
  mercurial/unionrepo.py
  tests/test-parseindex2.py

CHANGE DETAILS




To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-parseindex2.py b/tests/test-parseindex2.py
--- a/tests/test-parseindex2.py
+++ b/tests/test-parseindex2.py
@@ -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)
diff --git a/mercurial/unionrepo.py b/mercurial/unionrepo.py
--- a/mercurial/unionrepo.py
+++ b/mercurial/unionrepo.py
@@ -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)
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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:
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -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]
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -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 */
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -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)