Skip to main content

git_internal/internal/pack/
mod.rs

1//! Pack file encoder/decoder implementations, caches, waitlists, and stream wrappers that faithfully
2//! follow the [pack-format spec](https://git-scm.com/docs/pack-format).
3
4pub mod cache;
5pub mod cache_object;
6pub mod channel_reader;
7pub mod decode;
8pub mod encode;
9pub mod entry;
10mod index_entry;
11pub mod pack_index;
12pub mod stats;
13pub mod utils;
14pub mod waitlist;
15pub mod wrapper;
16use std::sync::{Arc, atomic::AtomicUsize};
17
18use threadpool::ThreadPool;
19
20use crate::{
21    hash::{HashKind, ObjectHash},
22    internal::{
23        object::ObjectTrait,
24        pack::{cache::Caches, waitlist::Waitlist},
25    },
26};
27
28const DEFAULT_TMP_DIR: &str = "./.cache_temp";
29
30/// Representation of a Git pack file in memory.
31pub struct Pack {
32    /// Repository hash kind used for every object ID, ref-delta base, pack trailer and idx
33    /// checksum this pack touches (explicit; never read from a worker's thread-local).
34    pub hash_kind: HashKind,
35    pub number: usize,
36    pub signature: ObjectHash,
37    pub objects: Vec<Box<dyn ObjectTrait>>,
38    pub pool: Arc<ThreadPool>,
39    pub waitlist: Arc<Waitlist>,
40    pub caches: Arc<Caches>,
41    pub mem_limit: Option<usize>,
42    pub cache_objs_mem: Arc<AtomicUsize>,
43    pub clean_tmp: bool,
44}
45
46#[cfg(test)]
47pub(crate) mod test_pack_download;
48
49#[cfg(test)]
50mod tests {
51    use tracing_subscriber::util::SubscriberInitExt;
52
53    /// CAUTION: This two is same
54    /// 1.
55    /// tracing_subscriber::fmt().init();
56    ///
57    /// 2.
58    /// env::set_var("RUST_LOG", "debug"); // must be set if use `fmt::init()`, or no output
59    /// tracing_subscriber::fmt::init();
60    pub(crate) fn init_logger() {
61        let _ = tracing_subscriber::fmt::Subscriber::builder()
62            .with_target(false)
63            .without_time()
64            .with_level(true)
65            .with_max_level(tracing::Level::DEBUG)
66            .finish()
67            .try_init(); // avoid multi-init
68    }
69}