That way both representations are optimal in memory for their intended usecase. - `TagRef` is decodable from a buffer refers to it with all of its fields. That way round-trips are cheapest. - `Tag` does not allocate for hashes as there is a more compact representation: `git_hash::ObjectId`.
Showing the changes to git-object/src/object (1 of 6 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::convert::TryFrom; |
| 2 | 2 | |
| 3 | −use crate::{bstr::BStr, tree, Blob, BlobRef, Commit, CommitRef, Object, ObjectRef, Tag, TagRef, Tree, TreeRef}; | |
| 3 | +use crate::{tree, Blob, BlobRef, Commit, CommitRef, Object, ObjectRef, Tag, TagRef, Tree, TreeRef}; | |
| 4 | 4 | |
| 5 | 5 | impl From<TagRef<'_>> for Tag { |
| 6 | 6 | fn from(other: TagRef<'_>) -> Tag { |
| @@ -13,7 +13,7 @@ impl From<TagRef<'_>> for Tag { · 6 unmodified lines | ||
| 13 | 13 | pgp_signature, |
| 14 | 14 | } = other; |
| 15 | 15 | Tag { |
| 16 | − target: target.to_owned(), | |
| 16 | + target: git_hash::ObjectId::from_hex(target).expect("prior parser validation"), | |
| 17 | 17 | name: name.to_owned(), |
| 18 | 18 | target_kind, |
| 19 | 19 | message: message.to_owned(), |
| @@ -23,27 +23,6 @@ impl From<TagRef<'_>> for Tag { · 3 unmodified lines | ||
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | −impl<'a> From<&'a Tag> for TagRef<'a> { | |
| 27 | − fn from(other: &'a Tag) -> TagRef<'a> { | |
| 28 | − let Tag { | |
| 29 | − target, | |
| 30 | − target_kind, | |
| 31 | − name, | |
| 32 | − tagger, | |
| 33 | − message, | |
| 34 | − pgp_signature, | |
| 35 | − } = other; | |
| 36 | − TagRef { | |
| 37 | − target: target.as_ref(), | |
| 38 | − target_kind: *target_kind, | |
| 39 | − name: name.as_ref(), | |
| 40 | − tagger: tagger.as_ref().map(|s| s.to_ref()), | |
| 41 | − message: message.as_ref(), | |
| 42 | − pgp_signature: pgp_signature.as_deref().map(BStr::new), | |
| 43 | − } | |
| 44 | − } | |
| 45 | −} | |
| 46 | − | |
| 47 | 26 | impl From<CommitRef<'_>> for Commit { |
| 48 | 27 | fn from(other: CommitRef<'_>) -> Commit { |
| 49 | 28 | let CommitRef { |
| @@ -56,10 +35,10 @@ impl From<CommitRef<'_>> for Commit { · 6 unmodified lines | ||
| 56 | 35 | extra_headers, |
| 57 | 36 | } = other; |
| 58 | 37 | Commit { |
| 59 | − tree: git_hash::ObjectId::from_hex(tree).expect("40 bytes hex sha1"), | |
| 38 | + tree: git_hash::ObjectId::from_hex(tree).expect("prior parser validation"), | |
| 60 | 39 | parents: parents |
| 61 | 40 | .iter() |
| 62 | − .map(|parent| git_hash::ObjectId::from_hex(parent).expect("40 bytes hex sha1")) | |
| 41 | + .map(|parent| git_hash::ObjectId::from_hex(parent).expect("prior parser validation")) | |
| 63 | 42 | .collect(), |
| 64 | 43 | author: author.into(), |
| 65 | 44 | committer: committer.into(), |