git_pack/index/traverse/
types.rs

1use std::{collections::BTreeMap, marker::PhantomData};
2
3/// Statistics regarding object encountered during execution of the [`traverse()`][crate::index::File::traverse()] method.
4#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
5#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
6pub struct Statistics {
7    /// The average over all decoded objects
8    pub average: crate::data::decode::entry::Outcome,
9    /// A mapping of the length of the chain to the amount of objects at that length.
10    ///
11    /// A length of 0 indicates full objects, and everything above that involves the given amount
12    /// of delta objects.
13    pub objects_per_chain_length: BTreeMap<u32, u32>,
14    /// The amount of bytes in all compressed streams, one per entry
15    pub total_compressed_entries_size: u64,
16    /// The amount of bytes in all decompressed streams, one per entry
17    pub total_decompressed_entries_size: u64,
18    /// The amount of bytes occupied by all undeltified, decompressed objects
19    pub total_object_size: u64,
20    /// The amount of bytes occupied by the pack itself, in bytes
21    pub pack_size: u64,
22    /// The amount of objects encountered that where commits
23    pub num_commits: u32,
24    /// The amount of objects encountered that where trees
25    pub num_trees: u32,
26    /// The amount of objects encountered that where tags
27    pub num_tags: u32,
28    /// The amount of objects encountered that where blobs
29    pub num_blobs: u32,
30}
31
32impl Default for Statistics {
33    fn default() -> Self {
34        Statistics {
35            average: crate::data::decode::entry::Outcome::default_from_kind(git_object::Kind::Tree),
36            objects_per_chain_length: Default::default(),
37            total_compressed_entries_size: 0,
38            total_decompressed_entries_size: 0,
39            total_object_size: 0,
40            pack_size: 0,
41            num_blobs: 0,
42            num_commits: 0,
43            num_trees: 0,
44            num_tags: 0,
45        }
46    }
47}
48
49/// The ways to validate decoded objects before passing them to the processor.
50#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
51#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
52pub enum SafetyCheck {
53    /// Don't verify the validity of the checksums stored in the index and pack file
54    SkipFileChecksumVerification,
55
56    /// All of the above, and also don't perform any object checksum verification
57    SkipFileAndObjectChecksumVerification,
58
59    /// All of the above, and only log object decode errors.
60    ///
61    /// Useful if there is a damaged pack and you would like to traverse as many objects as possible.
62    SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError,
63
64    /// Perform all available safety checks before operating on the pack and
65    /// abort if any of them fails
66    All,
67}
68
69impl SafetyCheck {
70    pub(crate) fn file_checksum(&self) -> bool {
71        matches!(self, SafetyCheck::All)
72    }
73    pub(crate) fn object_checksum(&self) -> bool {
74        matches!(self, SafetyCheck::All | SafetyCheck::SkipFileChecksumVerification)
75    }
76    pub(crate) fn fatal_decode_error(&self) -> bool {
77        match self {
78            SafetyCheck::All
79            | SafetyCheck::SkipFileChecksumVerification
80            | SafetyCheck::SkipFileAndObjectChecksumVerification => true,
81            SafetyCheck::SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError => false,
82        }
83    }
84}
85
86impl Default for SafetyCheck {
87    fn default() -> Self {
88        SafetyCheck::All
89    }
90}
91
92/// The way we verify the pack
93#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
94#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
95pub enum Algorithm {
96    /// Build an index to allow decoding each delta and base exactly once, saving a lot of computational
97    /// resource at the expense of resident memory, as we will use an additional `DeltaTree` to accelerate
98    /// delta chain resolution.
99    DeltaTreeLookup,
100    /// We lookup each object similarly to what would happen during normal repository use.
101    /// Uses more compute resources as it will resolve delta chains from back to front, but start right away
102    /// without indexing or investing any memory in indices.
103    ///
104    /// This option may be well suited for big packs in memory-starved system that support memory mapping.
105    Lookup,
106}
107
108impl Default for Algorithm {
109    fn default() -> Self {
110        Algorithm::DeltaTreeLookup
111    }
112}
113
114/// The progress ids used in [`traverse()`][crate::index::File::traverse()] .
115///
116/// Use this information to selectively extract the progress of interest in case the parent application has custom visualization.
117#[derive(Debug, Copy, Clone)]
118pub enum ProgressId {
119    /// A root progress which isn't actually used, but links to the `ProgressId` of the lookup version of the algorithm.
120    WithLookup(PhantomData<super::with_lookup::ProgressId>),
121    /// A root progress which isn't actually used, but links to the `ProgressId` of the indexed version of the algorithm.
122    WithIndex(PhantomData<super::with_index::ProgressId>),
123}