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