rust-index: add `pack_header` support
authorRaphaël Gomès <rgomes@octobus.net>
Thu, 03 Aug 2023 10:28:10 +0200
changeset 51219 51cc12158f97
parent 51218 4e6620b7fbbb
child 51220 44fbb7dfb563
rust-index: add `pack_header` support
rust/hg-core/src/revlog/index.rs
rust/hg-cpython/src/revlog.rs
--- 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