diff mercurial/cext/revlog.c @ 47279:9d1a8829f959

revlog: signal which revlog index are compatible with Rust Otherwise, Rust may treat python object like `cindex` object, leading to trouble. The new attribute is an integer because I expect we might need a flag field in the future. As a start we get the rust code to raise a clear TypeError. We will use the information in a smarter way in the next changesets. Differential Revision: https://phab.mercurial-scm.org/D10665
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 04 May 2021 14:16:26 +0200
parents 07641bafa646
children 8a6e6b62b9a3
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Tue May 04 11:19:48 2021 +0200
+++ b/mercurial/cext/revlog.c	Tue May 04 14:16:26 2021 +0200
@@ -101,8 +101,10 @@
 	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 */
+	long rust_ext_compat; /* compatibility with being used in rust
+	                         extensions */
+	char format_version;  /* size of index headers. Differs in v1 v.s. v2
+	                         format */
 };
 
 static Py_ssize_t index_length(const indexObject *self)
@@ -2769,6 +2771,7 @@
 	self->offsets = NULL;
 	self->nodelen = 20;
 	self->nullentry = NULL;
+	self->rust_ext_compat = 1;
 
 	revlogv2 = NULL;
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", kwlist,
@@ -2941,6 +2944,8 @@
 static PyMemberDef index_members[] = {
     {"entry_size", T_LONG, offsetof(indexObject, entry_size), 0,
      "size of an index entry"},
+    {"rust_ext_compat", T_LONG, offsetof(indexObject, rust_ext_compat), 0,
+     "size of an index entry"},
     {NULL} /* Sentinel */
 };