History

restore original representation of `Tag` at the cost of some duplication

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`.

Sebastian Thiel committed 3 years ago

Commit dd0a23d1 parent 7242d1f6 files · +49 −59Browse files

Showing the changes to git-object/src/object (1 of 6 files). Show all

Unified · Split

git-object/src/object/convert.rs+4−25
@@ -1,6 +1,6 @@
11 use std::convert::TryFrom;
22
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};
44
55 impl From<TagRef<'_>> for Tag {
66 fn from(other: TagRef<'_>) -> Tag {
@@ -13,7 +13,7 @@ impl From<TagRef<'_>> for Tag { · 6 unmodified lines
1313 pgp_signature,
1414 } = other;
1515 Tag {
16− target: target.to_owned(),
16+ target: git_hash::ObjectId::from_hex(target).expect("prior parser validation"),
1717 name: name.to_owned(),
1818 target_kind,
1919 message: message.to_owned(),
@@ -23,27 +23,6 @@ impl From<TagRef<'_>> for Tag { · 3 unmodified lines
2323 }
2424 }
2525
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−
4726 impl From<CommitRef<'_>> for Commit {
4827 fn from(other: CommitRef<'_>) -> Commit {
4928 let CommitRef {
@@ -56,10 +35,10 @@ impl From<CommitRef<'_>> for Commit { · 6 unmodified lines
5635 extra_headers,
5736 } = other;
5837 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"),
6039 parents: parents
6140 .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"))
6342 .collect(),
6443 author: author.into(),
6544 committer: committer.into(),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t