gix_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 = "serde", 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(gix_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(Default, Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
51#[cfg_attr(feature = "serde", 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 #[default]
67 All,
68}
69
70impl SafetyCheck {
71 pub(crate) fn file_checksum(&self) -> bool {
72 matches!(self, SafetyCheck::All)
73 }
74 pub(crate) fn object_checksum(&self) -> bool {
75 matches!(self, SafetyCheck::All | SafetyCheck::SkipFileChecksumVerification)
76 }
77 pub(crate) fn fatal_decode_error(&self) -> bool {
78 match self {
79 SafetyCheck::All
80 | SafetyCheck::SkipFileChecksumVerification
81 | SafetyCheck::SkipFileAndObjectChecksumVerification => true,
82 SafetyCheck::SkipFileAndObjectChecksumVerificationAndNoAbortOnDecodeError => false,
83 }
84 }
85}
86
87/// The way we verify the pack
88#[derive(Default, Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
89#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
90pub enum Algorithm {
91 /// Build an index to allow decoding each delta and base exactly once, saving a lot of computational
92 /// resource at the expense of resident memory, as we will use an additional `DeltaTree` to accelerate
93 /// delta chain resolution.
94 #[default]
95 DeltaTreeLookup,
96 /// We lookup each object similarly to what would happen during normal repository use.
97 /// Uses more compute resources as it will resolve delta chains from back to front, but start right away
98 /// without indexing or investing any memory in indices.
99 ///
100 /// This option may be well suited for big packs in memory-starved system that support memory mapping.
101 Lookup,
102}
103
104/// The progress ids used in [`traverse()`][crate::index::File::traverse()] .
105///
106/// Use this information to selectively extract the progress of interest in case the parent application has custom visualization.
107#[derive(Debug, Copy, Clone)]
108pub enum ProgressId {
109 /// A root progress which isn't actually used, but links to the `ProgressId` of the lookup version of the algorithm.
110 WithLookup(PhantomData<super::with_lookup::ProgressId>),
111 /// A root progress which isn't actually used, but links to the `ProgressId` of the indexed version of the algorithm.
112 WithIndex(PhantomData<super::with_index::ProgressId>),
113}