Patchwork D10648: revlogv2: preserve the compression mode on disk

login
register
mail settings
Submitter phabricator
Date May 4, 2021, 2:19 p.m.
Message ID <differential-rev-PHID-DREV-oix22z7ynbfmt5c2pmdi-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48966/
State Superseded
Headers show

Comments

phabricator - May 4, 2021, 2:19 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The value is still the same and still not treated, but now it exists one disk.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/revlog.c
  mercurial/pure/parsers.py
  mercurial/revlogutils/constants.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/revlogutils/constants.py b/mercurial/revlogutils/constants.py
--- a/mercurial/revlogutils/constants.py
+++ b/mercurial/revlogutils/constants.py
@@ -85,9 +85,10 @@ 
 # 32 bytes: nodeid
 #  8 bytes: sidedata offset
 #  4 bytes: sidedata compressed length
-#  20 bytes: Padding to align to 96 bytes (see RevlogV2Plan wiki page)
-INDEX_ENTRY_V2 = struct.Struct(b">Qiiiiii20s12xQi20x")
-assert INDEX_ENTRY_V2.size == 32 * 3
+#  1 bytes: compression mode (2 lower bit are data_compression_mode)
+#  19 bytes: Padding to align to 96 bytes (see RevlogV2Plan wiki page)
+INDEX_ENTRY_V2 = struct.Struct(b">Qiiiiii20s12xQiB19x")
+assert INDEX_ENTRY_V2.size == 32 * 3, INDEX_ENTRY_V2.size
 
 # revlog index flags
 
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -315,12 +315,10 @@ 
             self._extra[rev - self._lgt] = new
 
     def _unpack_entry(self, data):
-        return self.index_format.unpack(data) + (
-            revlog_constants.COMP_MODE_INLINE,
-        )
+        return self.index_format.unpack(data)
 
     def _pack_entry(self, entry):
-        return self.index_format.pack(*entry[:10])
+        return self.index_format.pack(*entry[:11])
 
     def entry_binary(self, rev):
         """return the raw binary string representing a revision"""
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -338,12 +338,13 @@ 
 	if (self->format_version == format_v1) {
 		sidedata_offset = 0;
 		sidedata_comp_len = 0;
+		data_comp_mode = comp_mode_inline;
 	} else {
 		sidedata_offset = getbe64(data + 64);
 		sidedata_comp_len = getbe32(data + 72);
+		data_comp_mode = data[76];
 	}
 
-	data_comp_mode = comp_mode_inline;
 	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,
@@ -466,7 +467,8 @@ 
 		PyErr_SetString(PyExc_TypeError, "invalid node");
 		return NULL;
 	}
-	if (data_comp_mode != comp_mode_inline) {
+	if (self->format_version == format_v1 &&
+	    data_comp_mode != comp_mode_inline) {
 		PyErr_Format(PyExc_ValueError,
 		             "invalid data compression mode: %i",
 		             data_comp_mode);
@@ -499,8 +501,9 @@ 
 	if (self->format_version == format_v2) {
 		putbe64(sidedata_offset, data + 64);
 		putbe32(sidedata_comp_len, data + 72);
+		data[76] = (char)data_comp_mode;
 		/* Padding for 96 bytes alignment */
-		memset(data + 76, 0, self->entry_size - 76);
+		memset(data + 77, 0, self->entry_size - 77);
 	}
 
 	if (self->ntinitialized)