Unified · Split
| @@ -28,7 +28,7 @@ impl Context { · 27 unmodified lines | ||
| 28 | 28 | ) -> anyhow::Result<Self> { |
| 29 | 29 | let meta = cargo_metadata::MetadataCommand::new().exec()?; |
| 30 | 30 | let root = meta.workspace_root.clone(); |
| 31 | − let repo = git::discover(&root)?.into_easy().apply_environment()?; | |
| 31 | + let repo = git::discover(&root)?.into_easy().apply_environment(); | |
| 32 | 32 | let crates_index = Index::new_cargo_default(); |
| 33 | 33 | let history = (force_history_segmentation |
| 34 | 34 | || matches!(bump, BumpSpec::Auto) |
| @@ -30,11 +30,12 @@ pub enum SegmentScope { · 29 unmodified lines | ||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { |
| 33 | − let prev = repo.object_cache_size(64 * 1024)?; | |
| 33 | + let mut repo = repo.clone(); | |
| 34 | + repo.object_cache_size(64 * 1024); | |
| 34 | 35 | let reference = match repo.head()?.peeled()?.kind { |
| 35 | 36 | head::Kind::Detached { .. } => bail!("Refusing to operate on a detached head."), |
| 36 | 37 | head::Kind::Unborn { .. } => return Ok(None), |
| 37 | − head::Kind::Symbolic(r) => r.attach(repo), | |
| 38 | + head::Kind::Symbolic(r) => r.attach(&repo), | |
| 38 | 39 | }; |
| 39 | 40 | |
| 40 | 41 | let mut items = Vec::new(); |
| @@ -55,7 +56,7 @@ pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { · 14 unmodified lines | ||
| 55 | 56 | ( |
| 56 | 57 | message, |
| 57 | 58 | tree_id, |
| 58 | − parent_commit_id.map(|id| id.attach(repo).object().expect("present").to_commit().tree()), | |
| 59 | + parent_commit_id.map(|id| id.attach(&repo).object().expect("present").to_commit().tree()), | |
| 59 | 60 | commit_time, |
| 60 | 61 | ) |
| 61 | 62 | }; |
| @@ -82,7 +83,7 @@ pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { · 20 unmodified lines | ||
| 82 | 83 | parent_tree_id, |
| 83 | 84 | }); |
| 84 | 85 | } |
| 85 | − repo.object_cache_size(prev)?; | |
| 86 | + // repo.object_cache_size(prev)?; | |
| 86 | 87 | items.sort_by(|lhs, rhs| { |
| 87 | 88 | (lhs.commit_time.time as i64 + lhs.commit_time.offset as i64) |
| 88 | 89 | .cmp(&(rhs.commit_time.time as i64 + rhs.commit_time.offset as i64)) |
| @@ -235,7 +236,8 @@ fn add_item_if_package_changed<'a>( · 146 unmodified lines | ||
| 235 | 236 | }; |
| 236 | 237 | } |
| 237 | 238 | Filter::Slow(ref components) => { |
| 238 | − let prev = ctx.repo.object_cache_size(1024 * 1024)?; | |
| 239 | + let mut repo = ctx.repo.clone(); | |
| 240 | + repo.object_cache_size(1024 * 1024); | |
| 239 | 241 | let current_data = RefCell::new(item.tree_id); |
| 240 | 242 | let current = git::easy::TreeRef::from_id_and_data( |
| 241 | 243 | item.id, |
| @@ -264,7 +266,6 @@ fn add_item_if_package_changed<'a>( · 22 unmodified lines | ||
| 264 | 266 | (Some(_), None) => history.push(item), |
| 265 | 267 | (None, Some(_)) | (None, None) => {} |
| 266 | 268 | }; |
| 267 | − ctx.repo.object_cache_size(prev)?; | |
| 268 | 269 | } |
| 269 | 270 | }; |
| 270 | 271 | Ok(()) |
| @@ -21,6 +21,22 @@ impl<S> Handle<S> { · 20 unmodified lines | ||
| 21 | 21 | self.new_object_cache = Some(Arc::new(create)); |
| 22 | 22 | self |
| 23 | 23 | } |
| 24 | + pub fn set_pack_cache(&mut self, create: impl Fn() -> Box<PackCache> + Send + Sync + 'static) { | |
| 25 | + self.pack_cache = Some(RefCell::new(create())); | |
| 26 | + self.new_pack_cache = Some(Arc::new(create)); | |
| 27 | + } | |
| 28 | + pub fn set_object_cache(&mut self, create: impl Fn() -> Box<ObjectCache> + Send + Sync + 'static) { | |
| 29 | + self.object_cache = Some(RefCell::new(create())); | |
| 30 | + self.new_object_cache = Some(Arc::new(create)); | |
| 31 | + } | |
| 32 | + pub fn without_pack_cache(&mut self) { | |
| 33 | + self.pack_cache = None; | |
| 34 | + self.new_pack_cache = None; | |
| 35 | + } | |
| 36 | + pub fn without_object_cache(&mut self) { | |
| 37 | + self.object_cache = None; | |
| 38 | + self.new_object_cache = None; | |
| 39 | + } | |
| 24 | 40 | } |
| 25 | 41 | |
| 26 | 42 | impl<S> From<S> for Handle<S> |
| @@ -58,6 +74,21 @@ mod find_impl { · 31 unmodified lines | ||
| 58 | 74 | use git_pack::cache::Object; |
| 59 | 75 | use std::ops::DerefMut; |
| 60 | 76 | |
| 77 | + impl<S> crate::Find for Handle<S> | |
| 78 | + where | |
| 79 | + S: crate::pack::Find, | |
| 80 | + { | |
| 81 | + type Error = S::Error; | |
| 82 | + | |
| 83 | + fn contains(&self, id: impl AsRef<oid>) -> bool { | |
| 84 | + self.store.contains(id) | |
| 85 | + } | |
| 86 | + | |
| 87 | + fn try_find<'a>(&self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, Self::Error> { | |
| 88 | + git_pack::Find::try_find(self, id, buffer).map(|t| t.map(|t| t.0)) | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 61 | 92 | impl<S> crate::pack::Find for Handle<S> |
| 62 | 93 | where |
| 63 | 94 | S: crate::pack::Find, |
| @@ -34,9 +34,11 @@ pub trait CacheAccessExt: easy::Access + Sized { · 33 unmodified lines | ||
| 34 | 34 | fn apply_environment(mut self) -> Self { |
| 35 | 35 | self.state_mut().objects.set_pack_cache(|| { |
| 36 | 36 | #[cfg(not(feature = "max-performance"))] |
| 37 | − let pack_cache = git_pack::cache::Never; | |
| 37 | + { | |
| 38 | + Box::new(git_pack::cache::Never) | |
| 39 | + } | |
| 38 | 40 | #[cfg(feature = "max-performance")] |
| 39 | − let pack_cache: easy::PackCache = { | |
| 41 | + { | |
| 40 | 42 | use std::convert::TryInto; |
| 41 | 43 | if std::env::var_os("GITOXIDE_DISABLE_PACK_CACHE").is_some() { |
| 42 | 44 | Box::new(git_pack::cache::Never) |
| @@ -63,8 +65,7 @@ pub trait CacheAccessExt: easy::Access + Sized { · 20 unmodified lines | ||
| 63 | 65 | } else { |
| 64 | 66 | Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default()) |
| 65 | 67 | } |
| 66 | − }; | |
| 67 | − pack_cache | |
| 68 | + } | |
| 68 | 69 | }); |
| 69 | 70 | self |
| 70 | 71 | } |
| @@ -65,6 +65,7 @@ pub trait ObjectAccessExt: easy::Access + Sized { · 64 unmodified lines | ||
| 65 | 65 | fn write_object(&self, object: impl git_object::WriteTo) -> Result<Oid<'_, Self>, object::write::Error> { |
| 66 | 66 | use git_odb::Write; |
| 67 | 67 | |
| 68 | + // TODO: implement Write on handle and copy hash_kind onto the State for local access. | |
| 68 | 69 | let repo = self.repo()?; |
| 69 | 70 | repo.objects |
| 70 | 71 | .write(object, repo.hash_kind) |
| @@ -28,7 +28,6 @@ pub mod borrow; · 27 unmodified lines | ||
| 28 | 28 | pub mod commit; |
| 29 | 29 | pub mod head; |
| 30 | 30 | pub mod object; |
| 31 | −pub mod odb; | |
| 32 | 31 | pub mod oid; |
| 33 | 32 | pub mod reference; |
| 34 | 33 | pub mod state; |
| @@ -100,11 +99,6 @@ pub struct Reference<'r, A> { · 65 unmodified lines | ||
| 100 | 99 | pub(crate) access: &'r A, |
| 101 | 100 | } |
| 102 | 101 | |
| 103 | −#[cfg(not(feature = "max-performance"))] | |
| 104 | −type PackCache = git_pack::cache::Never; | |
| 105 | −#[cfg(feature = "max-performance")] | |
| 106 | −type PackCache = Box<dyn git_pack::cache::DecodeEntry + Send + 'static>; | |
| 107 | − | |
| 108 | 102 | /// State for use in `Easy*` to provide mutable parts of a repository such as caches and buffers. |
| 109 | 103 | /// |
| 110 | 104 | /// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically |
| @@ -1,15 +0,0 @@ | ||
| 1 | −//! | |
| 2 | −/// | |
| 3 | −pub mod refresh { | |
| 4 | − use crate::easy; | |
| 5 | − | |
| 6 | − /// The error returned by [`RepositoryAccessExt::refresh_object_database(…)`][easy::ext::RepositoryAccessExt::refresh_object_database()]. | |
| 7 | − #[derive(Debug, thiserror::Error)] | |
| 8 | − #[allow(missing_docs)] | |
| 9 | − pub enum Error { | |
| 10 | − #[error(transparent)] | |
| 11 | − Refresh(#[from] git_odb::linked::init::Error), | |
| 12 | − #[error(transparent)] | |
| 13 | − BorrowRepoMut(#[from] easy::borrow::repo::Error), | |
| 14 | − } | |
| 15 | −} | |
| @@ -14,9 +14,12 @@ impl easy::State { · 13 unmodified lines | ||
| 14 | 14 | easy::State { |
| 15 | 15 | buf: RefCell::new(vec![]), |
| 16 | 16 | objects: { |
| 17 | − if cfg!(feature = "max-performance") { | |
| 17 | + #[cfg(feature = "max-performance")] | |
| 18 | + { | |
| 18 | 19 | objects.with_pack_cache(|| Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())) |
| 19 | − } else { | |
| 20 | + } | |
| 21 | + #[cfg(not(feature = "max-performance"))] | |
| 22 | + { | |
| 20 | 23 | objects |
| 21 | 24 | } |
| 22 | 25 | }, |
| @@ -199,12 +199,12 @@ where · 198 unmodified lines | ||
| 199 | 199 | { |
| 200 | 200 | let per_thread_object_pack_size = pack_cache_size_in_bytes / thread_count; |
| 201 | 201 | if per_thread_object_pack_size >= 10_000 { |
| 202 | − handle = handle.with_pack_cache(move || { | |
| 202 | + handle.set_pack_cache(move || { | |
| 203 | 203 | Box::new(pack::cache::lru::MemoryCappedHashmap::new(per_thread_object_pack_size)) |
| 204 | 204 | }); |
| 205 | 205 | } |
| 206 | 206 | if matches!(expansion, ObjectExpansion::TreeDiff) { |
| 207 | − handle = handle.with_object_cache(move || { | |
| 207 | + handle.set_object_cache(move || { | |
| 208 | 208 | let per_thread_object_cache_size = object_cache_size_in_bytes / thread_count; |
| 209 | 209 | Box::new(pack::cache::object::MemoryCappedHashmap::new( |
| 210 | 210 | per_thread_object_cache_size, |