Mercurial > hg-stable
changeset 51219:51cc12158f97
rust-index: add `pack_header` support
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 03 Aug 2023 10:28:10 +0200 |
parents | 4e6620b7fbbb |
children | 44fbb7dfb563 |
files | rust/hg-core/src/revlog/index.rs rust/hg-cpython/src/revlog.rs |
diffstat | 2 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs Mon Oct 30 10:34:48 2023 +0100 +++ b/rust/hg-core/src/revlog/index.rs Thu Aug 03 10:28:10 2023 +0200 @@ -426,6 +426,10 @@ Ok(()) } + pub fn pack_header(&self, header: i32) -> [u8; 4] { + header.to_be_bytes() + } + pub fn remove(&mut self, rev: Revision) -> Result<(), RevlogError> { let offsets = self.get_offsets().clone(); self.bytes.remove(rev, offsets.as_deref())?;
--- a/rust/hg-cpython/src/revlog.rs Mon Oct 30 10:34:48 2023 +0100 +++ b/rust/hg-cpython/src/revlog.rs Thu Aug 03 10:28:10 2023 +0200 @@ -216,7 +216,12 @@ /// return a binary packed version of the header def pack_header(&self, *args, **kw) -> PyResult<PyObject> { - self.call_cindex(py, "pack_header", args, kw) + let rindex = self.index(py).borrow(); + let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); + let packed = PyBytes::new(py, &packed); + let cpacked = self.call_cindex(py, "pack_header", args, kw)?; + assert!(packed.as_object().compare(py, cpacked)?.is_eq()); + Ok(packed.into_object()) } /// get an index entry