This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

1use gix_features::zlib; 2 3impl crate::Bundle { 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. 6 /// 7 /// [`cache`](crate::cache::DecodeEntry) is used to accelerate the lookup. 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, 13 id: &gix_hash::oid, 14 out: &'a mut Vec<u8>, 15 inflate: &mut zlib::Inflate, 16 cache: &mut dyn crate::cache::DecodeEntry, 17 ) -> Result< 18 Option<(gix_object::Data<'a>, crate::data::entry::Location)>, 19 crate::data::decode::Error, 20 > { 21 let idx = match self.index.lookup(id) { 22 Some(idx) => idx, 23 None => return Ok(None), 24 }; 25 self.get_object_by_index(idx, out, inflate, cache).map(Some) 26 } 27 28 /// Special-use function to get an object given an index previously returned from 29 /// [index::File::](crate::index::File::lookup()). 30 /// `inflate` is used to decompress objects, and will be reset before first use, but not after the last use. 31 /// 32 /// # Panics 33 /// 34 /// If `index` is out of bounds. 35 pub fn get_object_by_index<'a>( 36 &self, 37 idx: u32, 38 out: &'a mut Vec<u8>, 39 inflate: &mut zlib::Inflate, 40 cache: &mut dyn crate::cache::DecodeEntry, 41 ) -> Result<(gix_object::Data<'a>, crate::data::entry::Location), crate::data::decode::Error> 42 { 43 let ofs = self.index.pack_offset_at_index(idx); 44 let pack_entry = self.pack.entry(ofs)?; 45 let header_size = pack_entry.header_size(); 46 self.pack 47 .decode_entry( 48 pack_entry, 49 out, 50 inflate, 51 &|id, _out| { 52 let idx = self.index.lookup(id)?; 53 self.pack 54 .entry(self.index.pack_offset_at_index(idx)) 55 .ok() 56 .map(crate::data::decode::entry::ResolvedBase::InPack) 57 }, 58 cache, 59 ) 60 .map(move |r| { 61 ( 62 gix_object::Data { 63 kind: r.kind, 64 data: out.as_slice(), 65 object_hash: self.pack.object_hash(), 66 }, 67 crate::data::entry::Location { 68 pack_id: self.pack.id, 69 pack_offset: ofs, 70 entry_size: r.compressed_size + header_size, 71 }, 72 ) 73 }) 74 } 75}