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, SyncData};
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    StateAttachment = 5,
41}
42
43pub(crate) fn pack_container_spec() -> PackContainerSpec {
44    PackContainerSpec {
45        magic: b"LMPK",
46        version: 3,
47    }
48}
49
50impl ObjectType {
51    pub(crate) fn from_u8(value: u8) -> Option<Self> {
52        match value {
53            0 => Some(ObjectType::Blob),
54            1 => Some(ObjectType::Tree),
55            2 => Some(ObjectType::State),
56            3 => Some(ObjectType::Action),
57            4 => Some(ObjectType::Delta),
58            5 => Some(ObjectType::StateAttachment),
59            _ => None,
60        }
61    }
62}
63
64/// Pack statistics.
65#[derive(Debug, Clone, Copy)]
66pub struct PackStats {
67    pub object_count: u64,
68    pub total_uncompressed: u64,
69    pub total_compressed: u64,
70    pub delta_count: u64,
71    pub compression_ratio: f64,
72}