diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/gix-pack/src/index | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-pack/src/index')
-rw-r--r-- | vendor/gix-pack/src/index/access.rs | 2 | ||||
-rw-r--r-- | vendor/gix-pack/src/index/traverse/mod.rs | 40 | ||||
-rw-r--r-- | vendor/gix-pack/src/index/traverse/with_index.rs | 40 | ||||
-rw-r--r-- | vendor/gix-pack/src/index/traverse/with_lookup.rs | 25 | ||||
-rw-r--r-- | vendor/gix-pack/src/index/verify.rs | 13 | ||||
-rw-r--r-- | vendor/gix-pack/src/index/write/encode.rs | 5 | ||||
-rw-r--r-- | vendor/gix-pack/src/index/write/mod.rs | 23 |
7 files changed, 64 insertions, 84 deletions
diff --git a/vendor/gix-pack/src/index/access.rs b/vendor/gix-pack/src/index/access.rs index c384109ac..18fb70e2a 100644 --- a/vendor/gix-pack/src/index/access.rs +++ b/vendor/gix-pack/src/index/access.rs @@ -64,7 +64,7 @@ impl index::File { } /// Returns the object hash at the given index in our list of (sorted) sha1 hashes. - /// The index ranges from 0 to self.num_objects() + /// The index ranges from 0 to `self.num_objects()` /// /// # Panics /// diff --git a/vendor/gix-pack/src/index/traverse/mod.rs b/vendor/gix-pack/src/index/traverse/mod.rs index 68a502bca..83173f904 100644 --- a/vendor/gix-pack/src/index/traverse/mod.rs +++ b/vendor/gix-pack/src/index/traverse/mod.rs @@ -1,6 +1,9 @@ use std::sync::atomic::AtomicBool; -use gix_features::{parallel, progress::Progress}; +use gix_features::{ + parallel, + progress::{Progress, RawProgress}, +}; use crate::index; @@ -79,7 +82,7 @@ impl index::File { pack: &crate::data::File, progress: P, should_interrupt: &AtomicBool, - new_processor: impl Fn() -> Processor + Send + Clone, + processor: Processor, Options { traversal, thread_limit, @@ -91,17 +94,12 @@ impl index::File { P: Progress, C: crate::cache::DecodeEntry, E: std::error::Error + Send + Sync + 'static, - Processor: FnMut( - gix_object::Kind, - &[u8], - &index::Entry, - &mut <P::SubProgress as Progress>::SubProgress, - ) -> Result<(), E>, + Processor: FnMut(gix_object::Kind, &[u8], &index::Entry, &dyn RawProgress) -> Result<(), E> + Send + Clone, F: Fn() -> C + Send + Clone, { match traversal { Algorithm::Lookup => self.traverse_with_lookup( - new_processor, + processor, pack, progress, should_interrupt, @@ -113,10 +111,10 @@ impl index::File { ), Algorithm::DeltaTreeLookup => self.traverse_with_index( pack, - new_processor, + processor, progress, should_interrupt, - crate::index::traverse::with_index::Options { check, thread_limit }, + with_index::Options { check, thread_limit }, ), } } @@ -151,19 +149,18 @@ impl index::File { } #[allow(clippy::too_many_arguments)] - fn decode_and_process_entry<C, P, E>( + fn decode_and_process_entry<C, E>( &self, check: SafetyCheck, pack: &crate::data::File, cache: &mut C, buf: &mut Vec<u8>, - progress: &mut P, - index_entry: &crate::index::Entry, - processor: &mut impl FnMut(gix_object::Kind, &[u8], &index::Entry, &mut P) -> Result<(), E>, + progress: &mut dyn RawProgress, + index_entry: &index::Entry, + processor: &mut impl FnMut(gix_object::Kind, &[u8], &index::Entry, &dyn RawProgress) -> Result<(), E>, ) -> Result<crate::data::decode::entry::Outcome, Error<E>> where C: crate::cache::DecodeEntry, - P: Progress, E: std::error::Error + Send + Sync + 'static, { let pack_entry = pack.entry(index_entry.pack_offset); @@ -192,9 +189,9 @@ impl index::File { check, object_kind, buf, - progress, index_entry, || pack.entry_crc32(index_entry.pack_offset, entry_len), + progress, processor, )?; Ok(entry_stats) @@ -202,17 +199,16 @@ impl index::File { } #[allow(clippy::too_many_arguments)] -fn process_entry<P, E>( +fn process_entry<E>( check: SafetyCheck, object_kind: gix_object::Kind, decompressed: &[u8], - progress: &mut P, - index_entry: &crate::index::Entry, + index_entry: &index::Entry, pack_entry_crc32: impl FnOnce() -> u32, - processor: &mut impl FnMut(gix_object::Kind, &[u8], &index::Entry, &mut P) -> Result<(), E>, + progress: &dyn RawProgress, + processor: &mut impl FnMut(gix_object::Kind, &[u8], &index::Entry, &dyn RawProgress) -> Result<(), E>, ) -> Result<(), Error<E>> where - P: Progress, E: std::error::Error + Send + Sync + 'static, { if check.object_checksum() { diff --git a/vendor/gix-pack/src/index/traverse/with_index.rs b/vendor/gix-pack/src/index/traverse/with_index.rs index 769bbd07f..884277c9d 100644 --- a/vendor/gix-pack/src/index/traverse/with_index.rs +++ b/vendor/gix-pack/src/index/traverse/with_index.rs @@ -59,19 +59,16 @@ impl index::File { pub fn traverse_with_index<P, Processor, E>( &self, pack: &crate::data::File, - new_processor: impl Fn() -> Processor + Send + Clone, + mut processor: Processor, mut progress: P, should_interrupt: &AtomicBool, Options { check, thread_limit }: Options, ) -> Result<Outcome<P>, Error<E>> where P: Progress, - Processor: FnMut( - gix_object::Kind, - &[u8], - &index::Entry, - &mut <P::SubProgress as Progress>::SubProgress, - ) -> Result<(), E>, + Processor: FnMut(gix_object::Kind, &[u8], &index::Entry, &dyn gix_features::progress::RawProgress) -> Result<(), E> + + Send + + Clone, E: std::error::Error + Send + Sync + 'static, { let (verify_result, traversal_result) = parallel::join( @@ -113,29 +110,27 @@ impl index::File { self.object_hash, )?; let mut outcome = digest_statistics(tree.traverse( - |slice, out| pack.entry_slice(slice).map(|entry| out.copy_from_slice(entry)), + |slice, pack| pack.entry_slice(slice), + pack, pack.pack_end() as u64, - new_processor, - |data, - progress, - traverse::Context { - entry: pack_entry, - entry_end, - decompressed: bytes, - state: ref mut processor, - level, - }| { + move |data, + progress, + traverse::Context { + entry: pack_entry, + entry_end, + decompressed: bytes, + level, + }| { let object_kind = pack_entry.header.as_kind().expect("non-delta object"); data.level = level; data.decompressed_size = pack_entry.decompressed_size; data.object_kind = object_kind; data.compressed_size = entry_end - pack_entry.data_offset; data.object_size = bytes.len() as u64; - let result = crate::index::traverse::process_entry( + let result = index::traverse::process_entry( check, object_kind, bytes, - progress, &data.index_entry, || { // TODO: Fix this - we overwrite the header of 'data' which also changes the computed entry size, @@ -146,7 +141,8 @@ impl index::File { .expect("slice pointing into the pack (by now data is verified)"), ) }, - processor, + progress, + &mut processor, ); match result { Err(err @ Error::PackDecode { .. }) if !check.fatal_decode_error() => { @@ -156,7 +152,7 @@ impl index::File { res => res, } }, - crate::cache::delta::traverse::Options { + traverse::Options { object_progress: progress.add_child_with_id("Resolving", ProgressId::DecodedObjects.into()), size_progress: progress.add_child_with_id("Decoding", ProgressId::DecodedBytes.into()), thread_limit, diff --git a/vendor/gix-pack/src/index/traverse/with_lookup.rs b/vendor/gix-pack/src/index/traverse/with_lookup.rs index 509ae4e4f..0165e4e01 100644 --- a/vendor/gix-pack/src/index/traverse/with_lookup.rs +++ b/vendor/gix-pack/src/index/traverse/with_lookup.rs @@ -67,8 +67,8 @@ impl index::File { /// For more details, see the documentation on the [`traverse()`][index::File::traverse()] method. pub fn traverse_with_lookup<P, C, Processor, E, F>( &self, - new_processor: impl Fn() -> Processor + Send + Clone, - pack: &crate::data::File, + mut processor: Processor, + pack: &data::File, mut progress: P, should_interrupt: &AtomicBool, Options { @@ -81,12 +81,9 @@ impl index::File { P: Progress, C: crate::cache::DecodeEntry, E: std::error::Error + Send + Sync + 'static, - Processor: FnMut( - gix_object::Kind, - &[u8], - &index::Entry, - &mut <P::SubProgress as Progress>::SubProgress, - ) -> Result<(), E>, + Processor: FnMut(gix_object::Kind, &[u8], &index::Entry, &dyn gix_features::progress::RawProgress) -> Result<(), E> + + Send + + Clone, F: Fn() -> C + Send + Clone, { let (verify_result, traversal_result) = parallel::join( @@ -133,7 +130,6 @@ impl index::File { move |index| { ( make_pack_lookup_cache(), - new_processor(), Vec::with_capacity(2048), // decode buffer lock(&reduce_progress) .add_child_with_id(format!("thread {index}"), gix_features::progress::UNKNOWN), // per thread progress @@ -146,9 +142,9 @@ impl index::File { input_chunks, thread_limit, state_per_thread, - |entries: &[index::Entry], - (cache, ref mut processor, buf, progress)| - -> Result<Vec<data::decode::entry::Outcome>, Error<_>> { + move |entries: &[index::Entry], + (cache, buf, progress)| + -> Result<Vec<data::decode::entry::Outcome>, Error<_>> { progress.init( Some(entries.len()), gix_features::progress::count_with_decimals("objects", 2), @@ -163,7 +159,7 @@ impl index::File { buf, progress, index_entry, - processor, + &mut processor, ); progress.inc(); let stat = match result { @@ -174,6 +170,9 @@ impl index::File { res => res, }?; stats.push(stat); + if should_interrupt.load(Ordering::Relaxed) { + break; + } } Ok(stats) }, diff --git a/vendor/gix-pack/src/index/verify.rs b/vendor/gix-pack/src/index/verify.rs index 182f816ba..6af352ac9 100644 --- a/vendor/gix-pack/src/index/verify.rs +++ b/vendor/gix-pack/src/index/verify.rs @@ -198,7 +198,7 @@ impl index::File { pack, progress, should_interrupt, - || { + { let mut encode_buf = Vec::with_capacity(2048); move |kind, data, index_entry, progress| { Self::verify_entry(verify_mode, &mut encode_buf, kind, data, index_entry, progress) @@ -231,17 +231,14 @@ impl index::File { } #[allow(clippy::too_many_arguments)] - fn verify_entry<P>( + fn verify_entry( verify_mode: Mode, encode_buf: &mut Vec<u8>, object_kind: gix_object::Kind, buf: &[u8], index_entry: &index::Entry, - progress: &mut P, - ) -> Result<(), integrity::Error> - where - P: Progress, - { + progress: &dyn gix_features::progress::RawProgress, + ) -> Result<(), integrity::Error> { if let Mode::HashCrc32Decode | Mode::HashCrc32DecodeEncode = verify_mode { use gix_object::Kind::*; match object_kind { @@ -260,7 +257,7 @@ impl index::File { .expect("writing to a memory buffer never fails"); if encode_buf.as_slice() != buf { let mut should_return_error = true; - if let gix_object::Kind::Tree = object_kind { + if let Tree = object_kind { if buf.as_bstr().find(b"100664").is_some() || buf.as_bstr().find(b"100640").is_some() { progress.info(format!("Tree object {} would be cleaned up during re-serialization, replacing mode '100664|100640' with '100644'", index_entry.oid)); should_return_error = false diff --git a/vendor/gix-pack/src/index/write/encode.rs b/vendor/gix-pack/src/index/write/encode.rs index 80f0cac61..f1195875c 100644 --- a/vendor/gix-pack/src/index/write/encode.rs +++ b/vendor/gix-pack/src/index/write/encode.rs @@ -111,10 +111,7 @@ pub(crate) fn fanout(iter: impl ExactSizeIterator<Item = u8>) -> [u32; 256] { entries_len } else { idx_and_entry = iter.find(|(_, first_byte)| *first_byte != byte); - upper_bound = idx_and_entry - .as_ref() - .map(|(idx, _)| *idx as u32) - .unwrap_or(entries_len); + upper_bound = idx_and_entry.as_ref().map_or(entries_len, |(idx, _)| *idx as u32); upper_bound } } diff --git a/vendor/gix-pack/src/index/write/mod.rs b/vendor/gix-pack/src/index/write/mod.rs index 39ed0f31e..72a076a85 100644 --- a/vendor/gix-pack/src/index/write/mod.rs +++ b/vendor/gix-pack/src/index/write/mod.rs @@ -83,20 +83,22 @@ impl crate::index::File { /// It should return `None` if the entry cannot be resolved from the pack that produced the `entries` iterator, causing /// the write operation to fail. #[allow(clippy::too_many_arguments)] - pub fn write_data_iter_to_stream<F, F2>( + pub fn write_data_iter_to_stream<F, F2, R, P>( version: crate::index::Version, make_resolver: F, entries: impl Iterator<Item = Result<crate::data::input::Entry, crate::data::input::Error>>, thread_limit: Option<usize>, - mut root_progress: impl Progress, + mut root_progress: P, out: impl io::Write, should_interrupt: &AtomicBool, object_hash: gix_hash::Kind, pack_version: crate::data::Version, ) -> Result<Outcome, Error> where - F: FnOnce() -> io::Result<F2>, - F2: for<'r> Fn(crate::data::EntryRange, &'r mut Vec<u8>) -> Option<()> + Send + Clone, + F: FnOnce() -> io::Result<(F2, R)>, + R: Send + Sync, + F2: for<'r> Fn(crate::data::EntryRange, &'r R) -> Option<&'r [u8]> + Send + Clone, + P: Progress, { if version != crate::index::Version::default() { return Err(Error::Unsupported(version)); @@ -180,12 +182,12 @@ impl crate::index::File { root_progress.inc(); - let resolver = make_resolver()?; + let (resolver, pack) = make_resolver()?; let sorted_pack_offsets_by_oid = { let traverse::Outcome { roots, children } = tree.traverse( resolver, + &pack, pack_entries_end, - || (), |data, _progress, traverse::Context { @@ -250,14 +252,7 @@ impl crate::index::File { } fn modify_base(entry: &mut TreeEntry, pack_entry: &crate::data::Entry, decompressed: &[u8], hash: gix_hash::Kind) { - fn compute_hash(kind: gix_object::Kind, bytes: &[u8], object_hash: gix_hash::Kind) -> gix_hash::ObjectId { - let mut hasher = gix_features::hash::hasher(object_hash); - hasher.update(&gix_object::encode::loose_header(kind, bytes.len())); - hasher.update(bytes); - gix_hash::ObjectId::from(hasher.digest()) - } - let object_kind = pack_entry.header.as_kind().expect("base object as source of iteration"); - let id = compute_hash(object_kind, decompressed, hash); + let id = gix_object::compute_hash(hash, object_kind, decompressed); entry.id = id; } |