diff --git a/rust/hg-cpython/src/revlog.rs b/rust/hg-cpython/src/revlog.rs --- a/rust/hg-cpython/src/revlog.rs +++ b/rust/hg-cpython/src/revlog.rs @@ -15,7 +15,7 @@ PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject, }; use hg::{ - nodemap::{NodeMapError, NodeTree}, + nodemap::{Block, NodeMapError, NodeTree}, revlog::{nodemap::NodeMap, RevlogIndex}, NodeError, Revision, }; @@ -35,6 +35,7 @@ py_class!(pub class MixedIndex |py| { data cindex: RefCell; data nt: RefCell>; + data docket: RefCell>; def __new__(_cls, cindex: PyObject) -> PyResult { Self::new(py, cindex) @@ -255,6 +256,9 @@ self.inner_nodemap_data_all(py) } + def nodemap_data_incremental(&self) -> PyResult { + self.inner_nodemap_data_incremental(py) + } }); @@ -264,6 +268,7 @@ py, RefCell::new(cindex::Index::new(py, cindex)?), RefCell::new(None), + RefCell::new(None), ) } @@ -338,6 +343,28 @@ let bytes = PyBytes::new(py, &bytes); Ok(bytes) } + + /// Returns the last saved docket along with the size of any changed data + /// (in number of blocks), and said data as bytes. + fn inner_nodemap_data_incremental( + &self, + py: Python, + ) -> PyResult { + let docket = self.docket(py).borrow(); + let docket = match docket.as_ref() { + Some(d) => d, + None => return Ok(py.None()), + }; + + let node_tree = self.get_nodetree(py)?.borrow_mut().take().unwrap(); + let masked_blocks = node_tree.masked_readonly_blocks(); + let (_, data) = node_tree.into_readonly_and_added_bytes(); + let changed = masked_blocks * std::mem::size_of::(); + + Ok((docket, changed, PyBytes::new(py, &data)) + .to_py_object(py) + .into_object()) + } } fn revlog_error(py: Python) -> PyErr {