diff --git a/git-pack/src/data/output/count/objects/mod.rs b/git-pack/src/data/output/count/objects/mod.rs index 503102f26f0..96e51cf16df 100644 --- a/git-pack/src/data/output/count/objects/mod.rs +++ b/git-pack/src/data/output/count/objects/mod.rs @@ -14,6 +14,7 @@ mod util; mod types; pub use types::{Error, ObjectExpansion, Options, Outcome}; + mod tree; /// The return type used by [`objects()`]. @@ -68,7 +69,7 @@ where iter: objects_ids, size: chunk_size, }; - let seen_objs = dashmap::DashSet::::new(); + let seen_objs = dashmap::DashSet::::default(); let progress = Arc::new(parking_lot::Mutex::new(progress)); parallel::in_parallel( @@ -124,7 +125,7 @@ where Oid: Into + Send, IterErr: std::error::Error + Send, { - let seen_objs = RefCell::new(HashSet::::new()); + let seen_objs = RefCell::new(HashSet::::default()); let (mut buf1, mut buf2) = (Vec::new(), Vec::new()); expand::this( diff --git a/git-pack/src/data/output/count/objects/tree.rs b/git-pack/src/data/output/count/objects/tree.rs index da512c88e42..b5dad1f6d99 100644 --- a/git-pack/src/data/output/count/objects/tree.rs +++ b/git-pack/src/data/output/count/objects/tree.rs @@ -4,10 +4,9 @@ pub mod changes { Visit, }; use git_hash::ObjectId; - use git_object::bstr::BStr; + use git_object::{bstr::BStr, tree::EntryMode}; use crate::data::output::count::objects_impl::util::InsertImmutable; - use git_object::tree::EntryMode; pub struct AllNew<'a, H> { pub objects: Vec, @@ -61,11 +60,13 @@ pub mod changes { pub mod traverse { use git_hash::ObjectId; - use git_object::{bstr::BStr, tree::EntryRef}; + use git_object::{ + bstr::BStr, + tree::{EntryMode, EntryRef}, + }; use git_traverse::tree::{visit::Action, Visit}; use crate::data::output::count::objects_impl::util::InsertImmutable; - use git_object::tree::EntryMode; pub struct AllUnseen<'a, H> { pub non_trees: Vec, diff --git a/git-pack/src/data/output/count/objects/types.rs b/git-pack/src/data/output/count/objects/types.rs index 3dd63dfd12b..f74dc7884a7 100644 --- a/git-pack/src/data/output/count/objects/types.rs +++ b/git-pack/src/data/output/count/objects/types.rs @@ -1,3 +1,8 @@ +use std::{ + convert::TryInto, + hash::{BuildHasher, Hasher}, +}; + /// Information gathered during the run of [`iter_from_objects()`][super::objects()]. #[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] @@ -14,6 +19,32 @@ pub struct Outcome { pub total_objects: usize, } +#[derive(Default, Clone)] +pub struct OidState; + +#[derive(Default, Clone)] +pub struct OidHasher { + digest: u64, +} + +impl Hasher for OidHasher { + fn finish(&self) -> u64 { + self.digest + } + + fn write(&mut self, bytes: &[u8]) { + self.digest = u64::from_be_bytes(bytes[..8].try_into().expect("any git hash has more than 8 bytes")); + } +} + +impl BuildHasher for OidState { + type Hasher = OidHasher; + + fn build_hasher(&self) -> Self::Hasher { + OidHasher::default() + } +} + impl Outcome { pub(in crate::data::output::count) fn aggregate( &mut self, diff --git a/git-pack/src/data/output/count/objects/util.rs b/git-pack/src/data/output/count/objects/util.rs index fe1e282256f..4f580cf1f28 100644 --- a/git-pack/src/data/output/count/objects/util.rs +++ b/git-pack/src/data/output/count/objects/util.rs @@ -8,14 +8,15 @@ mod trait_impls { use dashmap::DashSet; use super::InsertImmutable; + use crate::data::output::count::objects_impl::types::OidState; - impl InsertImmutable for DashSet { + impl InsertImmutable for DashSet { fn insert(&self, item: T) -> bool { self.insert(item) } } - impl InsertImmutable for RefCell> { + impl InsertImmutable for RefCell> { fn insert(&self, item: T) -> bool { self.borrow_mut().insert(item) }