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
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 ///
git-object/src/commit/mod.rs+0−7
@@ -1,5 +1,3 @@
1use std::borrow::Cow;
2
3use bstr::{BStr, ByteSlice};1use bstr::{BStr, ByteSlice};
4 2
5use crate::{Commit, CommitRef, TagRef};3use crate::{Commit, CommitRef, TagRef};
@@ -54,11 +52,6 @@ impl<'a> CommitRef<'a> { · 48 unmodified lines
54 pub fn message(&self) -> MessageRef<'a> {52 pub fn message(&self) -> MessageRef<'a> {
55 MessageRef::from_bytes(self.message)53 MessageRef::from_bytes(self.message)
56 }54 }
57
58 /// Return exactly the same message as [`MessageRef::summary()`].
59 pub fn summary(&self) -> Cow<'a, BStr> {
60 message::summary(self.message)
61 }
62}55}
63 56
64impl Commit {57impl Commit {