Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-cpython/src/revlog.rs @ 51211:6ec8387eb0be
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.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 27 Jun 2023 17:34:51 +0200 |
parents | 8c4e8d06432e |
children | 13f58ce70299 |
line wrap: on
line diff
--- 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<cindex::Index>; + data index: RefCell<hg::index::Index>; data nt: RefCell<Option<NodeTree>>; data docket: RefCell<Option<PyObject>>; // Holds a reference to the mmap'ed persistent nodemap data data nodemap_mmap: RefCell<Option<PyBuffer>>; + // Holds a reference to the mmap'ed persistent index data + data index_mmap: RefCell<Option<PyBuffer>>; - def __new__(_cls, cindex: PyObject) -> PyResult<MixedIndex> { - Self::new(py, cindex) + def __new__( + _cls, + cindex: PyObject, + data: PyObject + ) -> PyResult<MixedIndex> { + 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<MixedIndex> { + fn new( + py: Python, + cindex: PyObject, + data: PyObject, + ) -> PyResult<MixedIndex> { + // 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)), ) }