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 compact_frame;
8mod manager;
9mod pack_builder;
10mod pack_index;
11mod pack_reader;
12mod repack;
13mod shared;
14mod streaming_builder;
15pub(crate) mod varint;
16mod versioned_header;
17
18#[cfg(test)]
19mod pack_tests;
20
21pub use compact_frame::compress_compact_frame;
22pub use manager::PackManager;
23pub use pack_builder::PackBuilder;
24pub use pack_index::PackIndex;
25pub use pack_reader::{EncodedPackSubset, PackReadTier, PackReader};
26pub use repack::{
27    CancellationToken, LoadMonitor, RepackContext, RepackError, RepackHandle, RepackInventory,
28    RepackOperation, RepackOutcome, RepackPolicy, RepackReason, RepackReport, RepackResourceLimits,
29    RepackSchedule, RepackScheduler,
30};
31pub use shared::{
32    PACK_CHECKSUM_LEN, PackContainerSpec, PackEntryHeader, PackObjectId, PackObjectRecord,
33    append_container_checksum, compress_pack_payload, decode_tagged_entry_header,
34    decompress_pack_payload, encode_tagged_entry, encode_tagged_entry_parts, has_zstd_magic,
35    try_decode_tagged_entry_header, verify_container, verify_container_layout,
36    write_container_header,
37};
38pub use streaming_builder::{StreamingPackBuilder, SyncData};
39
40/// Object type for pack entries.
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
42#[repr(u8)]
43pub enum ObjectType {
44    Blob = 0,
45    Tree = 1,
46    State = 2,
47    Action = 3,
48    Delta = 4,
49    StateAttachment = 5,
50    SnapshotCommit = 6,
51    TimelineOperation = 7,
52}
53
54pub(crate) fn pack_container_spec() -> PackContainerSpec {
55    PackContainerSpec {
56        magic: b"LMPK",
57        version: 3,
58    }
59}
60
61impl ObjectType {
62    pub(crate) fn from_u8(value: u8) -> Option<Self> {
63        match value {
64            0 => Some(ObjectType::Blob),
65            1 => Some(ObjectType::Tree),
66            2 => Some(ObjectType::State),
67            3 => Some(ObjectType::Action),
68            4 => Some(ObjectType::Delta),
69            5 => Some(ObjectType::StateAttachment),
70            6 => Some(ObjectType::SnapshotCommit),
71            7 => Some(ObjectType::TimelineOperation),
72            _ => None,
73        }
74    }
75}
76
77/// Pack statistics.
78#[derive(Debug, Clone, Copy)]
79pub struct PackStats {
80    pub object_count: u64,
81    pub total_uncompressed: u64,
82    pub total_compressed: u64,
83    pub delta_count: u64,
84    pub compression_ratio: f64,
85}