From patchwork Wed Feb 26 17:37:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D8159: rust-nodemap: add binding for `nodemap_data_incremental` From: phabricator X-Patchwork-Id: 45340 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 26 Feb 2020 17:37:02 +0000 Alphare created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D8159 AFFECTED FILES rust/hg-cpython/src/revlog.rs CHANGE DETAILS To: Alphare, #hg-reviewers Cc: mercurial-devel 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 {