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/commit (1 of 6 files). Show all
Unified · Split
| @@ -23,6 +23,10 @@ impl crate::WriteTo for Commit { · 22 unmodified lines | ||
| 23 | 23 | out.write_all(&self.message) |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | + fn kind(&self) -> Kind { | |
| 27 | + Kind::Commit | |
| 28 | + } | |
| 29 | + | |
| 26 | 30 | fn size(&self) -> usize { |
| 27 | 31 | let hash_in_hex = self.tree.kind().len_in_hex(); |
| 28 | 32 | b"tree".len() + 1 /*space*/ + hash_in_hex + 1 /* nl */ |
| @@ -45,10 +49,6 @@ impl crate::WriteTo for Commit { · 16 unmodified lines | ||
| 45 | 49 | + 1 /* nl */ |
| 46 | 50 | + self.message.len() |
| 47 | 51 | } |
| 48 | − | |
| 49 | − fn kind(&self) -> Kind { | |
| 50 | − Kind::Commit | |
| 51 | − } | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | impl<'a> crate::WriteTo for CommitRef<'a> { |
| @@ -70,6 +70,10 @@ impl<'a> crate::WriteTo for CommitRef<'a> { · 15 unmodified lines | ||
| 70 | 70 | out.write_all(self.message) |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | + fn kind(&self) -> Kind { | |
| 74 | + Kind::Commit | |
| 75 | + } | |
| 76 | + | |
| 73 | 77 | fn size(&self) -> usize { |
| 74 | 78 | let hash_in_hex = self.tree().kind().len_in_hex(); |
| 75 | 79 | b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */ |
| @@ -92,8 +96,4 @@ impl<'a> crate::WriteTo for CommitRef<'a> { · 16 unmodified lines | ||
| 92 | 96 | + 1 /* nl */ |
| 93 | 97 | + self.message.len() |
| 94 | 98 | } |
| 95 | − | |
| 96 | − fn kind(&self) -> Kind { | |
| 97 | − Kind::Commit | |
| 98 | − } | |
| 99 | 99 | } |