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