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