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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::{
cell::RefCell,
path::{Path, PathBuf},
};
use crate::easy;
impl Clone for easy::Handle {
fn clone(&self) -> Self {
easy::Handle::from_refs_and_objects(
self.refs.clone(),
self.objects.clone(),
self.object_hash,
self.work_tree.clone(),
)
}
}
impl easy::Handle {
pub fn work_tree(&self) -> Option<&Path> {
self.work_tree.as_deref()
}
}
impl easy::Handle {
pub(crate) fn from_refs_and_objects(
refs: crate::RefStore,
objects: crate::OdbHandle,
object_hash: git_hash::Kind,
work_tree: Option<PathBuf>,
) -> Self {
easy::Handle {
bufs: RefCell::new(Vec::with_capacity(4)),
object_hash,
work_tree,
objects: {
#[cfg(feature = "max-performance")]
{
objects.with_pack_cache(|| Box::new(git_pack::cache::lru::StaticLinkedList::<64>::default()))
}
#[cfg(not(feature = "max-performance"))]
{
objects
}
},
refs,
}
}
}
impl From<&crate::Repository> for easy::Handle {
fn from(repo: &crate::Repository) -> Self {
easy::Handle::from_refs_and_objects(
repo.refs.clone(),
repo.objects.to_handle().into(),
repo.object_hash,
repo.work_tree.clone(),
)
}
}
impl From<crate::Repository> for easy::Handle {
fn from(repo: crate::Repository) -> Self {
(&repo).into()
}
}
impl easy::Handle {
#[inline]
pub(crate) fn free_buf(&self) -> Vec<u8> {
self.bufs.borrow_mut().pop().unwrap_or_default()
}
#[inline]
pub(crate) fn reuse_buffer(&self, data: &mut Vec<u8>) {
if data.capacity() > 0 {
self.bufs.borrow_mut().push(std::mem::take(data));
}
}
}