Patchwork D10567: revlog: introduce an explicit `format_version` member in the index struct

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

Comments

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

REVISION SUMMARY
  This will allow for cleaner check than assuming each version has a different
  size. Unsurprisingly I am planning to use this to introduce more format variant.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




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

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -101,6 +101,8 @@ 
 	int inlined;
 	long entry_size; /* size of index headers. Differs in v1 v.s. v2 format
 	                  */
+	char format_version; /* size of index headers. Differs in v1 v.s. v2
+	                        format */
 };
 
 static Py_ssize_t index_length(const indexObject *self)
@@ -129,6 +131,9 @@ 
 /* A Revlogv2 index entry is 96 bytes long. */
 static const long v2_entry_size = 96;
 
+static const long format_v1 = 1; /* Internal only, could be any number */
+static const long format_v2 = 2; /* Internal only, could be any number */
+
 static void raise_revlog_error(void)
 {
 	PyObject *mod = NULL, *dict = NULL, *errclass = NULL;
@@ -2757,12 +2762,14 @@ 
 	}
 
 	if (revlogv2 && PyObject_IsTrue(revlogv2)) {
+		self->format_version = format_v2;
 		self->entry_size = v2_entry_size;
 	} else {
+		self->format_version = format_v1;
 		self->entry_size = v1_entry_size;
 	}
 
-	if (self->entry_size == v1_entry_size) {
+	if (self->format_version == format_v1) {
 		self->nullentry =
 		    Py_BuildValue(PY23("iiiiiiis#", "iiiiiiiy#"), 0, 0, 0, -1,
 		                  -1, -1, -1, nullid, self->nodelen);