From patchwork Mon May 3 11:49:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D10567: revlog: introduce an explicit `format_version` member in the index struct From: phabricator X-Patchwork-Id: 48884 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Mon, 3 May 2021 11:49:54 +0000 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 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);