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
28 ) -> anyhow::Result<Self> {28 ) -> anyhow::Result<Self> {
29 let meta = cargo_metadata::MetadataCommand::new().exec()?;29 let meta = cargo_metadata::MetadataCommand::new().exec()?;
30 let root = meta.workspace_root.clone();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 let crates_index = Index::new_cargo_default();32 let crates_index = Index::new_cargo_default();
33 let history = (force_history_segmentation33 let history = (force_history_segmentation
34 || matches!(bump, BumpSpec::Auto)34 || matches!(bump, BumpSpec::Auto)
cargo-smart-release/src/git/history.rs+7−6
@@ -30,11 +30,12 @@ pub enum SegmentScope { · 29 unmodified lines
30}30}
31 31
32pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> {32pub 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 let reference = match repo.head()?.peeled()?.kind {35 let reference = match repo.head()?.peeled()?.kind {
35 head::Kind::Detached { .. } => bail!("Refusing to operate on a detached head."),36 head::Kind::Detached { .. } => bail!("Refusing to operate on a detached head."),
36 head::Kind::Unborn { .. } => return Ok(None),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 let mut items = Vec::new();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 message,57 message,
57 tree_id,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 commit_time,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 parent_tree_id,83 parent_tree_id,
83 });84 });
84 }85 }
85 repo.object_cache_size(prev)?;86 // repo.object_cache_size(prev)?;
86 items.sort_by(|lhs, rhs| {87 items.sort_by(|lhs, rhs| {
87 (lhs.commit_time.time as i64 + lhs.commit_time.offset as i64)88 (lhs.commit_time.time as i64 + lhs.commit_time.offset as i64)
88 .cmp(&(rhs.commit_time.time as i64 + rhs.commit_time.offset as i64))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 Filter::Slow(ref components) => {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 let current_data = RefCell::new(item.tree_id);241 let current_data = RefCell::new(item.tree_id);
240 let current = git::easy::TreeRef::from_id_and_data(242 let current = git::easy::TreeRef::from_id_and_data(
241 item.id,243 item.id,
@@ -264,7 +266,6 @@ fn add_item_if_package_changed<'a>( · 22 unmodified lines
264 (Some(_), None) => history.push(item),266 (Some(_), None) => history.push(item),
265 (None, Some(_)) | (None, None) => {}267 (None, Some(_)) | (None, None) => {}
266 };268 };
267 ctx.repo.object_cache_size(prev)?;
268 }269 }
269 };270 };
270 Ok(())271 Ok(())
git-odb/src/store/handle.rs+31−0
@@ -21,6 +21,22 @@ impl<S> Handle<S> { · 20 unmodified lines
21 self.new_object_cache = Some(Arc::new(create));21 self.new_object_cache = Some(Arc::new(create));
22 self22 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
26impl<S> From<S> for Handle<S>42impl<S> From<S> for Handle<S>
@@ -58,6 +74,21 @@ mod find_impl { · 31 unmodified lines
58 use git_pack::cache::Object;74 use git_pack::cache::Object;
59 use std::ops::DerefMut;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 impl<S> crate::pack::Find for Handle<S>92 impl<S> crate::pack::Find for Handle<S>
62 where93 where
63 S: crate::pack::Find,94 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
34 fn apply_environment(mut self) -> Self {34 fn apply_environment(mut self) -> Self {
35 self.state_mut().objects.set_pack_cache(|| {35 self.state_mut().objects.set_pack_cache(|| {
36 #[cfg(not(feature = "max-performance"))]36 #[cfg(not(feature = "max-performance"))]
37 let pack_cache = git_pack::cache::Never;37 {
38 Box::new(git_pack::cache::Never)
39 }
38 #[cfg(feature = "max-performance")]40 #[cfg(feature = "max-performance")]
39 let pack_cache: easy::PackCache = {41 {
40 use std::convert::TryInto;42 use std::convert::TryInto;
41 if std::env::var_os("GITOXIDE_DISABLE_PACK_CACHE").is_some() {43 if std::env::var_os("GITOXIDE_DISABLE_PACK_CACHE").is_some() {
42 Box::new(git_pack::cache::Never)44 Box::new(git_pack::cache::Never)
@@ -63,8 +65,7 @@ pub trait CacheAccessExt: easy::Access + Sized { · 20 unmodified lines
63 } else {65 } else {
64 Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())66 Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())
65 }67 }
66 };68 }
67 pack_cache
68 });69 });
69 self70 self
70 }71 }
git-repository/src/easy/ext/object.rs+1−0
@@ -65,6 +65,7 @@ pub trait ObjectAccessExt: easy::Access + Sized { · 64 unmodified lines
65 fn write_object(&self, object: impl git_object::WriteTo) -> Result<Oid<'_, Self>, object::write::Error> {65 fn write_object(&self, object: impl git_object::WriteTo) -> Result<Oid<'_, Self>, object::write::Error> {
66 use git_odb::Write;66 use git_odb::Write;
67 67
68 // TODO: implement Write on handle and copy hash_kind onto the State for local access.
68 let repo = self.repo()?;69 let repo = self.repo()?;
69 repo.objects70 repo.objects
70 .write(object, repo.hash_kind)71 .write(object, repo.hash_kind)
git-repository/src/easy/mod.rs+0−6
@@ -28,7 +28,6 @@ pub mod borrow; · 27 unmodified lines
28pub mod commit;28pub mod commit;
29pub mod head;29pub mod head;
30pub mod object;30pub mod object;
31pub mod odb;
32pub mod oid;31pub mod oid;
33pub mod reference;32pub mod reference;
34pub mod state;33pub mod state;
@@ -100,11 +99,6 @@ pub struct Reference<'r, A> { · 65 unmodified lines
100 pub(crate) access: &'r A,99 pub(crate) access: &'r A,
101}100}
102 101
103#[cfg(not(feature = "max-performance"))]
104type PackCache = git_pack::cache::Never;
105#[cfg(feature = "max-performance")]
106type PackCache = Box<dyn git_pack::cache::DecodeEntry + Send + 'static>;
107
108/// State for use in `Easy*` to provide mutable parts of a repository such as caches and buffers.102/// State for use in `Easy*` to provide mutable parts of a repository such as caches and buffers.
109///103///
110/// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically104/// 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///
3pub 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
14 easy::State {14 easy::State {
15 buf: RefCell::new(vec![]),15 buf: RefCell::new(vec![]),
16 objects: {16 objects: {
17 if cfg!(feature = "max-performance") {17 #[cfg(feature = "max-performance")]
18 {
18 objects.with_pack_cache(|| Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default()))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 objects23 objects
21 }24 }
22 },25 },
gitoxide-core/src/pack/create.rs+2−2
@@ -199,12 +199,12 @@ where · 198 unmodified lines
199 {199 {
200 let per_thread_object_pack_size = pack_cache_size_in_bytes / thread_count;200 let per_thread_object_pack_size = pack_cache_size_in_bytes / thread_count;
201 if per_thread_object_pack_size >= 10_000 {201 if per_thread_object_pack_size >= 10_000 {
202 handle = handle.with_pack_cache(move || {202 handle.set_pack_cache(move || {
203 Box::new(pack::cache::lru::MemoryCappedHashmap::new(per_thread_object_pack_size))203 Box::new(pack::cache::lru::MemoryCappedHashmap::new(per_thread_object_pack_size))
204 });204 });
205 }205 }
206 if matches!(expansion, ObjectExpansion::TreeDiff) {206 if matches!(expansion, ObjectExpansion::TreeDiff) {
207 handle = handle.with_object_cache(move || {207 handle.set_object_cache(move || {
208 let per_thread_object_cache_size = object_cache_size_in_bytes / thread_count;208 let per_thread_object_cache_size = object_cache_size_in_bytes / thread_count;
209 Box::new(pack::cache::object::MemoryCappedHashmap::new(209 Box::new(pack::cache::object::MemoryCappedHashmap::new(
210 per_thread_object_cache_size,210 per_thread_object_cache_size,