Skip to main content

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