1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::cell::{Ref, RefCell, RefMut};
use crate::{easy, easy::borrow, Repository};
impl Clone for easy::State {
fn clone(&self) -> Self {
self.refs.clone().into()
}
}
impl From<crate::RefStore> for easy::State {
fn from(refs: crate::RefStore) -> Self {
easy::State {
#[cfg(not(feature = "max-performance"))]
pack_cache: RefCell::new(git_pack::cache::Never),
#[cfg(feature = "max-performance")]
pack_cache: RefCell::new(Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default())),
object_cache: RefCell::new(None),
buf: RefCell::new(vec![]),
refs,
}
}
}
impl From<&Repository> for easy::State {
fn from(repo: &Repository) -> Self {
repo.refs.clone().into()
}
}
impl easy::State {
#[inline]
pub(crate) fn try_borrow_mut_pack_cache(&self) -> borrow::state::Result<RefMut<'_, easy::PackCache>> {
self.pack_cache.try_borrow_mut().map_err(Into::into)
}
#[inline]
pub(crate) fn try_borrow_mut_object_cache(
&self,
) -> borrow::state::Result<RefMut<'_, Option<easy::object::cache::MemoryCappedHashmap>>> {
self.object_cache.try_borrow_mut().map_err(Into::into)
}
#[inline]
pub(crate) fn try_borrow_mut_buf(&self) -> borrow::state::Result<RefMut<'_, Vec<u8>>> {
self.buf.try_borrow_mut().map_err(Into::into)
}
#[inline]
pub(crate) fn try_borrow_buf(&self) -> borrow::state::Result<Ref<'_, Vec<u8>>> {
self.buf.try_borrow().map_err(Into::into)
}
}