Skip to content

Commit e151dda

Browse files
committed
fix!: remove winnow and replace it with hand-implemented parsers everywhere.
1 parent 4bc48f3 commit e151dda

42 files changed

Lines changed: 993 additions & 998 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/hours/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ impl ParsedIdentity<'_> {
7171

7272
fn parse_trailer_identity(trailer: gix::objs::commit::message::body::TrailerRef<'_>) -> Option<ParsedIdentity<'_>> {
7373
match trailer.value {
74-
std::borrow::Cow::Borrowed(value) => IdentityRef::from_bytes::<gix::objs::decode::ParseError>(value.as_ref())
74+
std::borrow::Cow::Borrowed(value) => IdentityRef::from_bytes(value.as_ref())
7575
.ok()
7676
.map(|identity| ParsedIdentity::Borrowed(identity.trim())),
77-
std::borrow::Cow::Owned(value) => IdentityRef::from_bytes::<gix::objs::decode::ParseError>(value.as_ref())
77+
std::borrow::Cow::Owned(value) => IdentityRef::from_bytes(value.as_ref())
7878
.ok()
7979
.map(|identity| ParsedIdentity::Owned(identity.trim().to_owned())),
8080
}

gitoxide-core/src/repository/mailmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn check(
7171

7272
let mut buf = Vec::new();
7373
for contact in contacts {
74-
let actor = match gix::actor::IdentityRef::from_bytes::<()>(&contact) {
74+
let actor = match gix::actor::IdentityRef::from_bytes(&contact) {
7575
Ok(a) => a,
7676
Err(_) => {
7777
let Some(email) = contact

gix-actor/src/decode.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

gix-actor/src/identity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{signature::decode, Identity, IdentityRef};
44

55
impl<'a> IdentityRef<'a> {
66
/// Deserialize an identity from the given `data`.
7-
pub fn from_bytes(mut data: &'a [u8]) -> Result<Self, crate::decode::Error> {
7+
pub fn from_bytes(mut data: &'a [u8]) -> Result<Self, gix_error::ValidationError> {
88
decode::identity(&mut data)
99
}
1010

gix-actor/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ use bstr::{BStr, BString};
4444
/// For convenience to allow using `gix-date` without adding it to own cargo manifest.
4545
pub use gix_date as date;
4646

47-
/// Decode actor identities and signatures.
48-
pub mod decode;
4947
mod identity;
5048
///
5149
pub mod signature;

gix-actor/src/signature/decode.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
pub(crate) mod function {
22
use bstr::ByteSlice;
3+
use gix_error::ValidationError;
34

4-
use crate::{decode::Error, IdentityRef, SignatureRef};
5+
use crate::{IdentityRef, SignatureRef};
56

67
/// Parse a signature from the bytes input `i`, and change it to point to the unparsed bytes afterwards.
7-
pub fn decode<'a>(i: &mut &'a [u8]) -> Result<SignatureRef<'a>, Error> {
8+
pub fn decode<'a>(i: &mut &'a [u8]) -> Result<SignatureRef<'a>, ValidationError> {
89
let identity = identity(i)?;
910
if i.first() == Some(&b' ') {
1011
*i = &i[1..];
@@ -25,19 +26,23 @@ pub(crate) mod function {
2526
}
2627

2728
/// Parse an identity from the bytes input `i` (like `name <email>`).
28-
pub fn identity<'a>(i: &mut &'a [u8]) -> Result<IdentityRef<'a>, Error> {
29+
pub fn identity<'a>(i: &mut &'a [u8]) -> Result<IdentityRef<'a>, ValidationError> {
2930
let eol_idx = i.find_byte(b'\n').unwrap_or(i.len());
30-
let right_delim_idx = i[..eol_idx].rfind_byte(b'>').ok_or(Error::MissingClosingBracket)?;
31+
let right_delim_idx = i[..eol_idx]
32+
.rfind_byte(b'>')
33+
.ok_or_else(|| ValidationError::new("Closing '>' not found"))?;
3134
let i_name_and_email = &i[..right_delim_idx];
3235
let skip_from_right = i_name_and_email.iter().rev().take_while(|b| **b == b'>').count();
33-
let left_delim_idx = i_name_and_email.find_byte(b'<').ok_or(Error::MissingOpeningBracket)?;
36+
let left_delim_idx = i_name_and_email
37+
.find_byte(b'<')
38+
.ok_or_else(|| ValidationError::new("Opening '<' not found"))?;
3439
let skip_from_left = i[left_delim_idx..].iter().take_while(|b| **b == b'<').count();
3540
let mut name = i[..left_delim_idx].as_bstr();
3641
name = name.strip_suffix(b" ").unwrap_or(name).as_bstr();
3742

3843
let email = i
3944
.get(left_delim_idx + skip_from_left..right_delim_idx - skip_from_right)
40-
.ok_or(Error::DelimiterOverlap)?
45+
.ok_or_else(|| ValidationError::new("Skipped parts run into each other"))?
4146
.as_bstr();
4247
*i = i.get(right_delim_idx + 1..).unwrap_or(&[]);
4348
Ok(IdentityRef { name, email })
@@ -52,9 +57,11 @@ pub use function::identity;
5257
#[cfg(test)]
5358
mod tests {
5459
mod parse_signature {
55-
use crate::{decode::Error, signature, SignatureRef};
60+
use gix_error::ValidationError;
5661

57-
fn decode(i: &[u8]) -> Result<(&[u8], SignatureRef<'_>), Error> {
62+
use crate::{signature, SignatureRef};
63+
64+
fn decode(i: &[u8]) -> Result<(&[u8], SignatureRef<'_>), ValidationError> {
5865
let mut i = i;
5966
signature::decode(&mut i).map(|signature| (i, signature))
6067
}
@@ -137,8 +144,10 @@ mod tests {
137144
#[test]
138145
fn invalid_signature() {
139146
assert_eq!(
140-
decode(b"hello < 12345 -1215").expect_err("parse fails as > is missing"),
141-
Error::MissingClosingBracket
147+
decode(b"hello < 12345 -1215")
148+
.expect_err("parse fails as > is missing")
149+
.to_string(),
150+
"Closing '>' not found"
142151
);
143152
}
144153

gix-actor/src/signature/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod _ref {
66
/// Lifecycle
77
impl<'a> SignatureRef<'a> {
88
/// Deserialize a signature from the given `data`.
9-
pub fn from_bytes(mut data: &'a [u8]) -> Result<SignatureRef<'a>, crate::decode::Error> {
9+
pub fn from_bytes(mut data: &'a [u8]) -> Result<SignatureRef<'a>, gix_error::ValidationError> {
1010
decode(&mut data)
1111
}
1212

gix-config/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ gix-sec = { version = "^0.13.3", path = "../gix-sec" }
2828
gix-ref = { version = "^0.62.0", path = "../gix-ref" }
2929
gix-glob = { version = "^0.25.0", path = "../gix-glob" }
3030

31-
winnow = { version = "1.0.0", features = ["simd"] }
3231
memchr = "2"
3332
thiserror = "2.0.18"
3433
unicode-bom = { version = "2.0.3" }

0 commit comments

Comments
 (0)