pub fn materialize<'a>(
pack: &[u8],
index: &'a mut [MaterializedEntry],
arena: &'a mut [u8],
scratch: &mut [u8],
window: &mut [u8; 32768],
limits: MaterializeLimits,
) -> Result<MaterializedPack<'a>>Expand description
Import a checksummed, non-thin SHA-1 pack into caller-owned index/body storage. Index needs object_count slots; excess slots remain untouched. Each pass resets the reader and can resolve backward OFS or forward REF deltas against earlier materialized objects. Depth, instruction, inflation, pass and work limits are explicit; missing/external bases fail rather than doing I/O.
The ID index uses iterative heap sort, with constant stack space. Resolution charges every metadata probe and tree-validation read against explicit work budgets, and may reinflate entries across passes. Discard partial storage on error; a retry reinitializes the index. No allocation, recursion or platform I/O is used.
use git_zero_core::{Snapshot, ObjectKind, object::Commit, io::SliceWriter, pack,
zlib::{InflateLimits, WINDOW_SIZE}};
let mut tree = [0; 256];
let mut commit = [0; 512];
let source = Snapshot::new(&[], &mut tree, &mut commit)?;
let mut wire = [0; 2048];
let mut output = SliceWriter::new(&mut wire);
pack::write(&source, &mut output)?;
let mut index = [pack::MaterializedEntry::default(); 2];
let mut arena = [0; 1024];
let mut scratch = [0; 512];
let mut window = [0; WINDOW_SIZE];
let limits = pack::MaterializeLimits {
inflate: InflateLimits { max_output: 512, max_ratio: 1024, ratio_slack: 64 },
delta: pack::DeltaLimits { max_output: 512, max_instructions: 512, max_depth: 64 },
max_passes: 65,
max_decoded_bytes_per_pass: 1024,
max_base_probes: 4096,
max_tree_validation_bytes: 4096,
};
let objects = pack::materialize(output.as_bytes(), &mut index, &mut arena,
&mut scratch, &mut window, limits)?;
let head = objects.entries().iter().find(|entry| entry.kind() == Ok(ObjectKind::Commit)).unwrap();
let commit = Commit::parse(objects.find(head.id()).unwrap().data)?;
assert_eq!(objects.find(commit.tree()).unwrap().kind, ObjectKind::Tree);