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)]
43pub(crate) mod test_pack_download;
44
45#[cfg(test)]
46mod tests {
47    use tracing_subscriber::util::SubscriberInitExt;
48
49    /// CAUTION: This two is same
50    /// 1.
51    /// tracing_subscriber::fmt().init();
52    ///
53    /// 2.
54    /// env::set_var("RUST_LOG", "debug"); // must be set if use `fmt::init()`, or no output
55    /// tracing_subscriber::fmt::init();
56    pub(crate) fn init_logger() {
57        let _ = tracing_subscriber::fmt::Subscriber::builder()
58            .with_target(false)
59            .without_time()
60            .with_level(true)
61            .with_max_level(tracing::Level::DEBUG)
62            .finish()
63            .try_init(); // avoid multi-init
64    }
65}