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 { + 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 { + 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 {