diff --git a/gix-actor/src/identity.rs b/gix-actor/src/identity.rs index 730169027f7..5ce3ba5d3e7 100644 --- a/gix-actor/src/identity.rs +++ b/gix-actor/src/identity.rs @@ -4,7 +4,7 @@ use crate::{signature::decode, Identity, IdentityRef}; impl<'a> IdentityRef<'a> { /// Deserialize an identity from the given `data`. - pub fn from_bytes(data: &'a [u8]) -> Result> + pub fn from_bytes(data: &'a [u8]) -> Result> where E: winnow::error::ParseError<&'a [u8]> + winnow::error::ContextError<&'a [u8]>, { diff --git a/gix-actor/src/signature/decode.rs b/gix-actor/src/signature/decode.rs index 4fe0f939e6f..f137d2469e6 100644 --- a/gix-actor/src/signature/decode.rs +++ b/gix-actor/src/signature/decode.rs @@ -5,12 +5,12 @@ pub(crate) mod function { use std::cell::RefCell; use winnow::{ branch::alt, - bytes::complete::{take, take_until, take_while_m_n}, - character::is_digit, + bytes::{take, take_until0, take_while_m_n}, error::{ContextError, ParseError}, - multi::many1_count, + multi::many1, prelude::*, - sequence::{terminated, tuple}, + sequence::terminated, + stream::AsChar, }; use crate::{IdentityRef, SignatureRef}; @@ -26,31 +26,31 @@ pub(crate) mod function { identity, b" ", (|i| { - terminated(take_until(SPACE), take(1usize))(i).and_then(|(i, v)| { + terminated(take_until0(SPACE), take(1usize))(i).and_then(|(i, v)| { btoi::(v) .map(|v| (i, v)) - .map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes)) + .map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes)) }) }) .context(""), alt(( - many1_count(b"-").map(|_| *tzsign.borrow_mut() = b'-'), // TODO: this should be a non-allocating consumer of consecutive tags - many1_count(b"+").map(|_| *tzsign.borrow_mut() = b'+'), + many1(b"-").map(|_: ()| *tzsign.borrow_mut() = b'-'), // TODO: this should be a non-allocating consumer of consecutive tags + many1(b"+").map(|_: ()| *tzsign.borrow_mut() = b'+'), )) .context("+|-"), (|i| { - take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| { + take_while_m_n(2usize, 2, AsChar::is_dec_digit)(i).and_then(|(i, v)| { btoi::(v) .map(|v| (i, v)) - .map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes)) + .map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes)) }) }) .context("HH"), (|i| { - take_while_m_n(1usize, 2, is_digit)(i).and_then(|(i, v)| { + take_while_m_n(1usize, 2, AsChar::is_dec_digit)(i).and_then(|(i, v)| { btoi::(v) .map(|v| (i, v)) - .map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes)) + .map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes)) }) }) .context("MM"), @@ -82,8 +82,8 @@ pub(crate) mod function { i: &'a [u8], ) -> IResult<&'a [u8], IdentityRef<'a>, E> { let (i, (name, email)) = ( - terminated(take_until(&b" <"[..]), take(2usize)).context(""), - terminated(take_until(&b">"[..]), take(1usize)).context(""), + terminated(take_until0(&b" <"[..]), take(2usize)).context(""), + terminated(take_until0(&b">"[..]), take(1usize)).context(""), ) .context(" <>") .parse_next(i)?; diff --git a/gix-actor/src/signature/mod.rs b/gix-actor/src/signature/mod.rs index f613553abde..8b7076deb3e 100644 --- a/gix-actor/src/signature/mod.rs +++ b/gix-actor/src/signature/mod.rs @@ -5,7 +5,7 @@ mod _ref { impl<'a> SignatureRef<'a> { /// Deserialize a signature from the given `data`. - pub fn from_bytes(data: &'a [u8]) -> Result, winnow::Err> + pub fn from_bytes(data: &'a [u8]) -> Result, winnow::error::ErrMode> where E: winnow::error::ParseError<&'a [u8]> + winnow::error::ContextError<&'a [u8]>, { diff --git a/gix-object/src/commit/decode.rs b/gix-object/src/commit/decode.rs index b136d5bb729..e016480b760 100644 --- a/gix-object/src/commit/decode.rs +++ b/gix-object/src/commit/decode.rs @@ -3,11 +3,12 @@ use std::borrow::Cow; use smallvec::SmallVec; use winnow::{ branch::alt, - bytes::complete::{is_not, tag}, - combinator::{all_consuming, opt}, + bytes::{tag, take_till1}, + combinator::{eof, opt}, error::{ContextError, ParseError}, multi::many0, prelude::*, + sequence::terminated, }; use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef}; @@ -15,8 +16,10 @@ use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef}; pub fn message<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> { if i.is_empty() { // newline + [message] - return Err(winnow::Err::from_error_kind(i, winnow::error::ErrorKind::Eof) - .map(|err: E| err.add_context(i, "newline + "))); + return Err( + winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Eof) + .map(|err: E| err.add_context(i, "newline + ")), + ); } let (i, _) = tag(NL) .context("a newline separates headers from the message") @@ -39,16 +42,18 @@ pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( let (i, committer) = (|i| parse::header_field(i, b"committer", parse::signature)) .context("committer ") .parse_next(i)?; - let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", is_not(NL))) + let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", take_till1(NL))) .context("encoding ") .parse_next(i)?; let (i, extra_headers) = many0(alt(( parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))), - |i| parse::any_header_field(i, is_not(NL)).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr())))), + |i| { + parse::any_header_field(i, take_till1(NL)).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr())))) + }, ))) .context(" ") .parse_next(i)?; - let (i, message) = all_consuming(message)(i)?; + let (i, message) = terminated(message, eof)(i)?; Ok(( i, diff --git a/gix-object/src/commit/message/body.rs b/gix-object/src/commit/message/body.rs index c52ad96dbd8..e1161fedf2a 100644 --- a/gix-object/src/commit/message/body.rs +++ b/gix-object/src/commit/message/body.rs @@ -1,8 +1,8 @@ use std::ops::Deref; use winnow::{ - bytes::complete::take_until1, - combinator::all_consuming, + bytes::take_until1, + combinator::eof, error::{ErrorKind, ParseError}, sequence::terminated, IResult, @@ -35,7 +35,7 @@ pub struct TrailerRef<'a> { fn parse_single_line_trailer<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], (&'a BStr, &'a BStr), E> { let (value, token) = terminated(take_until1(b":".as_ref()), b": ")(i.trim_end())?; if token.trim_end().len() != token.len() || value.trim_start().len() != value.len() { - Err(winnow::Err::from_error_kind(i, ErrorKind::Fail).cut()) + Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Fail).cut()) } else { Ok((&[], (token.as_bstr(), value.as_bstr()))) } @@ -51,7 +51,7 @@ impl<'a> Iterator for Trailers<'a> { for line in self.cursor.lines_with_terminator() { self.cursor = &self.cursor[line.len()..]; if let Some(trailer) = - all_consuming(parse_single_line_trailer::<()>)(line) + terminated(parse_single_line_trailer::<()>, eof)(line) .ok() .map(|(_, (token, value))| TrailerRef { token: token.trim().as_bstr(), diff --git a/gix-object/src/commit/message/decode.rs b/gix-object/src/commit/message/decode.rs index 74c73169ea3..e8b3a044d74 100644 --- a/gix-object/src/commit/message/decode.rs +++ b/gix-object/src/commit/message/decode.rs @@ -1,4 +1,4 @@ -use winnow::{branch::alt, bytes::complete::take_till1, combinator::all_consuming, error::ParseError, prelude::*}; +use winnow::{branch::alt, bytes::take_till1, combinator::eof, error::ParseError, prelude::*, sequence::terminated}; use crate::bstr::{BStr, ByteSlice}; @@ -46,5 +46,5 @@ fn subject_and_body<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8 /// Returns title and body, without separator pub fn message(input: &[u8]) -> (&BStr, Option<&BStr>) { - all_consuming(subject_and_body::<()>)(input).expect("cannot fail").1 + terminated(subject_and_body::<()>, eof)(input).expect("cannot fail").1 } diff --git a/gix-object/src/commit/ref_iter.rs b/gix-object/src/commit/ref_iter.rs index dc295c1c0f0..59f8229506c 100644 --- a/gix-object/src/commit/ref_iter.rs +++ b/gix-object/src/commit/ref_iter.rs @@ -5,9 +5,10 @@ use bstr::BStr; use gix_hash::{oid, ObjectId}; use winnow::{ branch::alt, - bytes::complete::is_not, - combinator::{all_consuming, opt}, + bytes::take_till1, + combinator::{eof, opt}, prelude::*, + sequence::terminated, }; use crate::commit::SignedData; @@ -207,7 +208,7 @@ impl<'a> CommitRefIter<'a> { ) } Encoding => { - let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", is_not(NL))) + let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", take_till1(NL))) .context("encoding ") .parse_next(i)?; *state = State::ExtraHeaders; @@ -220,7 +221,7 @@ impl<'a> CommitRefIter<'a> { let (i, extra_header) = opt(alt(( |i| parse::any_header_field_multi_line(i).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Owned(o)))), |i| { - parse::any_header_field(i, is_not(NL)) + parse::any_header_field(i, take_till1(NL)) .map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr())))) }, ))) @@ -235,7 +236,7 @@ impl<'a> CommitRefIter<'a> { } } Message => { - let (i, message) = all_consuming(decode::message)(i)?; + let (i, message) = terminated(decode::message, eof)(i)?; debug_assert!( i.is_empty(), "we should have consumed all data - otherwise iter may go forever" diff --git a/gix-object/src/lib.rs b/gix-object/src/lib.rs index e26f84c30d8..233d8880fc7 100644 --- a/gix-object/src/lib.rs +++ b/gix-object/src/lib.rs @@ -278,18 +278,20 @@ pub mod decode { pub inner: ParseErrorOwned, } - impl<'a> From>> for Error { - fn from(v: winnow::Err>) -> Self { + impl<'a> From>> for Error { + fn from(v: winnow::error::ErrMode>) -> Self { Error { inner: match v { - winnow::Err::Backtrack(err) | winnow::Err::Cut(err) => winnow::error::VerboseError { - errors: err - .errors - .into_iter() - .map(|(i, v)| (i.as_bstr().to_owned(), v)) - .collect(), - }, - winnow::Err::Incomplete(_) => unreachable!("we don't have streaming parsers"), + winnow::error::ErrMode::Backtrack(err) | winnow::error::ErrMode::Cut(err) => { + winnow::error::VerboseError { + errors: err + .errors + .into_iter() + .map(|(i, v)| (i.as_bstr().to_owned(), v)) + .collect(), + } + } + winnow::error::ErrMode::Incomplete(_) => unreachable!("we don't have streaming parsers"), }, } } @@ -321,12 +323,12 @@ pub mod decode { pub inner: ParseErrorOwned, } - impl<'a> From>> for Error { - fn from(v: winnow::Err>) -> Self { + impl<'a> From>> for Error { + fn from(v: winnow::error::ErrMode>) -> Self { Error { inner: match v { - winnow::Err::Backtrack(err) | winnow::Err::Cut(err) => err, - winnow::Err::Incomplete(_) => unreachable!("we don't have streaming parsers"), + winnow::error::ErrMode::Backtrack(err) | winnow::error::ErrMode::Cut(err) => err, + winnow::error::ErrMode::Incomplete(_) => unreachable!("we don't have streaming parsers"), }, } } diff --git a/gix-object/src/parse.rs b/gix-object/src/parse.rs index efdbb8fc360..abce6447df6 100644 --- a/gix-object/src/parse.rs +++ b/gix-object/src/parse.rs @@ -1,9 +1,9 @@ use bstr::{BStr, BString, ByteVec}; use winnow::{ - bytes::complete::{is_not, take_until, take_while_m_n}, + bytes::{take_till1, take_until0, take_while_m_n}, combinator::peek, error::{ContextError, ParseError}, - multi::many1_count, + multi::many1, prelude::*, sequence::{preceded, terminated}, }; @@ -18,8 +18,13 @@ pub(crate) fn any_header_field_multi_line<'a, E: ParseError<&'a [u8]> + ContextE i: &'a [u8], ) -> IResult<&'a [u8], (&'a [u8], BString), E> { let (i, (k, o)) = peek(( - terminated(is_not(SPACE_OR_NL), SPACE), - (is_not(NL), NL, many1_count(terminated((SPACE, take_until(NL)), NL))).recognize(), + terminated(take_till1(SPACE_OR_NL), SPACE), + ( + take_till1(NL), + NL, + many1(terminated((SPACE, take_until0(NL)), NL)).map(|()| ()), + ) + .recognize(), )) .context("name ") .parse_next(i)?; @@ -41,16 +46,16 @@ pub(crate) fn any_header_field_multi_line<'a, E: ParseError<&'a [u8]> + ContextE pub(crate) fn header_field<'a, T, E: ParseError<&'a [u8]>>( i: &'a [u8], name: &'static [u8], - parse_value: impl Fn(&'a [u8]) -> IResult<&'a [u8], T, E>, + parse_value: impl FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, ) -> IResult<&'a [u8], T, E> { terminated(preceded(terminated(name, SPACE), parse_value), NL)(i) } pub(crate) fn any_header_field<'a, T, E: ParseError<&'a [u8]>>( i: &'a [u8], - parse_value: impl Fn(&'a [u8]) -> IResult<&'a [u8], T, E>, + parse_value: impl FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, ) -> IResult<&'a [u8], (&'a [u8], T), E> { - terminated((terminated(is_not(SPACE_OR_NL), SPACE), parse_value), NL)(i) + terminated((terminated(take_till1(SPACE_OR_NL), SPACE), parse_value), NL)(i) } fn is_hex_digit_lc(b: u8) -> bool { diff --git a/gix-object/src/tag/decode.rs b/gix-object/src/tag/decode.rs index 24c1067e5eb..7094c8dfb23 100644 --- a/gix-object/src/tag/decode.rs +++ b/gix-object/src/tag/decode.rs @@ -1,11 +1,11 @@ use winnow::{ branch::alt, - bytes::complete::{tag, take_until, take_while, take_while1}, - character::is_alphabetic, - combinator::{all_consuming, opt}, + bytes::{tag, take_until0, take_while0, take_while1}, + combinator::{eof, opt}, error::{ContextError, ParseError}, prelude::*, - sequence::preceded, + sequence::{preceded, terminated}, + stream::AsChar, }; use crate::{parse, parse::NL, BStr, ByteSlice, TagRef}; @@ -15,11 +15,11 @@ pub fn git_tag<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8] .context("object <40 lowercase hex char>") .parse_next(i)?; - let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(is_alphabetic))) + let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(AsChar::is_alpha))) .context("type ") .parse_next(i)?; - let kind = - crate::Kind::from_bytes(kind).map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes))?; + let kind = crate::Kind::from_bytes(kind) + .map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes))?; let (i, tag_version) = (|i| parse::header_field(i, b"tag", take_while1(|b| b != NL[0]))) .context("tag ") @@ -28,7 +28,7 @@ pub fn git_tag<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8] let (i, signature) = opt(|i| parse::header_field(i, b"tagger", parse::signature)) .context("tagger ") .parse_next(i)?; - let (i, (message, pgp_signature)) = all_consuming(message)(i)?; + let (i, (message, pgp_signature)) = terminated(message, eof)(i)?; Ok(( i, TagRef { @@ -61,14 +61,14 @@ pub fn message<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], (& } let (i, (message, signature)) = alt(( ( - take_until(PGP_SIGNATURE_BEGIN), + take_until0(PGP_SIGNATURE_BEGIN), preceded( NL, ( &PGP_SIGNATURE_BEGIN[1..], - take_until(PGP_SIGNATURE_END), + take_until0(PGP_SIGNATURE_END), PGP_SIGNATURE_END, - take_while(|_| true), + take_while0(|_| true), ) .recognize(), ), diff --git a/gix-object/src/tag/ref_iter.rs b/gix-object/src/tag/ref_iter.rs index 4c81ebb6c1d..95408f0508e 100644 --- a/gix-object/src/tag/ref_iter.rs +++ b/gix-object/src/tag/ref_iter.rs @@ -1,11 +1,12 @@ use bstr::BStr; use gix_hash::{oid, ObjectId}; use winnow::{ - bytes::complete::take_while1, - character::is_alphabetic, - combinator::{all_consuming, opt}, + bytes::take_while1, + combinator::{eof, opt}, error::ParseError, prelude::*, + sequence::terminated, + stream::AsChar, }; use crate::{bstr::ByteSlice, parse, parse::NL, tag::decode, Kind, TagRefIter}; @@ -74,11 +75,11 @@ impl<'a> TagRefIter<'a> { ) } TargetKind => { - let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(is_alphabetic))) + let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(AsChar::is_alpha))) .context("type ") .parse_next(i)?; let kind = Kind::from_bytes(kind) - .map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes))?; + .map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes))?; *state = Name; (i, Token::TargetKind(kind)) } @@ -97,7 +98,7 @@ impl<'a> TagRefIter<'a> { (i, Token::Tagger(signature)) } Message => { - let (i, (message, pgp_signature)) = all_consuming(decode::message)(i)?; + let (i, (message, pgp_signature)) = terminated(decode::message, eof)(i)?; debug_assert!( i.is_empty(), "we should have consumed all data - otherwise iter may go forever" diff --git a/gix-object/src/tree/ref_iter.rs b/gix-object/src/tree/ref_iter.rs index 6207ed1bafa..58e1841cbff 100644 --- a/gix-object/src/tree/ref_iter.rs +++ b/gix-object/src/tree/ref_iter.rs @@ -69,7 +69,7 @@ impl<'a> Iterator for TreeRefIter<'a> { None => { self.data = &[]; #[allow(clippy::unit_arg)] - Some(Err(winnow::Err::from_error_kind( + Some(Err(winnow::error::ErrMode::from_error_kind( &[] as &[u8], winnow::error::ErrorKind::MapRes, ) @@ -118,12 +118,12 @@ mod decode { use bstr::ByteSlice; use winnow::{ - bytes::complete::{take, take_while1, take_while_m_n}, - character::is_digit, - combinator::all_consuming, + bytes::{take, take_while1, take_while_m_n}, + combinator::eof, error::ParseError, multi::many0, sequence::terminated, + stream::AsChar, IResult, }; @@ -161,9 +161,9 @@ mod decode { } pub fn entry<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&[u8], EntryRef<'_>, E> { - let (i, mode) = terminated(take_while_m_n(5, 6, is_digit), SPACE)(i)?; + let (i, mode) = terminated(take_while_m_n(5, 6, AsChar::is_dec_digit), SPACE)(i)?; let mode = tree::EntryMode::try_from(mode) - .map_err(|invalid| winnow::Err::from_error_kind(invalid, winnow::error::ErrorKind::MapRes))?; + .map_err(|invalid| winnow::error::ErrMode::from_error_kind(invalid, winnow::error::ErrorKind::MapRes))?; let (i, filename) = terminated(take_while1(|b| b != NULL[0]), NULL)(i)?; let (i, oid) = take(20u8)(i)?; // TODO: make this compatible with other hash lengths @@ -178,7 +178,7 @@ mod decode { } pub fn tree<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], TreeRef<'a>, E> { - let (i, entries) = all_consuming(many0(entry))(i)?; + let (i, entries) = terminated(many0(entry), eof)(i)?; Ok((i, TreeRef { entries })) } } diff --git a/gix-ref/src/parse.rs b/gix-ref/src/parse.rs index 3e719f750c7..15085f52319 100644 --- a/gix-ref/src/parse.rs +++ b/gix-ref/src/parse.rs @@ -1,5 +1,5 @@ use gix_object::bstr::{BStr, ByteSlice}; -use winnow::{branch::alt, bytes::complete::take_while_m_n, error::ParseError, IResult}; +use winnow::{branch::alt, bytes::take_while_m_n, error::ParseError, IResult}; fn is_hex_digit_lc(b: u8) -> bool { matches!(b, b'0'..=b'9' | b'a'..=b'f') diff --git a/gix-ref/src/store/file/log/line.rs b/gix-ref/src/store/file/log/line.rs index 4cf92443d2d..360430f54a9 100644 --- a/gix-ref/src/store/file/log/line.rs +++ b/gix-ref/src/store/file/log/line.rs @@ -75,7 +75,7 @@ impl<'a> From> for Line { pub mod decode { use gix_object::bstr::{BStr, ByteSlice}; use winnow::{ - bytes::complete::take_while, + bytes::take_while0, combinator::opt, error::{ContextError, ParseError}, prelude::*, @@ -127,7 +127,7 @@ pub mod decode { if i.is_empty() { Ok((&[], i.as_bstr())) } else { - terminated(take_while(|c| c != b'\n'), opt(b'\n'))(i).map(|(i, o)| (i, o.as_bstr())) + terminated(take_while0(|c| c != b'\n'), opt(b'\n'))(i).map(|(i, o)| (i, o.as_bstr())) } } @@ -146,7 +146,7 @@ pub mod decode { if let Some(first) = message.first() { if !first.is_ascii_whitespace() { return Err( - winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes).map(|err: E| { + winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes).map(|err: E| { err.add_context(i, "log message must be separated from signature with whitespace") }), ); diff --git a/gix-ref/src/store/file/loose/reference/decode.rs b/gix-ref/src/store/file/loose/reference/decode.rs index 91a66587d7b..51a86f9d8ff 100644 --- a/gix-ref/src/store/file/loose/reference/decode.rs +++ b/gix-ref/src/store/file/loose/reference/decode.rs @@ -2,7 +2,7 @@ use std::convert::{TryFrom, TryInto}; use gix_hash::ObjectId; use gix_object::bstr::BString; -use winnow::{bytes::complete::take_while, combinator::opt, prelude::*, sequence::terminated}; +use winnow::{bytes::take_while0, combinator::opt, prelude::*, sequence::terminated}; use crate::{ parse::{hex_hash, newline}, @@ -67,8 +67,8 @@ impl Reference { fn parse(bytes: &[u8]) -> IResult<&[u8], MaybeUnsafeState> { let is_space = |b: u8| b == b' '; - if let (path, Some(_ref_prefix)) = opt(terminated("ref: ", take_while(is_space)))(bytes)? { - terminated(take_while(|b| b != b'\r' && b != b'\n'), opt(newline)) + if let (path, Some(_ref_prefix)) = opt(terminated("ref: ", take_while0(is_space)))(bytes)? { + terminated(take_while0(|b| b != b'\r' && b != b'\n'), opt(newline)) .map(|path| MaybeUnsafeState::UnvalidatedPath(path.into())) .parse_next(path) } else { diff --git a/gix-ref/src/store/packed/decode.rs b/gix-ref/src/store/packed/decode.rs index a9a0f599740..0b60051085f 100644 --- a/gix-ref/src/store/packed/decode.rs +++ b/gix-ref/src/store/packed/decode.rs @@ -2,7 +2,7 @@ use std::convert::TryInto; use gix_object::bstr::{BStr, ByteSlice}; use winnow::{ - bytes::complete::take_while, + bytes::take_while0, combinator::opt, error::{FromExternalError, ParseError}, prelude::*, @@ -41,7 +41,7 @@ fn until_newline<'a, E>(input: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> where E: ParseError<&'a [u8]>, { - terminated(take_while(|b: u8| b != b'\r' && b != b'\n'), newline) + terminated(take_while0(|b: u8| b != b'\r' && b != b'\n'), newline) .map(ByteSlice::as_bstr) .parse_next(input) } diff --git a/tests/tools/src/lib.rs b/tests/tools/src/lib.rs index 11ad927a933..defd5e8fe39 100644 --- a/tests/tools/src/lib.rs +++ b/tests/tools/src/lib.rs @@ -692,10 +692,10 @@ fn extract_archive( } /// Transform a verbose bom errors from raw bytes into a `BStr` to make printing/debugging human-readable. -pub fn to_bstr_err(err: winnow::Err>) -> VerboseError<&BStr> { +pub fn to_bstr_err(err: winnow::error::ErrMode>) -> VerboseError<&BStr> { let err = match err { - winnow::Err::Backtrack(err) | winnow::Err::Cut(err) => err, - winnow::Err::Incomplete(_) => unreachable!("not a streaming parser"), + winnow::error::ErrMode::Backtrack(err) | winnow::error::ErrMode::Cut(err) => err, + winnow::error::ErrMode::Incomplete(_) => unreachable!("not a streaming parser"), }; VerboseError { errors: err.errors.into_iter().map(|(i, v)| (i.as_bstr(), v)).collect(),