Showing the changes to git-object/src/commit (1 of 11 files). Show all
Unified · Split
| @@ -2,15 +2,40 @@ use std::io; · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | use bstr::ByteSlice; |
| 4 | 4 | |
| 5 | −use crate::{encode, encode::NL, Commit}; | |
| 5 | +use crate::{encode, encode::NL, Commit, CommitRef}; | |
| 6 | 6 | |
| 7 | −impl Commit { | |
| 7 | +impl crate::WriteTo for Commit { | |
| 8 | 8 | /// Serializes this instance to `out` in the git serialization format. |
| 9 | − pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> { | |
| 9 | + fn write_to(&self, mut out: impl io::Write) -> io::Result<()> { | |
| 10 | 10 | encode::trusted_header_id(b"tree", &self.tree, &mut out)?; |
| 11 | 11 | for parent in &self.parents { |
| 12 | 12 | encode::trusted_header_id(b"parent", parent, &mut out)?; |
| 13 | 13 | } |
| 14 | + encode::trusted_header_signature(b"author", &self.author.to_ref(), &mut out)?; | |
| 15 | + encode::trusted_header_signature(b"committer", &self.committer.to_ref(), &mut out)?; | |
| 16 | + if let Some(encoding) = self.encoding.as_ref() { | |
| 17 | + encode::header_field(b"encoding", encoding, &mut out)?; | |
| 18 | + } | |
| 19 | + for (name, value) in &self.extra_headers { | |
| 20 | + let has_newline = value.find_byte(b'\n').is_some(); | |
| 21 | + if has_newline { | |
| 22 | + encode::header_field_multi_line(name, value, &mut out)?; | |
| 23 | + } else { | |
| 24 | + encode::trusted_header_field(name, value, &mut out)?; | |
| 25 | + } | |
| 26 | + } | |
| 27 | + out.write_all(NL)?; | |
| 28 | + out.write_all(&self.message) | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +impl<'a> crate::WriteTo for CommitRef<'a> { | |
| 33 | + /// Serializes this instance to `out` in the git serialization format. | |
| 34 | + fn write_to(&self, mut out: impl io::Write) -> io::Result<()> { | |
| 35 | + encode::trusted_header_id(b"tree", &self.tree(), &mut out)?; | |
| 36 | + for parent in self.parents() { | |
| 37 | + encode::trusted_header_id(b"parent", &parent, &mut out)?; | |
| 38 | + } | |
| 14 | 39 | encode::trusted_header_signature(b"author", &self.author, &mut out)?; |
| 15 | 40 | encode::trusted_header_signature(b"committer", &self.committer, &mut out)?; |
| 16 | 41 | if let Some(encoding) = self.encoding.as_ref() { |