Mercurial > public > mercurial-scm > hg-stable
changeset 52832:88a69ebbba3b
rust-pyo3-revlog: compress
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 03 Jan 2025 00:45:25 +0100 |
parents | acd76143f868 |
children | 503752cc7177 |
files | rust/hg-pyo3/src/revlog/mod.rs |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-pyo3/src/revlog/mod.rs Thu Jan 02 23:59:26 2025 +0100 +++ b/rust/hg-pyo3/src/revlog/mod.rs Fri Jan 03 00:45:25 2025 +0100 @@ -305,6 +305,31 @@ }) } + fn compress( + slf: &Bound<'_, Self>, + py: Python<'_>, + data: &Bound<'_, PyAny>, + ) -> PyResult<Py<PyTuple>> { + Self::with_core_read(slf, |_self_ref, irl| { + // Safety: we only hold on to the data for as long as `_buf` + // is alive + let (_buf, data) = unsafe { take_buffer_with_slice(data)? }; + let compressed = + irl.compress(&data).map_err(revlog_error_from_msg)?; + let compressed = compressed.as_deref(); + let header = if compressed.is_some() { + PyBytes::new(py, &b""[..]) + } else { + PyBytes::new(py, &b"u"[..]) + }; + Ok(PyTuple::new( + py, + &[header, PyBytes::new(py, compressed.unwrap_or(&data))], + )? + .unbind()) + }) + } + fn reading(slf: &Bound<'_, Self>) -> PyResult<ReadingContextManager> { Ok(ReadingContextManager { inner_revlog: slf.clone().unbind(),