Skip to main content

objects/store/pack/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Packfile management for efficient storage.
3//!
4//! Packfiles bundle multiple objects together with delta compression,
5//! achieving 50-70% space savings for repositories with many similar objects.
6
7mod manager;
8mod pack_builder;
9mod pack_index;
10mod pack_reader;
11mod shared;
12mod streaming_builder;
13pub(crate) mod varint;
14
15#[cfg(test)]
16mod pack_tests;
17
18pub use manager::PackManager;
19pub use pack_builder::PackBuilder;
20pub use pack_index::PackIndex;
21pub use pack_reader::PackReader;
22pub use shared::{
23    PACK_CHECKSUM_LEN, PackContainerSpec, PackEntryHeader, PackObjectId, PackObjectRecord,
24    append_container_checksum, compress_pack_payload, decode_tagged_entry_header,
25    decompress_pack_payload, encode_tagged_entry, encode_tagged_entry_parts, has_zstd_magic,
26    try_decode_tagged_entry_header, verify_container, write_container_header,
27};
28pub use streaming_builder::StreamingPackBuilder;
29
30/// Object type for pack entries.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
32#[repr(u8)]
33pub enum ObjectType {
34    Blob = 0,
35    Tree = 1,
36    State = 2,
37    Action = 3,
38    Delta = 4,
39}
40
41pub(crate) fn pack_container_spec() -> PackContainerSpec {
42    PackContainerSpec {
43        magic: b"LMPK",
44        version: 2,
45    }
46}
47
48impl ObjectType {
49    pub(crate) fn from_u8(value: u8) -> Option<Self> {
50        match value {
51            0 => Some(ObjectType::Blob),
52            1 => Some(ObjectType::Tree),
53            2 => Some(ObjectType::State),
54            3 => Some(ObjectType::Action),
55            4 => Some(ObjectType::Delta),
56            _ => None,
57        }
58    }
59}
60
61/// Pack statistics.
62#[derive(Debug, Clone, Copy)]
63pub struct PackStats {
64    pub object_count: u64,
65    pub total_uncompressed: u64,
66    pub total_compressed: u64,
67    pub delta_count: u64,
68    pub compression_ratio: f64,
69}