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