History

feat: `CommitRef::message_trailers()` as shortcut… (#198)

…which also saves parsing time.

Sebastian Thiel committed 5 years ago

Commit 53243911 parent c3b01614 files · +36 −12Browse files

Showing the changes to git-object/src/commit (2 of 4 files). Show all

Unified · Split

2 files
  1. git-object/src/commit/message.rs +15 −2
  2. git-object/src/commit/mod.rs +0 −7
git-object/src/commit/message.rs+15−2
@@ -3,6 +3,7 @@ use std::{borrow::Cow, ops::Deref}; · 2 unmodified lines
33 use crate::{
44 bstr::{BStr, BString, ByteSlice, ByteVec},
55 commit::MessageRef,
6+ CommitRef,
67 };
78
89 ///
@@ -10,7 +11,7 @@ pub mod body { · 1 unmodified line
1011 use nom::{
1112 bytes::complete::{tag, take_until1},
1213 combinator::all_consuming,
13− error::ParseError,
14+ error::{ErrorKind, ParseError},
1415 sequence::terminated,
1516 IResult,
1617 };
@@ -19,7 +20,6 @@ pub mod body { · 2 unmodified lines
1920 bstr::{BStr, ByteSlice},
2021 commit::message::BodyRef,
2122 };
22− use nom::error::ErrorKind;
2323
2424 /// An iterator over trailers as parsed from a commit message body.
2525 ///
@@ -196,6 +196,19 @@ mod decode { · 170 unmodified lines
196196 }
197197 }
198198
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+
199212 impl<'a> MessageRef<'a> {
200213 /// Parse the given `input` as message.
201214 ///
git-object/src/commit/mod.rs+0−7
@@ -1,5 +1,3 @@
1−use std::borrow::Cow;
2−
31 use bstr::{BStr, ByteSlice};
42
53 use crate::{Commit, CommitRef, TagRef};
@@ -54,11 +52,6 @@ impl<'a> CommitRef<'a> { · 48 unmodified lines
5452 pub fn message(&self) -> MessageRef<'a> {
5553 MessageRef::from_bytes(self.message)
5654 }
57−
58− /// Return exactly the same message as [`MessageRef::summary()`].
59− pub fn summary(&self) -> Cow<'a, BStr> {
60− message::summary(self.message)
61− }
6255 }
6356
6457 impl Commit {