Skip to content

Commit 3f8c91f

Browse files
committed
Upgrade to Winnow 0.5
1 parent 12f03db commit 3f8c91f

File tree

31 files changed

+212
-194
lines changed

31 files changed

+212
-194
lines changed

Cargo.lock

Lines changed: 7 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-smart-release/Cargo.lock

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

cargo-smart-release/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ toml_edit = "0.19.1"
3434
semver = "1.0.4"
3535
crates-index = { version = "2.1.0", default-features = false, features = ["git-performance", "git-https"] }
3636
cargo_toml = "0.15.1"
37-
winnow = "0.5.1"
37+
winnow = "0.5.12"
3838
git-conventional = "0.12.0"
3939
time = "0.3.23"
4040
pulldown-cmark = "0.9.0"

gix-actor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ gix-date = { version = "^0.7.1", path = "../gix-date" }
2323
thiserror = "1.0.38"
2424
btoi = "0.4.2"
2525
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"]}
26-
winnow = { version = "0.4", features = ["simd"] }
26+
winnow = { version = "0.5.12", features = ["simd"] }
2727
itoa = "1.0.1"
2828
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
2929

gix-actor/src/identity.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use bstr::ByteSlice;
2+
use winnow::prelude::*;
23

34
use crate::{signature::decode, Identity, IdentityRef};
45

