# HG changeset patch # User Raphaël Gomès # Date 1687883094 -7200 # Node ID 65c9032e2e5abefbf1d8331fe433e160c4795578 # Parent 13f58ce702998d7def34d44252e6a6d33c401206 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. diff -r 13f58ce70299 -r 65c9032e2e5a rust/hg-core/src/revlog/index.rs --- 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)] diff -r 13f58ce70299 -r 65c9032e2e5a rust/hg-cpython/src/revlog.rs --- 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 { + if tuple.len(py) < 8 { + // this is better than the panic promised by tup.get_item() + return Err(PyErr::new::( + 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::(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,