Skip to content

Commit

Permalink
[clone] move packet-lint into transport layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 18, 2020
1 parent a562059 commit c0dd831
Show file tree
Hide file tree
Showing 23 changed files with 59 additions and 52 deletions.
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions git-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ doctest = false
serde1 = ["serde", "bstr/serde1"]

[dependencies]
git-features = { version = "^0.3.0", path = "../git-features" }
git-transport = { version = "^0.1.0", path = "../git-transport" }

quick-error = "2.0.0"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
bstr = { version = "0.2.13", default-features = false, features = ["std"] }
nom = { version = "6.0.0-alpha1", default-features = false, features = ["alloc"]}
btoi = "0.4.2"
hex = "0.4.2"

[dev-dependencies]
git-odb = { version = "0.3.0", path = "../git-odb" }
9 changes: 2 additions & 7 deletions git-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#![forbid(unsafe_code)]

pub mod packet_line;

mod progress;
pub use progress::RemoteProgress;

#[doc(inline)]
pub use packet_line::Borrowed as PacketLine;
mod remote_progress;
pub use remote_progress::from_bytes as parse_remote_progress;
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
use bstr::BStr;
use git_transport::RemoteProgress;
use nom::{
bytes::complete::{tag, take_till, take_till1},
combinator::{map_res, opt},
sequence::{preceded, terminated},
};
use std::convert::TryFrom;

#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct RemoteProgress<'a> {
#[cfg_attr(feature = "serde1", serde(borrow))]
pub action: &'a BStr,
pub percent: Option<u32>,
pub step: Option<usize>,
pub max: Option<usize>,
}

impl<'a> RemoteProgress<'a> {
pub fn from_bytes(line: &'a [u8]) -> Option<Self> {
parse_progress(line).ok().and_then(|(_, r)| {
if r.percent.is_none() && r.step.is_none() && r.max.is_none() {
None
} else {
Some(r)
}
})
}
pub fn from_bytes(line: &[u8]) -> Option<RemoteProgress> {
parse_progress(line).ok().and_then(|(_, r)| {
if r.percent.is_none() && r.step.is_none() && r.max.is_none() {
None
} else {
Some(r)
}
})
}

fn parse_number(i: &[u8]) -> nom::IResult<&[u8], usize> {
Expand Down
5 changes: 1 addition & 4 deletions git-protocol/tests/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;

mod packet_line;
mod progress;
mod remote_progress;
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
mod parse {
use bstr::ByteSlice;
use git_protocol::RemoteProgress;
use git_protocol::parse_remote_progress;
use git_transport::RemoteProgress;

#[test]
fn a_message_we_dont_understand() {
assert_eq!(
RemoteProgress::from_bytes(b"something that might be progress: but is not."),
parse_remote_progress(b"something that might be progress: but is not."),
None
)
}

#[test]
fn enumerating_just_with_count() {
assert_eq!(
RemoteProgress::from_bytes(b"Enumerating objects: 10, done."),
parse_remote_progress(b"Enumerating objects: 10, done."),
Some(RemoteProgress {
action: b"Enumerating objects".as_bstr(),
percent: None,
Expand All @@ -26,7 +27,7 @@ mod parse {
#[test]
fn counting_objects_with_percentage() {
assert_eq!(
RemoteProgress::from_bytes(b"Counting objects: 50% (5/10), done."),
parse_remote_progress(b"Counting objects: 50% (5/10), done."),
Some(RemoteProgress {
action: b"Counting objects".as_bstr(),
percent: Some(50),
Expand Down
9 changes: 8 additions & 1 deletion git-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ serde1 = ["serde"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
git-features = { version = "^0.3.0", path = "../git-features" }
git-url = { version = "^0.1.0", path = "../git-url" }

serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
quick-error = "2.0.0"
hex = "0.4.2"
bstr = { version = "0.2.13", default-features = false, features = ["std"] }

[dev-dependencies]
git-odb = { version = "0.3.0", path = "../git-odb" }
16 changes: 16 additions & 0 deletions git-transport/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#![forbid(unsafe_code)]
use bstr::BStr;

pub mod packet_line;

#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct RemoteProgress<'a> {
#[cfg_attr(feature = "serde1", serde(borrow))]
pub action: &'a BStr,
pub percent: Option<u32>,
pub step: Option<usize>,
pub max: Option<usize>,
}

#[doc(inline)]
pub use packet_line::Borrowed as PacketLine;

#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where
Band::Data(ref mut d) => break d.read(&mut self.buf)?,
Band::Progress(d) => {
let text = Text::from(d).0;
match RemoteProgress::from_bytes(text) {
match None::<RemoteProgress> {
Some(RemoteProgress {
action,
percent: _,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod streaming {
use crate::packet_line::assert_err_display;
use bstr::ByteSlice;
use git_protocol::packet_line::Channel;
use git_protocol::{
use git_transport::packet_line::Channel;
use git_transport::{
packet_line::decode::{self, streaming, Stream},
PacketLine,
};
Expand Down Expand Up @@ -120,7 +120,7 @@ mod streaming {
}

mod incomplete {
use git_protocol::packet_line::decode::{self, streaming, Stream};
use git_transport::packet_line::decode::{self, streaming, Stream};

fn assert_incomplete(res: Result<Stream, decode::Error>, expected_missing: usize) -> crate::Result {
match res? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod data_to_write {
use crate::packet_line::assert_err_display;
use bstr::ByteSlice;
use git_protocol::packet_line::encode::{
use git_transport::packet_line::encode::{
data_to_write, delim_to_write, error_to_write, flush_to_write, response_end_to_write, text_to_write,
};
use std::io;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use git_protocol::{packet_line, PacketLine};
use git_transport::{packet_line, PacketLine};
use std::{io, path::PathBuf};

fn fixture_path(path: &str) -> PathBuf {
Expand All @@ -13,7 +13,7 @@ mod to_read {
use crate::packet_line::read::{exhaust, fixture_bytes};
use bstr::ByteSlice;
use git_odb::pack;
use git_protocol::packet_line;
use git_transport::packet_line;

#[test]
fn read_pack_with_progress_extraction() -> crate::Result {
Expand Down
3 changes: 3 additions & 0 deletions git-transport/tests/transport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;

mod packet_line;
2 changes: 1 addition & 1 deletion tests/fixtures/baseline-init/hooks/pre-push.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# <local ref> <local sha1> <remote ref> <remote sha1>
#
# This sample shows how to prevent push of commits where the log message starts
# with "WIP" (work in progress).
# with "WIP" (work in remote_progress).

remote="$1"
url="$2"
Expand Down

0 comments on commit c0dd831

Please sign in to comment.