Unified · Split
| @@ -1,5 +1,4 @@ | ||
| 1 | 1 | //! Contains a borrowed Object bound to a buffer holding its decompressed data. |
| 2 | −use git_object::borrowed; | |
| 3 | 2 | |
| 4 | 3 | /// A borrowed object using a borrowed slice as backing buffer. |
| 5 | 4 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] |
| @@ -11,17 +10,25 @@ pub struct Object<'a> { · 5 unmodified lines | ||
| 11 | 10 | } |
| 12 | 11 | |
| 13 | 12 | impl<'a> Object<'a> { |
| 14 | − /// Decodes the data in the backing slice into a [`borrowed::Object`], allowing to access all of its data | |
| 13 | + /// Decodes the data in the backing slice into a [`crate::borrowed::Object`], allowing to access all of its data | |
| 15 | 14 | /// conveniently. The cost of parsing an object is negligible. |
| 16 | 15 | /// |
| 17 | − /// **Note** that [owned, decoded objects][git_object::owned::Object] can be created from a [`borrowed::Object`] | |
| 18 | − /// using [`borrowed::Object::into_owned()`]. | |
| 19 | − pub fn decode(&self) -> Result<borrowed::Object<'_>, borrowed::Error> { | |
| 16 | + /// **Note** that [owned, decoded objects][git_object::owned::Object] can be created from a [`crate::borrowed::Object`] | |
| 17 | + /// using [`crate::borrowed::Object::into_owned()`]. | |
| 18 | + pub fn decode(&self) -> Result<git_object::borrowed::Object<'_>, git_object::borrowed::Error> { | |
| 20 | 19 | Ok(match self.kind { |
| 21 | − git_object::Kind::Tree => borrowed::Object::Tree(borrowed::Tree::from_bytes(self.data)?), | |
| 22 | − git_object::Kind::Blob => borrowed::Object::Blob(borrowed::Blob { data: self.data }), | |
| 23 | − git_object::Kind::Commit => borrowed::Object::Commit(borrowed::Commit::from_bytes(self.data)?), | |
| 24 | − git_object::Kind::Tag => borrowed::Object::Tag(borrowed::Tag::from_bytes(self.data)?), | |
| 20 | + git_object::Kind::Tree => { | |
| 21 | + git_object::borrowed::Object::Tree(git_object::borrowed::Tree::from_bytes(self.data)?) | |
| 22 | + } | |
| 23 | + git_object::Kind::Blob => { | |
| 24 | + git_object::borrowed::Object::Blob(git_object::borrowed::Blob { data: self.data }) | |
| 25 | + } | |
| 26 | + git_object::Kind::Commit => { | |
| 27 | + git_object::borrowed::Object::Commit(git_object::borrowed::Commit::from_bytes(self.data)?) | |
| 28 | + } | |
| 29 | + git_object::Kind::Tag => { | |
| 30 | + git_object::borrowed::Object::Tag(git_object::borrowed::Tag::from_bytes(self.data)?) | |
| 31 | + } | |
| 25 | 32 | }) |
| 26 | 33 | } |
| 27 | 34 | } |
| @@ -1,4 +1,4 @@ | ||
| 1 | −use crate::{borrowed, compound, linked, pack}; | |
| 1 | +use crate::{compound, linked, pack}; | |
| 2 | 2 | |
| 3 | 3 | impl linked::Db { |
| 4 | 4 | /// Find an object as identified by [`ObjectId`][git_hash::ObjectId] and store its data in full in the provided `buffer`. |
| @@ -9,7 +9,7 @@ impl linked::Db { · 4 unmodified lines | ||
| 9 | 9 | id: impl AsRef<git_hash::oid>, |
| 10 | 10 | buffer: &'a mut Vec<u8>, |
| 11 | 11 | pack_cache: &mut impl pack::cache::DecodeEntry, |
| 12 | − ) -> Result<Option<borrowed::Object<'a>>, compound::locate::Error> { | |
| 12 | + ) -> Result<Option<crate::borrowed::Object<'a>>, compound::locate::Error> { | |
| 13 | 13 | use compound::locate::PackInfo; |
| 14 | 14 | let id = id.as_ref(); |
| 15 | 15 | for db in self.dbs.iter() { |
| @@ -1,5 +1,4 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | − borrowed, | |
| 3 | 2 | loose::{db::sha1_path, object::header, Db, HEADER_READ_UNCOMPRESSED_BYTES}, |
| 4 | 3 | zlib, |
| 5 | 4 | }; |
| @@ -39,7 +38,7 @@ impl Db { · 33 unmodified lines | ||
| 39 | 38 | &self, |
| 40 | 39 | id: impl AsRef<git_hash::oid>, |
| 41 | 40 | out: &'a mut Vec<u8>, |
| 42 | − ) -> Result<Option<borrowed::Object<'a>>, Error> { | |
| 41 | + ) -> Result<Option<crate::borrowed::Object<'a>>, Error> { | |
| 43 | 42 | match self.locate_inner(id.as_ref(), out) { |
| 44 | 43 | Ok(obj) => Ok(Some(obj)), |
| 45 | 44 | Err(err) => match err { |
| @@ -63,7 +62,7 @@ impl Db { · 17 unmodified lines | ||
| 63 | 62 | } |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | − fn locate_inner<'a>(&self, id: &git_hash::oid, buf: &'a mut Vec<u8>) -> Result<borrowed::Object<'a>, Error> { | |
| 65 | + fn locate_inner<'a>(&self, id: &git_hash::oid, buf: &'a mut Vec<u8>) -> Result<crate::borrowed::Object<'a>, Error> { | |
| 67 | 66 | let path = sha1_path(id, self.path.clone()); |
| 68 | 67 | |
| 69 | 68 | let mut inflate = zlib::Inflate::default(); |
| @@ -112,7 +111,7 @@ impl Db { · 42 unmodified lines | ||
| 112 | 111 | buf.copy_within(decompressed_body_bytes_sans_header, 0); |
| 113 | 112 | buf.resize(size, 0); |
| 114 | 113 | // TODO: assure both branches run via tests |
| 115 | − Ok(borrowed::Object { kind, data: buf }) | |
| 114 | + Ok(crate::borrowed::Object { kind, data: buf }) | |
| 116 | 115 | } else { |
| 117 | 116 | buf.resize(bytes_read + size + header_size, 0); |
| 118 | 117 | { |
| @@ -135,7 +134,7 @@ impl Db { · 16 unmodified lines | ||
| 135 | 134 | }; |
| 136 | 135 | buf.copy_within(decompressed_start + header_size.., 0); |
| 137 | 136 | buf.resize(size, 0); |
| 138 | − Ok(borrowed::Object { kind, data: buf }) | |
| 137 | + Ok(crate::borrowed::Object { kind, data: buf }) | |
| 139 | 138 | } |
| 140 | 139 | } |
| 141 | 140 | } |
| @@ -171,10 +171,12 @@ impl index::File { · 170 unmodified lines | ||
| 171 | 171 | match object_kind { |
| 172 | 172 | Tree | Commit | Tag => { |
| 173 | 173 | let borrowed_object = |
| 174 | − borrowed::Object::from_bytes(object_kind, buf).map_err(|err| Error::ObjectDecode { | |
| 175 | − source: err, | |
| 176 | − kind: object_kind, | |
| 177 | − id: index_entry.oid, | |
| 174 | + git_object::borrowed::Object::from_bytes(object_kind, buf).map_err(|err| { | |
| 175 | + Error::ObjectDecode { | |
| 176 | + source: err, | |
| 177 | + kind: object_kind, | |
| 178 | + id: index_entry.oid, | |
| 179 | + } | |
| 178 | 180 | })?; |
| 179 | 181 | if let Mode::Sha1Crc32DecodeEncode = mode { |
| 180 | 182 | let object = owned::Object::from(borrowed_object); |