changeset 52824:e7ad174ae58f

rust-pyo3-revlog: _index_nodemap_data_all
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 02 Jan 2025 17:06:31 +0100
parents 09544af536ef
children 6fc1637f0986
files rust/hg-pyo3/src/revlog/mod.rs
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-pyo3/src/revlog/mod.rs	Tue Dec 24 16:11:19 2024 +0100
+++ b/rust/hg-pyo3/src/revlog/mod.rs	Thu Jan 02 17:06:31 2025 +0100
@@ -768,6 +768,35 @@
         })
     }
 
+    /// Returns the full nodemap bytes to be written as-is to disk
+    fn _index_nodemap_data_all(
+        slf: &Bound<'_, Self>,
+        py: Python<'_>,
+    ) -> PyResult<Py<PyBytes>> {
+        Self::with_index_nt_write(slf, |idx, nt| {
+            let old_nt = std::mem::take(nt);
+            let (readonly, bytes) = old_nt.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 =
+                    CoreNodeTree::load_bytes(Box::<Vec<_>>::default(), 0);
+                Self::fill_nodemap(idx, &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.unbind())
+        })
+    }
+
     #[getter]
     fn _index_entry_size(&self) -> usize {
         INDEX_ENTRY_SIZE