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

login
register
mail settings
Submitter phabricator
Date Feb. 28, 2020, 6:53 p.m.
Message ID <76ce563a58b7e3624994f0932d092bdf@localhost.localdomain>
Download mbox | patch
Permalink /patch/45383/
State Not Applicable
Headers show

Comments

phabricator - Feb. 28, 2020, 6:53 p.m.
marmoute updated this revision to Diff 20377.

REPOSITORY
  rHG Mercurial

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

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 {