Struct git_object::CommitRef
source · pub struct CommitRef<'a> {
pub tree: &'a BStr,
pub parents: SmallVec<[&'a BStr; 1]>,
pub author: SignatureRef<'a>,
pub committer: SignatureRef<'a>,
pub encoding: Option<&'a BStr>,
pub message: &'a BStr,
pub extra_headers: Vec<(&'a BStr, Cow<'a, BStr>)>,
}
Expand description
A git commit parsed using from_bytes()
.
A commit encapsulates information about a point in time at which the state of the repository is recorded, usually after a
change which is documented in the commit message
.
Fields§
§tree: &'a BStr
HEX hash of tree object we point to. Usually 40 bytes long.
Use tree()
to obtain a decoded version of it.
parents: SmallVec<[&'a BStr; 1]>
HEX hash of each parent commit. Empty for first commit in repository.
Who wrote this commit. Name and email might contain whitespace and are not trimmed to ensure round-tripping.
Use the author()
method to received a trimmed version of it.
committer: SignatureRef<'a>
Who committed this commit. Name and email might contain whitespace and are not trimmed to ensure round-tripping.
Use the committer()
method to received a trimmed version of it.
This may be different from the author
in case the author couldn’t write to the repository themselves and
is commonly encountered with contributed commits.
encoding: Option<&'a BStr>
The name of the message encoding, otherwise UTF-8 should be assumed.
message: &'a BStr
The commit message documenting the change.
extra_headers: Vec<(&'a BStr, Cow<'a, BStr>)>
Extra header fields, in order of them being encountered, made accessible with the iterator returned by extra_headers()
.
Implementations§
source§impl<'a> CommitRef<'a>
impl<'a> CommitRef<'a>
sourcepub fn message_summary(&self) -> Cow<'a, BStr>
pub fn message_summary(&self) -> Cow<'a, BStr>
Return exactly the same message as MessageRef::summary()
.
sourcepub fn message_trailers(&self) -> Trailers<'a> ⓘ
pub fn message_trailers(&self) -> Trailers<'a> ⓘ
Return an iterator over message trailers as obtained from the last paragraph of the commit message. May be empty.
source§impl<'a> CommitRef<'a>
impl<'a> CommitRef<'a>
sourcepub fn from_bytes(data: &'a [u8]) -> Result<CommitRef<'a>, Error>
pub fn from_bytes(data: &'a [u8]) -> Result<CommitRef<'a>, Error>
Deserialize a commit from the given data
bytes while avoiding most allocations.
Examples found in repository?
More examples
sourcepub fn tree(&self) -> ObjectId
pub fn tree(&self) -> ObjectId
Return the tree
fields hash digest.
Examples found in repository?
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
encode::trusted_header_id(b"tree", &self.tree(), &mut out)?;
for parent in self.parents() {
encode::trusted_header_id(b"parent", &parent, &mut out)?;
}
encode::trusted_header_signature(b"author", &self.author, &mut out)?;
encode::trusted_header_signature(b"committer", &self.committer, &mut out)?;
if let Some(encoding) = self.encoding.as_ref() {
encode::header_field(b"encoding", encoding, &mut out)?;
}
for (name, value) in &self.extra_headers {
encode::header_field_multi_line(name, value, &mut out)?;
}
out.write_all(NL)?;
out.write_all(self.message)
}
fn kind(&self) -> Kind {
Kind::Commit
}
fn size(&self) -> usize {
let hash_in_hex = self.tree().kind().len_in_hex();
b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */
+ self.parents.iter().count() * (b"parent".len() + 1 /* space */ + hash_in_hex + 1 /* nl */)
+ b"author".len() + 1 /* space */ + self.author.size() + 1 /* nl */
+ b"committer".len() + 1 /* space */ + self.committer.size() + 1 /* nl */
+ self
.encoding
.as_ref()
.map(|e| b"encoding".len() + 1 /* space */ + e.len() + 1 /* nl */)
.unwrap_or(0)
+ self
.extra_headers
.iter()
.map(|(name, value)| {
// each header *value* is preceded by a space and followed by a newline
name.len() + value.split_str("\n").map(|s| s.len() + 2).sum::<usize>()
})
.sum::<usize>()
+ 1 /* nl */
+ self.message.len()
}
sourcepub fn parents(&self) -> impl Iterator<Item = ObjectId> + '_
pub fn parents(&self) -> impl Iterator<Item = ObjectId> + '_
Returns an iterator of parent object ids
Examples found in repository?
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
encode::trusted_header_id(b"tree", &self.tree(), &mut out)?;
for parent in self.parents() {
encode::trusted_header_id(b"parent", &parent, &mut out)?;
}
encode::trusted_header_signature(b"author", &self.author, &mut out)?;
encode::trusted_header_signature(b"committer", &self.committer, &mut out)?;
if let Some(encoding) = self.encoding.as_ref() {
encode::header_field(b"encoding", encoding, &mut out)?;
}
for (name, value) in &self.extra_headers {
encode::header_field_multi_line(name, value, &mut out)?;
}
out.write_all(NL)?;
out.write_all(self.message)
}
sourcepub fn extra_headers(
&self
) -> ExtraHeaders<impl Iterator<Item = (&BStr, &BStr)>>
pub fn extra_headers(
&self
) -> ExtraHeaders<impl Iterator<Item = (&BStr, &BStr)>>
Returns a convenient iterator over all extra headers.
Return the author, with whitespace trimmed.
This is different from the author
field which may contain whitespace.
sourcepub fn committer(&self) -> SignatureRef<'a>
pub fn committer(&self) -> SignatureRef<'a>
Return the committer, with whitespace trimmed.
This is different from the committer
field which may contain whitespace.
sourcepub fn message(&self) -> MessageRef<'a>
pub fn message(&self) -> MessageRef<'a>
Returns a partially parsed message from which more information can be derived.
Trait Implementations§
source§impl<'de: 'a, 'a> Deserialize<'de> for CommitRef<'a>
impl<'de: 'a, 'a> Deserialize<'de> for CommitRef<'a>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<'a> Ord for CommitRef<'a>
impl<'a> Ord for CommitRef<'a>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'a> PartialEq<CommitRef<'a>> for CommitRef<'a>
impl<'a> PartialEq<CommitRef<'a>> for CommitRef<'a>
source§impl<'a> PartialOrd<CommitRef<'a>> for CommitRef<'a>
impl<'a> PartialOrd<CommitRef<'a>> for CommitRef<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more