History

Add odb handle to state (#266)

Sebastian Thiel committed 4 years ago

Commit 4e38da31 parent 93db4a52 files · +10 −9Browse files

Unified · Split

2 files
  1. git-repository/src/easy/mod.rs +2 −1
  2. git-repository/src/easy/state.rs +8 −8
git-repository/src/easy/mod.rs+2−1
@@ -112,8 +112,9 @@ type PackCache = Box<dyn git_pack::cache::DecodeEntry + Send + 'static>; · 111 unmodified lines
112/// those who experiment with workloads to get speed boosts of 2x or more.112/// those who experiment with workloads to get speed boosts of 2x or more.
113pub struct State {113pub struct State {
114 /// As the packed-buffer may hold onto a memory map, so ideally this State is freed after use instead of keeping it around114 /// As the packed-buffer may hold onto a memory map, so ideally this State is freed after use instead of keeping it around
115 /// for too long. At least `packed_refs` is lazily initialized.115 /// for too long. At least `packed_refs` is lazily initialized though.
116 refs: crate::RefStore,116 refs: crate::RefStore,
117 objects: crate::OdbHandle,
117 pack_cache: RefCell<PackCache>,118 pack_cache: RefCell<PackCache>,
118 object_cache: RefCell<Option<object::cache::MemoryCappedHashmap>>,119 object_cache: RefCell<Option<object::cache::MemoryCappedHashmap>>,
119 buf: RefCell<Vec<u8>>,120 buf: RefCell<Vec<u8>>,
git-repository/src/easy/state.rs+8−8
@@ -1,17 +1,16 @@
1//!1//!
2use std::cell::{Ref, RefCell, RefMut};2use std::cell::{Ref, RefCell, RefMut};
3 3
4use crate::{easy, easy::borrow, Repository};4use crate::{easy, easy::borrow};
5 5
6impl Clone for easy::State {6impl Clone for easy::State {
7 fn clone(&self) -> Self {7 fn clone(&self) -> Self {
8 self.refs.clone().into()8 easy::State::from_refs_and_objects(self.refs.clone(), self.objects.clone())
9 }9 }
10}10}
11 11
12// TODO: Expand this as needed as more higher-level stores exist (i.e. odb)12impl easy::State {
13impl From<crate::RefStore> for easy::State {13 pub(crate) fn from_refs_and_objects(refs: crate::RefStore, objects: crate::OdbHandle) -> Self {
14 fn from(refs: crate::RefStore) -> Self {
15 easy::State {14 easy::State {
16 #[cfg(not(feature = "max-performance"))]15 #[cfg(not(feature = "max-performance"))]
17 pack_cache: RefCell::new(git_pack::cache::Never),16 pack_cache: RefCell::new(git_pack::cache::Never),
@@ -19,14 +18,15 @@ impl From<crate::RefStore> for easy::State { · 1 unmodified line
19 pack_cache: RefCell::new(Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())),18 pack_cache: RefCell::new(Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())),
20 object_cache: RefCell::new(None),19 object_cache: RefCell::new(None),
21 buf: RefCell::new(vec![]),20 buf: RefCell::new(vec![]),
21 objects,
22 refs,22 refs,
23 }23 }
24 }24 }
25}25}
26 26
27impl From<&Repository> for easy::State {27impl From<&crate::Repository> for easy::State {
28 fn from(repo: &Repository) -> Self {28 fn from(repo: &crate::Repository) -> Self {
29 repo.refs.clone().into()29 easy::State::from_refs_and_objects(repo.refs.clone(), repo.odb.to_handle_shared())
30 }30 }
31}31}
32 32