diff --git a/gix-ref/src/store/file/log/line.rs b/gix-ref/src/store/file/log/line.rs index 346ab53a8d8..af06b40471e 100644 --- a/gix-ref/src/store/file/log/line.rs +++ b/gix-ref/src/store/file/log/line.rs @@ -75,7 +75,11 @@ impl<'a> From> for Line { pub mod decode { use gix_object::bstr::{BStr, ByteSlice}; use winnow::{ + combinator::alt, + combinator::eof, + combinator::fail, combinator::opt, + combinator::preceded, combinator::terminated, error::{AddContext, ParserError}, prelude::*, @@ -134,28 +138,22 @@ pub mod decode { } fn one<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(bytes: &'a [u8]) -> IResult<&[u8], LineRef<'a>, E> { - let (i, (old, new, signature, message_sep, message)) = ( - terminated(hex_hash, b" ").context(""), - terminated(hex_hash, b" ").context(""), - gix_actor::signature::decode.context(" <> "), - opt(b'\t'), - message.context(""), + let (i, ((old, new, signature), message)) = ( + ( + terminated(hex_hash, b" ").context(""), + terminated(hex_hash, b" ").context(""), + gix_actor::signature::decode.context(" <> "), + ) + .context(" <> \\t"), + alt(( + preceded(b'\t', message.context("")), + b'\n'.value(Default::default()), + eof.value(Default::default()), + fail.context("log message must be separated from signature with whitespace"), + )), ) - .context(" <> \\t") .parse_next(bytes)?; - if message_sep.is_none() { - if let Some(first) = message.first() { - if !first.is_ascii_whitespace() { - return Err( - winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Verify).map(|err: E| { - err.add_context(i, "log message must be separated from signature with whitespace") - }), - ); - } - } - } - Ok(( i, LineRef { @@ -204,9 +202,11 @@ pub mod decode { let err = one::>(line.as_bytes()) .map_err(to_bstr_err) .expect_err("this should fail"); - assert!(err - .to_string() - .contains("log message must be separated from signature with whitespace")); + assert!( + err.to_string() + .contains("log message must be separated from signature with whitespace"), + "expected\n `log message must be separated from signature with whitespace`\nin\n```\n{err}\n```" + ); } }