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
use crate::pack;
use git_object::borrowed;
use quick_error::quick_error;
quick_error! {
#[derive(Debug)]
pub enum Error {
Decode(err: pack::data::decode::Error) {
display("Could not decode object")
}
}
}
impl pack::Bundle {
pub fn locate<'a>(
&self,
id: borrowed::Id,
out: &'a mut Vec<u8>,
cache: &mut impl pack::cache::DecodeEntry,
) -> Option<Result<pack::Object<'a>, Error>> {
let idx = self.index.lookup(id)?;
let ofs = self.index.pack_offset_at_index(idx);
let pack_entry = self.pack.entry(ofs);
self.pack
.decode_entry(
pack_entry,
out,
|id, _out| {
self.index.lookup(id).map(|idx| {
pack::data::decode::ResolvedBase::InPack(self.pack.entry(self.index.pack_offset_at_index(idx)))
})
},
cache,
)
.map_err(Error::Decode)
.map(move |r| pack::Object {
kind: r.kind,
data: out.as_slice(),
})
.into()
}
}