Patchwork D8159: rust-nodemap: add binding for `nodemap_data_incremental`

login
register
mail settings
Submitter phabricator
Date March 10, 2020, 10:52 a.m.
Message ID <179dcba2615d7ecfd1b70cd1a1ff045f@localhost.localdomain>
Download mbox | patch
Permalink /patch/45656/
State Not Applicable
Headers show

Comments

phabricator - March 10, 2020, 10:52 a.m.
Alphare updated this revision to Diff 20658.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8159?vs=20378&id=20658

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8159/new/

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

Patch

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<cindex::Index>;
     data nt: RefCell<Option<NodeTree>>;
+    data docket: RefCell<Option<PyObject>>;
 
     def __new__(_cls, cindex: PyObject) -> PyResult<MixedIndex> {
         Self::new(py, cindex)
@@ -264,6 +265,9 @@ 
         self.inner_nodemap_data_all(py)
     }
 
+    def nodemap_data_incremental(&self) -> PyResult<PyObject> {
+        self.inner_nodemap_data_incremental(py)
+    }
 
 });
 
@@ -273,6 +277,7 @@ 
             py,
             RefCell::new(cindex::Index::new(py, cindex)?),
             RefCell::new(None),
+            RefCell::new(None),
         )
     }
 
@@ -347,6 +352,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<PyObject> {
+        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::<Block>();
+
+        Ok((docket, changed, PyBytes::new(py, &data))
+            .to_py_object(py)
+            .into_object())
+    }
 }
 
 fn revlog_error(py: Python) -> PyErr {