Patchwork D8158: rust-nodemap: add binding for `nodemap_data_all`

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

Comments

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

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8158?vs=20377&id=20657

BRANCH
  default

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

REVISION DETAIL
  https://phab.mercurial-scm.org/D8158

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
@@ -260,6 +260,10 @@ 
         }
     }
 
+    def nodemap_data_all(&self) -> PyResult<PyBytes> {
+        self.inner_nodemap_data_all(py)
+    }
+
 
 });
 
@@ -320,6 +324,29 @@ 
     pub fn clone_cindex(&self, py: Python) -> cindex::Index {
         self.cindex(py).borrow().clone_ref(py)
     }
+
+    /// Returns the full nodemap bytes to be written as-is to disk
+    fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> {
+        let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap();
+        let (readonly, bytes) = nodemap.into_readonly_and_added_bytes();
+
+        // If there's anything readonly, we need to build the data again from
+        // scratch
+        let bytes = if readonly.len() > 0 {
+            let mut nt = NodeTree::load_bytes(Box::new(vec![]), 0);
+            self.fill_nodemap(py, &mut nt)?;
+
+            let (readonly, bytes) = nt.into_readonly_and_added_bytes();
+            assert_eq!(readonly.len(), 0);
+
+            bytes
+        } else {
+            bytes
+        };
+
+        let bytes = PyBytes::new(py, &bytes);
+        Ok(bytes)
+    }
 }
 
 fn revlog_error(py: Python) -> PyErr {