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::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    pub number: usize,
33    pub signature: ObjectHash,
34    pub objects: Vec<Box<dyn ObjectTrait>>,
35    pub pool: Arc<ThreadPool>,
36    pub waitlist: Arc<Waitlist>,
37    pub caches: Arc<Caches>,
38    pub mem_limit: Option<usize>,
39    pub cache_objs_mem: Arc<AtomicUsize>,
40    pub clean_tmp: bool,
41}
42
43#[cfg(test)]
44pub(crate) mod test_pack_download;
45
46#[cfg(test)]
47mod tests {
48    use tracing_subscriber::util::SubscriberInitExt;
49
50    /// CAUTION: This two is same
51    /// 1.
52    /// tracing_subscriber::fmt().init();
53    ///
54    /// 2.
55    /// env::set_var("RUST_LOG", "debug"); // must be set if use `fmt::init()`, or no output
56    /// tracing_subscriber::fmt::init();
57    pub(crate) fn init_logger() {
58        let _ = tracing_subscriber::fmt::Subscriber::builder()
59            .with_target(false)
60            .without_time()
61            .with_level(true)
62            .with_max_level(tracing::Level::DEBUG)
63            .finish()
64            .try_init(); // avoid multi-init
65    }
66}