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