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