Skip to main content

gix_pack/cache/delta/
mod.rs

1/// Returned when using various methods on a [`Tree`]
2#[derive(thiserror::Error, Debug)]
3#[allow(missing_docs)]
4pub enum Error {
5    #[error(
6        "Pack offsets must only increment. The previous pack offset was {last_pack_offset}, the current one is {pack_offset}"
7    )]
8    InvariantIncreasingPackOffset {
9        /// The last seen pack offset
10        last_pack_offset: crate::data::Offset,
11        /// The invariant violating offset
12        pack_offset: crate::data::Offset,
13    },
14}
15///
16/// A tree that allows one-time iteration over all nodes and their children, consuming it in the process,
17/// while being shareable among threads without a lock.
18/// It does this by making the guarantee that iteration only happens once.
19pub struct Tree<T> {
20    /// The root nodes, i.e. base objects
21    // SAFETY invariant: see Item.children
22    root_items: Vec<tree::Item<T>>,
23    /// The child nodes, i.e. those that rely a base object, like ref and ofs delta objects
24    // SAFETY invariant: see Item.children
25    child_items: Vec<tree::Item<T>>,
26    /// The last encountered node was either a root or a child.
27    last_seen: Option<tree::NodeKind>,
28    /// Future child offsets, associating their offset into the pack with their index in the items array.
29    /// (parent_offset, child_index)
30    // SAFETY invariant:
31    //    - None of these child indices should already have parents
32    //      i.e. future_child_offsets[i].1 should never be also found
33    //      in Item.children. Indices should be found here at most once.
34    //    - These indices should be in bounds for tree.child_items.
35    future_child_offsets: Vec<(crate::data::Offset, usize)>,
36    /// Child indices waiting for an in-pack object with the given id to be resolved.
37    ref_child_indices: tree::RefDeltaChildren,
38}
39
40///
41pub mod traverse;
42
43///
44pub mod from_offsets;
45
46/// Types associated with [Tree].
47// kept in separate module to encapsulate unsafety (it has field invariants)
48pub mod tree;