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/message.rs (1 of 4 files). Show all

Unified · Split

git-object/src/commit/message.rs+15−2
@@ -3,6 +3,7 @@ use std::{borrow::Cow, ops::Deref}; · 2 unmodified lines
3use crate::{3use crate::{
4 bstr::{BStr, BString, ByteSlice, ByteVec},4 bstr::{BStr, BString, ByteSlice, ByteVec},
5 commit::MessageRef,5 commit::MessageRef,
6 CommitRef,
6};7};
7 8
8///9///
@@ -10,7 +11,7 @@ pub mod body { · 1 unmodified line
10 use nom::{11 use nom::{
11 bytes::complete::{tag, take_until1},12 bytes::complete::{tag, take_until1},
12 combinator::all_consuming,13 combinator::all_consuming,
13 error::ParseError,14 error::{ErrorKind, ParseError},
14 sequence::terminated,15 sequence::terminated,
15 IResult,16 IResult,
16 };17 };
@@ -19,7 +20,6 @@ pub mod body { · 2 unmodified lines
19 bstr::{BStr, ByteSlice},20 bstr::{BStr, ByteSlice},
20 commit::message::BodyRef,21 commit::message::BodyRef,
21 };22 };
22 use nom::error::ErrorKind;
23 23
24 /// An iterator over trailers as parsed from a commit message body.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
199impl<'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
199impl<'a> MessageRef<'a> {212impl<'a> MessageRef<'a> {
200 /// Parse the given `input` as message.213 /// Parse the given `input` as message.
201 ///214 ///

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t