Patchwork D10625: revlogv2: store version information in the docket only

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 12:08 p.m.
Message ID <differential-rev-PHID-DREV-t5kqnbrohqtfkjvq4g4c-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48946/
State New
Headers show

Comments

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

REVISION SUMMARY
  Having it duplicated in the index was both useless and a risk of discrepancy.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/revlog.c
  mercurial/configitems.py
  mercurial/pure/parsers.py
  mercurial/revlog.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -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
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1145,7 +1145,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
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -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);