Skip to content

Commit 16cac47

Browse files
authored
Merge pull request #1009 from epage/proto
Migrate gix-protocol to winnow
2 parents 72328a3 + 444f970 commit 16cac47

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

Cargo.lock

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

gix-protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ gix-credentials = { version = "^0.18.0", path = "../gix-credentials" }
4949
thiserror = "1.0.32"
5050
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
5151
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
52-
nom = { version = "7", default-features = false, features = ["std"]}
52+
winnow = { version = "0.5.14", features = ["simd"] }
5353
btoi = "0.4.2"
5454

5555
# for async-client

gix-protocol/src/remote_progress.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::convert::TryFrom;
22

33
use bstr::ByteSlice;
4-
use nom::{
5-
bytes::complete::{tag, take_till, take_till1},
6-
combinator::{map_res, opt},
7-
sequence::{preceded, terminated},
4+
use winnow::{
5+
combinator::opt,
6+
combinator::{preceded, terminated},
7+
prelude::*,
8+
token::{tag, take_till0, take_till1},
89
};
910

1011
/// The information usually found in remote progress messages as sent by a git server during
@@ -25,8 +26,8 @@ pub struct RemoteProgress<'a> {
2526

2627
impl<'a> RemoteProgress<'a> {
2728
/// Parse the progress from a typical git progress `line` as sent by the remote.
28-
pub fn from_bytes(line: &[u8]) -> Option<RemoteProgress<'_>> {
29-
parse_progress(line).ok().and_then(|(_, r)| {
29+
pub fn from_bytes(mut line: &[u8]) -> Option<RemoteProgress<'_>> {
30+
parse_progress(&mut line).ok().and_then(|r| {
3031
if r.percent.is_none() && r.step.is_none() && r.max.is_none() {
3132
None
3233
} else {
@@ -73,36 +74,36 @@ impl<'a> RemoteProgress<'a> {
7374
}
7475
}
7576

76-
fn parse_number(i: &[u8]) -> nom::IResult<&[u8], usize> {
77-
map_res(take_till(|c: u8| !c.is_ascii_digit()), btoi::btoi)(i)
77+
fn parse_number(i: &mut &[u8]) -> PResult<usize, ()> {
78+
take_till0(|c: u8| !c.is_ascii_digit())
79+
.try_map(btoi::btoi)
80+
.parse_next(i)
7881
}
7982

80-
fn next_optional_percentage(i: &[u8]) -> nom::IResult<&[u8], Option<u32>> {
83+
fn next_optional_percentage(i: &mut &[u8]) -> PResult<Option<u32>, ()> {
8184
opt(terminated(
8285
preceded(
83-
take_till(|c: u8| c.is_ascii_digit()),
84-
map_res(parse_number, u32::try_from),
86+
take_till0(|c: u8| c.is_ascii_digit()),
87+
parse_number.try_map(u32::try_from),
8588
),
8689
tag(b"%"),
87-
))(i)
90+
))
91+
.parse_next(i)
8892
}
8993

90-
fn next_optional_number(i: &[u8]) -> nom::IResult<&[u8], Option<usize>> {
91-
opt(preceded(take_till(|c: u8| c.is_ascii_digit()), parse_number))(i)
94+
fn next_optional_number(i: &mut &[u8]) -> PResult<Option<usize>, ()> {
95+
opt(preceded(take_till0(|c: u8| c.is_ascii_digit()), parse_number)).parse_next(i)
9296
}
9397

94-
fn parse_progress(line: &[u8]) -> nom::IResult<&[u8], RemoteProgress<'_>> {
95-
let (i, action) = take_till1(|c| c == b':')(line)?;
96-
let (i, percent) = next_optional_percentage(i)?;
97-
let (i, step) = next_optional_number(i)?;
98-
let (i, max) = next_optional_number(i)?;
99-
Ok((
100-
i,
101-
RemoteProgress {
102-
action: action.into(),
103-
percent,
104-
step,
105-
max,
106-
},
107-
))
98+
fn parse_progress<'i>(line: &mut &'i [u8]) -> PResult<RemoteProgress<'i>, ()> {
99+
let action = take_till1(|c| c == b':').parse_next(line)?;
100+
let percent = next_optional_percentage.parse_next(line)?;
101+
let step = next_optional_number.parse_next(line)?;
102+
let max = next_optional_number.parse_next(line)?;
103+
Ok(RemoteProgress {
104+
action: action.into(),
105+
percent,
106+
step,
107+
max,
108+
})
108109
}

0 commit comments

Comments
 (0)