diff rust/hg-cpython/src/revlog.rs @ 44508:b581231ae9d1

rust-nodemap: add binding for `nodemap_data_all` Differential Revision: https://phab.mercurial-scm.org/D8158
author Georges Racinet <georges.racinet@octobus.net>
date Wed, 12 Feb 2020 10:51:17 +0100
parents 857cc79247ac
children 5bbf887275b0
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs	Wed Feb 12 10:33:55 2020 +0100
+++ b/rust/hg-cpython/src/revlog.rs	Wed Feb 12 10:51:17 2020 +0100
@@ -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 {