revlog: introduce an explicit `format_version` member in the index struct
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.
Differential Revision: https://phab.mercurial-scm.org/D10567
--- a/mercurial/cext/revlog.c Mon May 03 12:20:55 2021 +0200
+++ b/mercurial/cext/revlog.c Mon May 03 12:21:05 2021 +0200
@@ -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);