56
impl<'a> IdentityRef<'a> {
67
/// Deserialize an identity from the given `data`.
7-
pub fn from_bytes<E>(data: &'a [u8]) -> Result<Self, winnow::error::ErrMode<E>>
8+
pub fn from_bytes<E>(mut data: &'a [u8]) -> Result<Self, winnow::error::ErrMode<E>>
89
where
910
E: winnow::error::ParserError<&'a [u8]> + winnow::error::AddContext<&'a [u8]>,
1011
{
11-
decode::identity(data).map(|(_, t)| t)
12+
decode::identity.parse_next(&mut data)
1213
}
1314

1415
/// Create an owned instance from this shared one.

gix-actor/src/signature/decode.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub(crate) mod function {
1919

2020
/// Parse a signature from the bytes input `i` using `nom`.
2121
pub fn decode<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(
22-
i: &'a [u8],
23-
) -> IResult<&'a [u8], SignatureRef<'a>, E> {
22+
i: &mut &'a [u8],
23+
) -> PResult<SignatureRef<'a>, E> {
2424
separated_pair(
2525
identity,
2626
b" ",
@@ -60,8 +60,8 @@ pub(crate) mod function {
6060

6161
/// Parse an identity from the bytes input `i` (like `name <email>`) using `nom`.
6262
pub fn identity<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(
63-
i: &'a [u8],
64-
) -> IResult<&'a [u8], IdentityRef<'a>, E> {
63+
i: &mut &'a [u8],
64+
) -> PResult<IdentityRef<'a>, E> {
6565
(
6666
terminated(take_until0(&b" <"[..]), take(2usize)).context("<name>"),
6767
terminated(take_until0(&b">"[..]), take(1usize)).context("<email>"),
@@ -82,12 +82,14 @@ mod tests {
8282
use bstr::ByteSlice;
8383
use gix_date::{time::Sign, OffsetInSeconds, SecondsSinceUnixEpoch};
8484
use gix_testtools::to_bstr_err;
85-
use winnow::IResult;
85+
use winnow::prelude::*;
8686

8787
use crate::{signature, SignatureRef, Time};
8888

89-
fn decode(i: &[u8]) -> IResult<&[u8], SignatureRef<'_>, winnow::error::VerboseError<&[u8]>> {
90-
signature::decode(i)
89+
fn decode<'i>(
90+
i: &mut &'i [u8],
91+
) -> PResult<SignatureRef<'i>, winnow::error::VerboseError<&'i [u8], &'static str>> {
92+
signature::decode.parse_next(i)
9193
}
9294

9395
fn signature(
@@ -107,7 +109,8 @@ mod tests {
107109
#[test]
108110
fn tz_minus() {
109111
assert_eq!(
110-
decode(b"Sebastian Thiel <[email protected]> 1528473343 -0230")
112+
decode
113+
.parse_peek(b"Sebastian Thiel <[email protected]> 1528473343 -0230")
111114
.expect("parse to work")
112115
.1,
113116
signature("Sebastian Thiel", "[email protected]", 1528473343, Sign::Minus, -9000)
@@ -117,7 +120,8 @@ mod tests {
117120
#[test]
118121
fn tz_plus() {
119122
assert_eq!(
120-
decode(b"Sebastian Thiel <[email protected]> 1528473343 +0230")
123+
decode
124+
.parse_peek(b"Sebastian Thiel <[email protected]> 1528473343 +0230")
121125
.expect("parse to work")
122126
.1,
123127
signature("Sebastian Thiel", "[email protected]", 1528473343, Sign::Plus, 9000)
@@ -127,7 +131,8 @@ mod tests {
127131
#[test]
128132
fn negative_offset_0000() {
129133
assert_eq!(
130-
decode(b"Sebastian Thiel <[email protected]> 1528473343 -0000")
134+
decode
135+
.parse_peek(b"Sebastian Thiel <[email protected]> 1528473343 -0000")
131136
.expect("parse to work")
132137
.1,
133138
signature("Sebastian Thiel", "[email protected]", 1528473343, Sign::Minus, 0)
@@ -137,7 +142,8 @@ mod tests {
137142
#[test]
138143
fn negative_offset_double_dash() {
139144
assert_eq!(
140-
decode(b"name <[email protected]> 1288373970 --700")
145+
decode
146+
.parse_peek(b"name <[email protected]> 1288373970 --700")
141147
.expect("parse to work")
142148
.1,
143149
signature("name", "[email protected]", 1288373970, Sign::Minus, -252000)
@@ -147,30 +153,30 @@ mod tests {
147153
#[test]
148154
fn empty_name_and_email() {
149155
assert_eq!(
150-
decode(b" <> 12345 -1215").expect("parse to work").1,
156+
decode.parse_peek(b" <> 12345 -1215").expect("parse to work").1,
151157
signature("", "", 12345, Sign::Minus, -44100)
152158
);
153159
}
154160

155161
#[test]
156162
fn invalid_signature() {
157163
assert_eq!(
158-
decode(b"hello < 12345 -1215")
164+
decode.parse_peek(b"hello < 12345 -1215")
159165
.map_err(to_bstr_err)
160166
.expect_err("parse fails as > is missing")
161167
.to_string(),
162-
"Parse error:\nSlice at: 12345 -1215\nin section '<email>', at: 12345 -1215\nin section '<name> <<email>>', at: hello < 12345 -1215\nin section '<name> <<email>> <timestamp> <+|-><HHMM>', at: hello < 12345 -1215\n"
168+
"Parse error:\nslice at: 12345 -1215\nin section '<email>', at: 12345 -1215\nin section '<name> <<email>>', at: 12345 -1215\nin section '<name> <<email>> <timestamp> <+|-><HHMM>', at: 12345 -1215\n"
163169
);
164170
}
165171

166172
#[test]
167173
fn invalid_time() {
168174
assert_eq!(
169-
decode(b"hello <> abc -1215")
175+
decode.parse_peek(b"hello <> abc -1215")
170176
.map_err(to_bstr_err)
171177
.expect_err("parse fails as > is missing")
172178
.to_string(),
173-
"Parse error:\nVerify at: abc -1215\nin section '<timestamp>', at: abc -1215\nin section '<name> <<email>> <timestamp> <+|-><HHMM>', at: hello <> abc -1215\n"
179+
"Parse error:\npredicate verification at: abc -1215\nin section '<timestamp>', at: abc -1215\nin section '<name> <<email>> <timestamp> <+|-><HHMM>', at: abc -1215\n"
174180
);
175181
}
176182
}

gix-actor/src/signature/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
mod _ref {
22
use bstr::ByteSlice;
3+
use winnow::prelude::*;
34

45
use crate::{signature::decode, IdentityRef, Signature, SignatureRef};
56

67
impl<'a> SignatureRef<'a> {
78
/// Deserialize a signature from the given `data`.
8-
pub fn from_bytes<E>(data: &'a [u8]) -> Result<SignatureRef<'a>, winnow::error::ErrMode<E>>
9+
pub fn from_bytes<E>(mut data: &'a [u8]) -> Result<SignatureRef<'a>, winnow::error::ErrMode<E>>
910
where
1011
E: winnow::error::ParserError<&'a [u8]> + winnow::error::AddContext<&'a [u8]>,
1112
{
12-
decode(data).map(|(_, t)| t)
13+
decode.parse_next(&mut data)
1314
}
1415

1516
/// Create an owned instance from this shared one.

gix-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gix-ref = { version = "^0.34.0", path = "../gix-ref" }
2525
gix-glob = { version = "^0.10.2", path = "../gix-glob" }
2626

2727
log = "0.4.17"
28-
winnow = { version = "0.5", features = ["simd"] }
28+
winnow = { version = "0.5.12", features = ["simd"] }
2929
memchr = "2"
3030
thiserror = "1.0.26"
3131
unicode-bom = "2.0.2"

gix-object/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ btoi = "0.4.2"
3838
itoa = "1.0.1"
3939
thiserror = "1.0.34"
4040
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
41-
winnow = { version = "0.4", features = ["simd"] }
41+
winnow = { version = "0.5.12", features = ["simd"] }
4242
smallvec = { version = "1.4.0", features = ["write"] }
4343
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
4444

gix-object/src/commit/decode.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use winnow::{
1414

1515
use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef};
1616

17-
pub fn message<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
17+
pub fn message<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<&'a BStr, E> {
1818
if i.is_empty() {
1919
// newline + [message]
2020
return Err(
@@ -27,22 +27,21 @@ pub fn message<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(i: &'a [u8])
2727
.parse_next(i)
2828
}
2929

30-
pub fn commit<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], CommitRef<'a>, E> {
30+
pub fn commit<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<CommitRef<'a>, E> {
3131
(
32-
(|i| parse::header_field(i, b"tree", parse::hex_hash)).context("tree <40 lowercase hex char>"),
33-
repeat(0.., |i| parse::header_field(i, b"parent", parse::hex_hash))
32+
(|i: &mut _| parse::header_field(i, b"tree", parse::hex_hash)).context("tree <40 lowercase hex char>"),
33+
repeat(0.., |i: &mut _| parse::header_field(i, b"parent", parse::hex_hash))
3434
.map(|p: Vec<_>| p)
3535
.context("zero or more 'parent <40 lowercase hex char>'"),
36-
(|i| parse::header_field(i, b"author", parse::signature)).context("author <signature>"),
37-
(|i| parse::header_field(i, b"committer", parse::signature)).context("committer <signature>"),
38-
opt(|i| parse::header_field(i, b"encoding", take_till1(NL))).context("encoding <encoding>"),
36+
(|i: &mut _| parse::header_field(i, b"author", parse::signature)).context("author <signature>"),
37+
(|i: &mut _| parse::header_field(i, b"committer", parse::signature)).context("committer <signature>"),
38+
opt(|i: &mut _| parse::header_field(i, b"encoding", take_till1(NL))).context("encoding <encoding>"),
3939
repeat(
4040
0..,
4141
alt((
4242
parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))),
43-
|i| {
44-
parse::any_header_field(i, take_till1(NL))
45-
.map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr()))))
43+
|i: &mut _| {
44+
parse::any_header_field(i, take_till1(NL)).map(|(k, o)| (k.as_bstr(), Cow::Borrowed(o.as_bstr())))
4645
},
4746
)),
4847
)

0 commit comments

Comments
 (0)