History

Adapt to changes in git-repository (#266)

Sebastian Thiel committed 4 years ago

Commit 3ab9b031 parent 5e7aa169 files · +52 −36Browse files

Unified · Split

9 files
  1. cargo-smart-release/src/context.rs +1 −1
  2. cargo-smart-release/src/git/history.rs +7 −6
  3. git-odb/src/store/handle.rs +31 −0
  4. git-repository/src/easy/ext/cache.rs +5 −4
  5. git-repository/src/easy/ext/object.rs +1 −0
  6. git-repository/src/easy/mod.rs +0 −6
  7. git-repository/src/easy/odb.rs +0 −15
  8. git-repository/src/easy/state.rs +5 −2
  9. gitoxide-core/src/pack/create.rs +2 −2
cargo-smart-release/src/context.rs+1−1
@@ -28,7 +28,7 @@ impl Context { · 27 unmodified lines
2828 ) -> anyhow::Result<Self> {
2929 let meta = cargo_metadata::MetadataCommand::new().exec()?;
3030 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();
3232 let crates_index = Index::new_cargo_default();
3333 let history = (force_history_segmentation
3434 || matches!(bump, BumpSpec::Auto)
cargo-smart-release/src/git/history.rs+7−6
@@ -30,11 +30,12 @@ pub enum SegmentScope { · 29 unmodified lines
3030 }
3131
3232 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);
3435 let reference = match repo.head()?.peeled()?.kind {
3536 head::Kind::Detached { .. } => bail!("Refusing to operate on a detached head."),
3637 head::Kind::Unborn { .. } => return Ok(None),
37− head::Kind::Symbolic(r) => r.attach(repo),
38+ head::Kind::Symbolic(r) => r.attach(&repo),
3839 };
3940
4041 let mut items = Vec::new();
@@ -55,7 +56,7 @@ pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { · 14 unmodified lines
5556 (
5657 message,
5758 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()),
5960 commit_time,
6061 )
6162 };
@@ -82,7 +83,7 @@ pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { · 20 unmodified lines
8283 parent_tree_id,
8384 });
8485 }
85− repo.object_cache_size(prev)?;
86+ // repo.object_cache_size(prev)?;
8687 items.sort_by(|lhs, rhs| {
8788 (lhs.commit_time.time as i64 + lhs.commit_time.offset as i64)
8889 .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
235236 };
236237 }
237238 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);
239241 let current_data = RefCell::new(item.tree_id);
240242 let current = git::easy::TreeRef::from_id_and_data(
241243 item.id,
@@ -264,7 +266,6 @@ fn add_item_if_package_changed<'a>( · 22 unmodified lines
264266 (Some(_), None) => history.push(item),
265267 (None, Some(_)) | (None, None) => {}
266268 };
267− ctx.repo.object_cache_size(prev)?;
268269 }
269270 };
270271 Ok(())
git-odb/src/store/handle.rs+31−0
@@ -21,6 +21,22 @@ impl<S> Handle<S> { · 20 unmodified lines
2121 self.new_object_cache = Some(Arc::new(create));
2222 self
2323 }
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+ }
2440 }
2541
2642 impl<S> From<S> for Handle<S>
@@ -58,6 +74,21 @@ mod find_impl { · 31 unmodified lines
5874 use git_pack::cache::Object;
5975 use std::ops::DerefMut;
6076
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+
6192 impl<S> crate::pack::Find for Handle<S>
6293 where
6394 S: crate::pack::Find,
git-repository/src/easy/ext/cache.rs+5−4
@@ -34,9 +34,11 @@ pub trait CacheAccessExt: easy::Access + Sized { · 33 unmodified lines
3434 fn apply_environment(mut self) -> Self {
3535 self.state_mut().objects.set_pack_cache(|| {
3636 #[cfg(not(feature = "max-performance"))]
37− let pack_cache = git_pack::cache::Never;
37+ {
38+ Box::new(git_pack::cache::Never)
39+ }
3840 #[cfg(feature = "max-performance")]
39− let pack_cache: easy::PackCache = {
41+ {
4042 use std::convert::TryInto;
4143 if std::env::var_os("GITOXIDE_DISABLE_PACK_CACHE").is_some() {
4244 Box::new(git_pack::cache::Never)
@@ -63,8 +65,7 @@ pub trait CacheAccessExt: easy::Access + Sized { · 20 unmodified lines
6365 } else {
6466 Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())
6567 }
66− };
67− pack_cache
68+ }
6869 });
6970 self
7071 }
git-repository/src/easy/ext/object.rs+1−0
@@ -65,6 +65,7 @@ pub trait ObjectAccessExt: easy::Access + Sized { · 64 unmodified lines
6565 fn write_object(&self, object: impl git_object::WriteTo) -> Result<Oid<'_, Self>, object::write::Error> {
6666 use git_odb::Write;
6767
68+ // TODO: implement Write on handle and copy hash_kind onto the State for local access.
6869 let repo = self.repo()?;
6970 repo.objects
7071 .write(object, repo.hash_kind)
git-repository/src/easy/mod.rs+0−6
@@ -28,7 +28,6 @@ pub mod borrow; · 27 unmodified lines
2828 pub mod commit;
2929 pub mod head;
3030 pub mod object;
31−pub mod odb;
3231 pub mod oid;
3332 pub mod reference;
3433 pub mod state;
@@ -100,11 +99,6 @@ pub struct Reference<'r, A> { · 65 unmodified lines
10099 pub(crate) access: &'r A,
101100 }
102101
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−
108102 /// State for use in `Easy*` to provide mutable parts of a repository such as caches and buffers.
109103 ///
110104 /// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically
git-repository/src/easy/odb.rs+0−15
@@ -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−}
git-repository/src/easy/state.rs+5−2
@@ -14,9 +14,12 @@ impl easy::State { · 13 unmodified lines
1414 easy::State {
1515 buf: RefCell::new(vec![]),
1616 objects: {
17− if cfg!(feature = "max-performance") {
17+ #[cfg(feature = "max-performance")]
18+ {
1819 objects.with_pack_cache(|| Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default()))
19− } else {
20+ }
21+ #[cfg(not(feature = "max-performance"))]
22+ {
2023 objects
2124 }
2225 },
gitoxide-core/src/pack/create.rs+2−2
@@ -199,12 +199,12 @@ where · 198 unmodified lines
199199 {
200200 let per_thread_object_pack_size = pack_cache_size_in_bytes / thread_count;
201201 if per_thread_object_pack_size >= 10_000 {
202− handle = handle.with_pack_cache(move || {
202+ handle.set_pack_cache(move || {
203203 Box::new(pack::cache::lru::MemoryCappedHashmap::new(per_thread_object_pack_size))
204204 });
205205 }
206206 if matches!(expansion, ObjectExpansion::TreeDiff) {
207− handle = handle.with_object_cache(move || {
207+ handle.set_object_cache(move || {
208208 let per_thread_object_cache_size = object_cache_size_in_bytes / thread_count;
209209 Box::new(pack::cache::object::MemoryCappedHashmap::new(
210210 per_thread_object_cache_size,