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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use crate::{data, pack};
use git_object::mutable;
use std::io;
pub trait Write {
type Error: std::error::Error + From<io::Error>;
fn write(&self, object: &mutable::Object, hash: git_hash::Kind) -> Result<git_hash::ObjectId, Self::Error> {
let mut buf = Vec::with_capacity(2048);
object.write_to(&mut buf)?;
self.write_stream(object.kind(), buf.len() as u64, buf.as_slice(), hash)
}
fn write_buf(
&self,
object: git_object::Kind,
from: &[u8],
hash: git_hash::Kind,
) -> Result<git_hash::ObjectId, Self::Error> {
self.write_stream(object, from.len() as u64, from, hash)
}
fn write_stream(
&self,
kind: git_object::Kind,
size: u64,
from: impl io::Read,
hash: git_hash::Kind,
) -> Result<git_hash::ObjectId, Self::Error>;
}
pub trait Find {
type Error: std::error::Error + 'static;
fn find<'a>(
&self,
id: impl AsRef<git_hash::oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl crate::pack::cache::DecodeEntry,
) -> Result<Option<data::Object<'a>>, Self::Error>;
fn pack_entry(&self, object: &data::Object<'_>) -> Option<PackEntry<'_>>;
}
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub struct PackEntry<'a> {
pub data: &'a [u8],
pub crc32: Option<u32>,
pub version: pack::data::Version,
}
mod locate_impls {
use crate::{data, data::Object, pack, PackEntry};
use git_hash::oid;
use std::ops::Deref;
impl<T> super::Find for std::sync::Arc<T>
where
T: super::Find,
{
type Error = T::Error;
fn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl pack::cache::DecodeEntry,
) -> Result<Option<Object<'a>>, Self::Error> {
self.deref().find(id, buffer, pack_cache)
}
fn pack_entry(&self, object: &data::Object<'_>) -> Option<PackEntry<'_>> {
self.deref().pack_entry(object)
}
}
impl<T> super::Find for Box<T>
where
T: super::Find,
{
type Error = T::Error;
fn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl pack::cache::DecodeEntry,
) -> Result<Option<Object<'a>>, Self::Error> {
self.deref().find(id, buffer, pack_cache)
}
fn pack_entry(&self, object: &data::Object<'_>) -> Option<PackEntry<'_>> {
self.deref().pack_entry(object)
}
}
}