changeset 51192:65c9032e2e5a

rust-index: synchronize append method We now append to the Rust index just as we do to the C index. Future steps will bring the two indexes further together until we can rip the C index entirely when running Rust code.
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 27 Jun 2023 18:24:54 +0200
parents 13f58ce70299
children e79b0a4be3a7
files rust/hg-core/src/revlog/index.rs rust/hg-cpython/src/revlog.rs
diffstat 2 files changed, 58 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs	Mon Sep 18 17:11:11 2023 +0200
+++ b/rust/hg-core/src/revlog/index.rs	Tue Jun 27 18:24:54 2023 +0200
@@ -115,20 +115,20 @@
 }
 
 pub struct RevisionDataParams {
-    flags: u16,
-    data_offset: u64,
-    data_compressed_length: i32,
-    data_uncompressed_length: i32,
-    data_delta_base: i32,
-    link_rev: i32,
-    parent_rev_1: i32,
-    parent_rev_2: i32,
-    node_id: [u8; NODE_BYTES_LENGTH],
-    _sidedata_offset: u64,
-    _sidedata_compressed_length: i32,
-    data_compression_mode: u8,
-    _sidedata_compression_mode: u8,
-    _rank: i32,
+    pub flags: u16,
+    pub data_offset: u64,
+    pub data_compressed_length: i32,
+    pub data_uncompressed_length: i32,
+    pub data_delta_base: i32,
+    pub link_rev: i32,
+    pub parent_rev_1: i32,
+    pub parent_rev_2: i32,
+    pub node_id: [u8; NODE_BYTES_LENGTH],
+    pub _sidedata_offset: u64,
+    pub _sidedata_compressed_length: i32,
+    pub data_compression_mode: u8,
+    pub _sidedata_compression_mode: u8,
+    pub _rank: i32,
 }
 
 #[derive(BytesCast)]
--- a/rust/hg-cpython/src/revlog.rs	Mon Sep 18 17:11:11 2023 +0200
+++ b/rust/hg-cpython/src/revlog.rs	Tue Jun 27 18:24:54 2023 +0200
@@ -18,6 +18,7 @@
 };
 use hg::{
     index::IndexHeader,
+    index::{RevisionDataParams, COMPRESSION_MODE_INLINE},
     nodemap::{Block, NodeMapError, NodeTree},
     revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex},
     BaseRevision, Revision, UncheckedRevision,
@@ -145,8 +146,11 @@
 
         // This is ok since we will just add the revision to the index
         let rev = Revision(idx.len() as BaseRevision);
-        idx.append(py, tup)?;
-
+        idx.append(py, tup.clone_ref(py))?;
+        self.index(py)
+            .borrow_mut()
+            .append(py_tuple_to_revision_data_params(py, tup)?)
+            .unwrap();
         self.get_nodetree(py)?.borrow_mut().as_mut().unwrap()
             .insert(&*idx, &node, rev)
             .map_err(|e| nodemap_error(py, e))?;
@@ -361,6 +365,44 @@
     Ok((buf, Box::new(bytes)))
 }
 
+fn py_tuple_to_revision_data_params(
+    py: Python,
+    tuple: PyTuple,
+) -> PyResult<RevisionDataParams> {
+    if tuple.len(py) < 8 {
+        // this is better than the panic promised by tup.get_item()
+        return Err(PyErr::new::<IndexError, _>(
+            py,
+            "tuple index out of range",
+        ));
+    }
+    let offset_or_flags: u64 = tuple.get_item(py, 0).extract(py)?;
+    let node_id = tuple
+        .get_item(py, 7)
+        .extract::<PyBytes>(py)?
+        .data(py)
+        .try_into()
+        .unwrap();
+    let flags = (offset_or_flags & 0xFFFF) as u16;
+    let data_offset = offset_or_flags >> 16;
+    Ok(RevisionDataParams {
+        flags,
+        data_offset,
+        data_compressed_length: tuple.get_item(py, 1).extract(py)?,
+        data_uncompressed_length: tuple.get_item(py, 2).extract(py)?,
+        data_delta_base: tuple.get_item(py, 3).extract(py)?,
+        link_rev: tuple.get_item(py, 4).extract(py)?,
+        parent_rev_1: tuple.get_item(py, 5).extract(py)?,
+        parent_rev_2: tuple.get_item(py, 6).extract(py)?,
+        node_id,
+        _sidedata_offset: 0,
+        _sidedata_compressed_length: 0,
+        data_compression_mode: COMPRESSION_MODE_INLINE,
+        _sidedata_compression_mode: COMPRESSION_MODE_INLINE,
+        _rank: -1,
+    })
+}
+
 impl MixedIndex {
     fn new(
         py: Python,