…which also saves parsing time.
Showing the changes to git-object/src/commit/message.rs (1 of 4 files). Show all
Unified · Split
| @@ -3,6 +3,7 @@ use std::{borrow::Cow, ops::Deref}; · 2 unmodified lines | ||
| 3 | 3 | use crate::{ |
| 4 | 4 | bstr::{BStr, BString, ByteSlice, ByteVec}, |
| 5 | 5 | commit::MessageRef, |
| 6 | + CommitRef, | |
| 6 | 7 | }; |
| 7 | 8 | |
| 8 | 9 | /// |
| @@ -10,7 +11,7 @@ pub mod body { · 1 unmodified line | ||
| 10 | 11 | use nom::{ |
| 11 | 12 | bytes::complete::{tag, take_until1}, |
| 12 | 13 | combinator::all_consuming, |
| 13 | − error::ParseError, | |
| 14 | + error::{ErrorKind, ParseError}, | |
| 14 | 15 | sequence::terminated, |
| 15 | 16 | IResult, |
| 16 | 17 | }; |
| @@ -19,7 +20,6 @@ pub mod body { · 2 unmodified lines | ||
| 19 | 20 | bstr::{BStr, ByteSlice}, |
| 20 | 21 | commit::message::BodyRef, |
| 21 | 22 | }; |
| 22 | − use nom::error::ErrorKind; | |
| 23 | 23 | |
| 24 | 24 | /// An iterator over trailers as parsed from a commit message body. |
| 25 | 25 | /// |
| @@ -196,6 +196,19 @@ mod decode { · 170 unmodified lines | ||
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | +impl<'a> CommitRef<'a> { | |
| 200 | + /// Return exactly the same message as [`MessageRef::summary()`]. | |
| 201 | + pub fn message_summary(&self) -> Cow<'a, BStr> { | |
| 202 | + summary(self.message) | |
| 203 | + } | |
| 204 | + | |
| 205 | + /// Return an iterator over message trailers as obtained from the last paragraph of the commit message. | |
| 206 | + /// May be empty. | |
| 207 | + pub fn message_trailers(&self) -> body::Trailers<'a> { | |
| 208 | + BodyRef::from_bytes(&self.message).trailers() | |
| 209 | + } | |
| 210 | +} | |
| 211 | + | |
| 199 | 212 | impl<'a> MessageRef<'a> { |
| 200 | 213 | /// Parse the given `input` as message. |
| 201 | 214 | /// |