Mercurial > public > mercurial-scm > hg-stable
changeset 52833:503752cc7177
rust-pyo3-revlog: split_inline
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 03 Jan 2025 00:59:50 +0100 |
parents | 88a69ebbba3b |
children | d90a78ca0bdd |
files | rust/hg-pyo3/src/revlog/mod.rs |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-pyo3/src/revlog/mod.rs Fri Jan 03 00:45:25 2025 +0100 +++ b/rust/hg-pyo3/src/revlog/mod.rs Fri Jan 03 00:59:50 2025 +0100 @@ -7,6 +7,7 @@ // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. #![allow(non_snake_case)] +use hg::revlog::index::IndexHeader; use hg::revlog::nodemap::Block; use hg::utils::files::get_bytes_from_path; use pyo3::buffer::PyBuffer; @@ -330,6 +331,29 @@ }) } + #[pyo3(signature = (tr, header, new_index_file_path=None))] + fn split_inline( + slf: &Bound<'_, Self>, + py: Python<'_>, + tr: PyObject, + header: i32, + new_index_file_path: Option<&Bound<'_, PyBytes>>, + ) -> PyResult<Py<PyBytes>> { + // Also unused in Python, TODO clean this up. + let _ = tr; + + Self::with_core_write(slf, |_self_ref, mut irl| { + let new_index_file_path = new_index_file_path + .map(|path| get_path_from_bytes(path.as_bytes()).to_owned()); + let header = IndexHeader::parse(&header.to_be_bytes()) + .expect("invalid header bytes"); + let old_path = irl + .split_inline(header, new_index_file_path) + .map_err(revlog_error_from_msg)?; + Ok(PyBytes::new(py, &get_bytes_from_path(old_path)).unbind()) + }) + } + fn reading(slf: &Bound<'_, Self>) -> PyResult<ReadingContextManager> { Ok(ReadingContextManager { inner_revlog: slf.clone().unbind(),