@@ -75,7 +75,11 @@ impl<'a> From<LineRef<'a>> for Line {
75
75
pub mod decode {
76
76
use gix_object:: bstr:: { BStr , ByteSlice } ;
77
77
use winnow:: {
78
+ combinator:: alt,
79
+ combinator:: eof,
80
+ combinator:: fail,
78
81
combinator:: opt,
82
+ combinator:: preceded,
79
83
combinator:: terminated,
80
84
error:: { AddContext , ParserError } ,
81
85
prelude:: * ,
@@ -134,28 +138,22 @@ pub mod decode {
134
138
}
135
139
136
140
fn one < ' a , E : ParserError < & ' a [ u8 ] > + AddContext < & ' a [ u8 ] > > ( bytes : & ' a [ u8 ] ) -> IResult < & [ u8 ] , LineRef < ' a > , E > {
137
- let ( i, ( old, new, signature, message_sep, message) ) = (
138
- terminated ( hex_hash, b" " ) . context ( "<old-hexsha>" ) ,
139
- terminated ( hex_hash, b" " ) . context ( "<new-hexsha>" ) ,
140
- gix_actor:: signature:: decode. context ( "<name> <<email>> <timestamp>" ) ,
141
- opt ( b'\t' ) ,
142
- message. context ( "<optional message>" ) ,
141
+ let ( i, ( ( old, new, signature) , message) ) = (
142
+ (
143
+ terminated ( hex_hash, b" " ) . context ( "<old-hexsha>" ) ,
144
+ terminated ( hex_hash, b" " ) . context ( "<new-hexsha>" ) ,
145
+ gix_actor:: signature:: decode. context ( "<name> <<email>> <timestamp>" ) ,
146
+ )
147
+ . context ( "<old-hexsha> <new-hexsha> <name> <<email>> <timestamp> <tz>\\ t<message>" ) ,
148
+ alt ( (
149
+ preceded ( b'\t' , message. context ( "<optional message>" ) ) ,
150
+ b'\n' . value ( Default :: default ( ) ) ,
151
+ eof. value ( Default :: default ( ) ) ,
152
+ fail. context ( "log message must be separated from signature with whitespace" ) ,
153
+ ) ) ,
143
154
)
144
- . context ( "<old-hexsha> <new-hexsha> <name> <<email>> <timestamp> <tz>\\ t<message>" )
145
155
. parse_next ( bytes) ?;
146
156
147
- if message_sep. is_none ( ) {
148
- if let Some ( first) = message. first ( ) {
149
- if !first. is_ascii_whitespace ( ) {
150
- return Err (
151
- winnow:: error:: ErrMode :: from_error_kind ( i, winnow:: error:: ErrorKind :: Verify ) . map ( |err : E | {
152
- err. add_context ( i, "log message must be separated from signature with whitespace" )
153
- } ) ,
154
- ) ;
155
- }
156
- }
157
- }
158
-
159
157
Ok ( (
160
158
i,
161
159
LineRef {
@@ -204,9 +202,11 @@ pub mod decode {
204
202
let err = one :: < VerboseError < & [ u8 ] > > ( line. as_bytes ( ) )
205
203
. map_err ( to_bstr_err)
206
204
. expect_err ( "this should fail" ) ;
207
- assert ! ( err
208
- . to_string( )
209
- . contains( "log message must be separated from signature with whitespace" ) ) ;
205
+ assert ! (
206
+ err. to_string( )
207
+ . contains( "log message must be separated from signature with whitespace" ) ,
208
+ "expected\n `log message must be separated from signature with whitespace`\n in\n ```\n {err}\n ```"
209
+ ) ;
210
210
}
211
211
}
212
212
0 commit comments