]> git.proxmox.com Git - rustc.git/blame - vendor/gix-pack/src/bundle/find.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / gix-pack / src / bundle / find.rs
CommitLineData
781aab86
FG
1use gix_features::zlib;
2
0a29b90c 3impl crate::Bundle {
781aab86
FG
4 /// Find an object with the given [`ObjectId`](gix_hash::ObjectId) and place its data into `out`.
5 /// `inflate` is used to decompress objects, and will be reset before first use, but not after the last use.
0a29b90c 6 ///
781aab86 7 /// [`cache`](crate::cache::DecodeEntry) is used to accelerate the lookup.
0a29b90c
FG
8 ///
9 /// **Note** that ref deltas are automatically resolved within this pack only, which makes this implementation unusable
10 /// for thin packs, which by now are expected to be resolved already.
11 pub fn find<'a>(
12 &self,
781aab86 13 id: &gix_hash::oid,
0a29b90c 14 out: &'a mut Vec<u8>,
781aab86
FG
15 inflate: &mut zlib::Inflate,
16 cache: &mut dyn crate::cache::DecodeEntry,
0a29b90c
FG
17 ) -> Result<Option<(gix_object::Data<'a>, crate::data::entry::Location)>, crate::data::decode::Error> {
18 let idx = match self.index.lookup(id) {
19 Some(idx) => idx,
20 None => return Ok(None),
21 };
781aab86 22 self.get_object_by_index(idx, out, inflate, cache).map(Some)
0a29b90c
FG
23 }
24
25 /// Special-use function to get an object given an index previously returned from
781aab86
FG
26 /// [index::File::](crate::index::File::lookup()).
27 /// `inflate` is used to decompress objects, and will be reset before first use, but not after the last use.
0a29b90c
FG
28 ///
29 /// # Panics
30 ///
31 /// If `index` is out of bounds.
32 pub fn get_object_by_index<'a>(
33 &self,
34 idx: u32,
35 out: &'a mut Vec<u8>,
781aab86
FG
36 inflate: &mut zlib::Inflate,
37 cache: &mut dyn crate::cache::DecodeEntry,
0a29b90c
FG
38 ) -> Result<(gix_object::Data<'a>, crate::data::entry::Location), crate::data::decode::Error> {
39 let ofs = self.index.pack_offset_at_index(idx);
40 let pack_entry = self.pack.entry(ofs);
41 let header_size = pack_entry.header_size();
42 self.pack
43 .decode_entry(
44 pack_entry,
45 out,
781aab86
FG
46 inflate,
47 &|id, _out| {
0a29b90c
FG
48 self.index.lookup(id).map(|idx| {
49 crate::data::decode::entry::ResolvedBase::InPack(
50 self.pack.entry(self.index.pack_offset_at_index(idx)),
51 )
52 })
53 },
54 cache,
55 )
56 .map(move |r| {
57 (
58 gix_object::Data {
59 kind: r.kind,
60 data: out.as_slice(),
61 },
62 crate::data::entry::Location {
63 pack_id: self.pack.id,
64 pack_offset: ofs,
65 entry_size: r.compressed_size + header_size,
66 },
67 )
68 })
69 }
70}