# HG changeset patch # User Raphaël Gomès # Date 1687880091 -7200 # Node ID 6ec8387eb0be5c9ceb1542068b65c0b9fc7a4d56 # Parent b4d152a28742dbbd206e12fa3a223cf93fe1df68 rust-index: pass data down to the Rust index This will allow us to start keeping the Rust index synchronized with the cindex as we gradually implement more and more methods in Rust. This will eventually be removed. diff -r b4d152a28742 -r 6ec8387eb0be mercurial/revlog.py --- a/mercurial/revlog.py Tue Jun 27 16:32:09 2023 +0200 +++ b/mercurial/revlog.py Tue Jun 27 17:34:51 2023 +0200 @@ -226,7 +226,7 @@ def parse_index_v1_mixed(data, inline): index, cache = parse_index_v1(data, inline) - return rustrevlog.MixedIndex(index), cache + return rustrevlog.MixedIndex(index, data), cache # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte diff -r b4d152a28742 -r 6ec8387eb0be rust/hg-cpython/src/revlog.rs --- a/rust/hg-cpython/src/revlog.rs Tue Jun 27 16:32:09 2023 +0200 +++ b/rust/hg-cpython/src/revlog.rs Tue Jun 27 17:34:51 2023 +0200 @@ -36,13 +36,20 @@ py_class!(pub class MixedIndex |py| { data cindex: RefCell; + data index: RefCell; data nt: RefCell>; data docket: RefCell>; // Holds a reference to the mmap'ed persistent nodemap data data nodemap_mmap: RefCell>; + // Holds a reference to the mmap'ed persistent index data + data index_mmap: RefCell>; - def __new__(_cls, cindex: PyObject) -> PyResult { - Self::new(py, cindex) + def __new__( + _cls, + cindex: PyObject, + data: PyObject + ) -> PyResult { + Self::new(py, cindex, data) } /// Compatibility layer used for Python consumers needing access to the C index @@ -353,13 +360,22 @@ } impl MixedIndex { - fn new(py: Python, cindex: PyObject) -> PyResult { + fn new( + py: Python, + cindex: PyObject, + data: PyObject, + ) -> PyResult { + // Safety: we keep the buffer around inside the class as `index_mmap` + let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; + Self::create_instance( py, RefCell::new(cindex::Index::new(py, cindex)?), + RefCell::new(hg::index::Index::new(bytes).unwrap()), RefCell::new(None), RefCell::new(None), RefCell::new(None), + RefCell::new(Some(buf)), ) } diff -r b4d152a28742 -r 6ec8387eb0be tests/test-rust-revlog.py --- a/tests/test-rust-revlog.py Tue Jun 27 16:32:09 2023 +0200 +++ b/tests/test-rust-revlog.py Tue Jun 27 17:34:51 2023 +0200 @@ -22,24 +22,24 @@ class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase): def test_heads(self): idx = self.parseindex() - rustidx = revlog.MixedIndex(idx) + rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined) self.assertEqual(rustidx.headrevs(), idx.headrevs()) def test_get_cindex(self): # drop me once we no longer need the method for shortest node idx = self.parseindex() - rustidx = revlog.MixedIndex(idx) + rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined) cidx = rustidx.get_cindex() self.assertTrue(idx is cidx) def test_len(self): idx = self.parseindex() - rustidx = revlog.MixedIndex(idx) + rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined) self.assertEqual(len(rustidx), len(idx)) def test_ancestors(self): idx = self.parseindex() - rustidx = revlog.MixedIndex(idx) + rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined) lazy = LazyAncestors(rustidx, [3], 0, True) # we have two more references to the index: # - in its inner iterator for __contains__ and __bool__