git_pack/lib.rs
1//! Git stores all of its data as _Objects_, which are data along with a hash over all data. Storing objects efficiently
2//! is what git packs are concerned about.
3//!
4//! Packs consist of [data files][data::File] and [index files][index::File]. The latter can be generated from a data file
5//! and make accessing objects within a pack feasible.
6//!
7//! A [Bundle] conveniently combines a data pack alongside its index to allow [finding][Find] objects or verifying the pack.
8//! Objects returned by `.find(…)` are [objects][git_object::Data] which know their pack location in order to speed up
9//! various common operations like creating new packs from existing ones.
10//!
11//! When traversing all objects in a pack, a _delta tree acceleration structure_ can be built from pack data or an index
12//! in order to decompress packs in parallel and without any waste.
13//! ## Feature Flags
14#![cfg_attr(
15 feature = "document-features",
16 cfg_attr(doc, doc = ::document_features::document_features!())
17)]
18#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
19#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
20
21///
22pub mod bundle;
23/// A bundle of pack data and the corresponding pack index
24pub struct Bundle {
25 /// The pack file corresponding to `index`
26 pub pack: data::File,
27 /// The index file corresponding to `pack`
28 pub index: index::File,
29}
30
31///
32pub mod find;
33
34///
35pub mod cache;
36///
37pub mod data;
38
39mod find_traits;
40pub use find_traits::{Find, FindExt};
41
42///
43pub mod index;
44///
45pub mod multi_index;
46
47///
48pub mod verify;
49
50mod mmap {
51 use std::path::Path;
52
53 pub fn read_only(path: &Path) -> std::io::Result<memmap2::Mmap> {
54 let file = std::fs::File::open(path)?;
55 // SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
56 #[allow(unsafe_code)]
57 unsafe {
58 memmap2::Mmap::map(&file)
59 }
60 }
61}
62
63use std::convert::TryInto;
64
65#[inline]
66fn read_u32(b: &[u8]) -> u32 {
67 u32::from_be_bytes(b.try_into().unwrap())
68}
69
70#[inline]
71fn read_u64(b: &[u8]) -> u64 {
72 u64::from_be_bytes(b.try_into().unwrap())
73}