revlogv2: store version information in the docket only
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 03 May 2021 12:34:21 +0200
changeset 47235 6b1eae313b2f
parent 47234 616b8f412676
child 47236 1422eef04309
revlogv2: store version information in the docket only Having it duplicated in the index was both useless and a risk of discrepancy. Differential Revision: https://phab.mercurial-scm.org/D10625
mercurial/cext/revlog.c
mercurial/configitems.py
mercurial/pure/parsers.py
mercurial/revlog.py
--- a/mercurial/cext/revlog.c	Mon May 03 12:34:11 2021 +0200
+++ b/mercurial/cext/revlog.c	Mon May 03 12:34:21 2021 +0200
@@ -354,6 +354,13 @@
 	if (!PyArg_ParseTuple(args, "I", &header)) {
 		return NULL;
 	}
+	if (self->format_version != format_v1) {
+		PyErr_Format(PyExc_RuntimeError,
+		             "version header should go in the docket, not the "
+		             "index: %lu",
+		             header);
+		return NULL;
+	}
 	putbe32(header, out);
 	return PyBytes_FromStringAndSize(out, 4);
 }
@@ -378,7 +385,7 @@
 	data = index_deref(self, rev);
 	if (data == NULL)
 		return NULL;
-	if (rev == 0) {
+	if (rev == 0 && self->format_version == format_v1) {
 		/* the header is eating the start of the first entry */
 		return PyBytes_FromStringAndSize(data + 4,
 		                                 self->entry_size - 4);
--- a/mercurial/configitems.py	Mon May 03 12:34:11 2021 +0200
+++ b/mercurial/configitems.py	Mon May 03 12:34:21 2021 +0200
@@ -1150,7 +1150,6 @@
 )
 # "out of experimental" todo list.
 #
-# * stop storing version information in the index (it is already in the docket)
 # * properly hide uncommitted content to other process
 # * expose transaction content hooks during pre-commit validation
 # * include management of a persistent nodemap in the main docket
--- a/mercurial/pure/parsers.py	Mon May 03 12:34:11 2021 +0200
+++ b/mercurial/pure/parsers.py	Mon May 03 12:34:21 2021 +0200
@@ -15,6 +15,7 @@
     sha1nodeconstants,
 )
 from .. import (
+    error,
     pycompat,
     util,
 )
@@ -311,10 +312,14 @@
         """return the raw binary string representing a revision"""
         entry = self[rev]
         p = revlog_constants.INDEX_ENTRY_V2.pack(*entry)
-        if rev == 0:
-            p = p[revlog_constants.INDEX_HEADER.size :]
         return p
 
+    def pack_header(self, header):
+        """pack header information as binary"""
+        msg = 'version header should go in the docket, not the index: %d'
+        msg %= header
+        raise error.ProgrammingError(msg)
+
 
 class IndexObject2(Index2Mixin, IndexObject):
     pass
--- a/mercurial/revlog.py	Mon May 03 12:34:11 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 12:34:21 2021 +0200
@@ -2017,7 +2017,7 @@
                 self._inline = False
                 for i in self:
                     e = self.index.entry_binary(i)
-                    if i == 0:
+                    if i == 0 and self._docket is None:
                         header = self._format_flags | self._format_version
                         header = self.index.pack_header(header)
                         e = header + e
@@ -2380,7 +2380,7 @@
 
         self.index.append(e)
         entry = self.index.entry_binary(curr)
-        if curr == 0:
+        if curr == 0 and self._docket is None:
             header = self._format_flags | self._format_version
             header = self.index.pack_header(header)
             entry = header + entry
@@ -3207,7 +3207,7 @@
                 rev = startrev + i
                 self.index.replace_sidedata_info(rev, e[8], e[9], e[0])
                 packed = self.index.entry_binary(rev)
-                if rev == 0:
+                if rev == 0 and self._docket is None:
                     header = self._format_flags | self._format_version
                     header = self.index.pack_header(header)
                     packed = header + packed