diff --git a/git-pack/src/multi_index/chunk.rs b/git-pack/src/multi_index/chunk.rs index fdb576992b2..c890bfc2a97 100644 --- a/git-pack/src/multi_index/chunk.rs +++ b/git-pack/src/multi_index/chunk.rs @@ -144,11 +144,27 @@ pub mod fanout { /// Information about the oid lookup table. pub mod lookup { + use crate::multi_index; use std::ops::Range; /// The id uniquely identifying the oid lookup table. pub const ID: git_chunk::Id = *b"OIDL"; + /// Return the amount of bytes needed to store the data on disk for the given amount of `entries` + pub fn storage_size(entries: usize, object_hash: git_hash::Kind) -> u64 { + (entries * object_hash.len_in_bytes()) as u64 + } + + pub(crate) fn write( + sorted_entries: &[multi_index::write::Entry], + mut out: impl std::io::Write, + ) -> std::io::Result<()> { + for entry in sorted_entries { + out.write_all(entry.id.as_slice())?; + } + Ok(()) + } + /// Return true if the size of the `offset` range seems to match for a `hash` of the given kind and the amount of objects. pub fn is_valid(offset: &Range, hash: git_hash::Kind, num_objects: u32) -> bool { (offset.end - offset.start) / hash.len_in_bytes() == num_objects as usize diff --git a/git-pack/src/multi_index/write.rs b/git-pack/src/multi_index/write.rs index b37f256b5d3..6c0700deca8 100644 --- a/git-pack/src/multi_index/write.rs +++ b/git-pack/src/multi_index/write.rs @@ -116,6 +116,10 @@ impl multi_index::File { multi_index::chunk::index_names::storage_size(&index_filenames_sorted), ); cf.plan_chunk(multi_index::chunk::fanout::ID, multi_index::chunk::fanout::SIZE as u64); + cf.plan_chunk( + multi_index::chunk::lookup::ID, + multi_index::chunk::lookup::storage_size(entries.len(), object_hash), + ); let bytes_written = Self::write_header( &mut out, @@ -130,6 +134,7 @@ impl multi_index::File { multi_index::chunk::index_names::write(&index_filenames_sorted, &mut chunk_write)? } multi_index::chunk::fanout::ID => multi_index::chunk::fanout::write(&entries, &mut chunk_write)?, + multi_index::chunk::lookup::ID => multi_index::chunk::lookup::write(&entries, &mut chunk_write)?, unknown => unreachable!("BUG: forgot to implement chunk {:?}", std::str::from_utf8(&unknown)), } } diff --git a/git-pack/tests/pack/multi_index.rs b/git-pack/tests/pack/multi_index.rs index 09a6f668265..bb9b3d8dbed 100644 --- a/git-pack/tests/pack/multi_index.rs +++ b/git-pack/tests/pack/multi_index.rs @@ -118,7 +118,6 @@ mod write { use std::sync::atomic::AtomicBool; #[test] - #[ignore] fn from_paths() { let dir = tempfile::TempDir::new().unwrap(); let input_indices = std::fs::read_dir(fixture_path("objects/pack"))