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 utils;
13pub mod waitlist;
14pub mod wrapper;
15use std::sync::{Arc, atomic::AtomicUsize};
16
17use threadpool::ThreadPool;
18
19use crate::{
20    hash::ObjectHash,
21    internal::{
22        object::ObjectTrait,
23        pack::{cache::Caches, waitlist::Waitlist},
24    },
25};
26
27const DEFAULT_TMP_DIR: &str = "./.cache_temp";
28
29/// Representation of a Git pack file in memory.
30pub struct Pack {
31    pub number: usize,
32    pub signature: ObjectHash,
33    pub objects: Vec<Box<dyn ObjectTrait>>,
34    pub pool: Arc<ThreadPool>,
35    pub waitlist: Arc<Waitlist>,
36    pub caches: Arc<Caches>,
37    pub mem_limit: Option<usize>,
38    pub cache_objs_mem: Arc<AtomicUsize>,
39    pub clean_tmp: bool,
40}
41
42#[cfg(test)]
43mod tests {
44    use tracing_subscriber::util::SubscriberInitExt;
45
46    /// CAUTION: This two is same
47    /// 1.
48    /// tracing_subscriber::fmt().init();
49    ///
50    /// 2.
51    /// env::set_var("RUST_LOG", "debug"); // must be set if use `fmt::init()`, or no output
52    /// tracing_subscriber::fmt::init();
53    pub(crate) fn init_logger() {
54        let _ = tracing_subscriber::fmt::Subscriber::builder()
55            .with_target(false)
56            .without_time()
57            .with_level(true)
58            .with_max_level(tracing::Level::DEBUG)
59            .finish()
60            .try_init(); // avoid multi-init
61    }
62}