Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions gix-protocol/tests/protocol/fetch/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use bstr::ByteSlice;
use gix_transport::Protocol;

use crate::fetch;
#[cfg(feature = "async-client")]
use gix_transport::client::git::async_io::Connection;
#[cfg(feature = "blocking-client")]
use gix_transport::client::git::blocking_io::Connection;

fn arguments_v1(features: impl IntoIterator<Item = &'static str>) -> fetch::Arguments {
fetch::Arguments::new(Protocol::V1, features.into_iter().map(|n| (n, None)).collect(), false)
Expand Down Expand Up @@ -140,12 +144,9 @@ mod impls {
}
}

fn transport(
out: &mut Vec<u8>,
stateful: bool,
) -> Transport<gix_transport::client::git::Connection<&'static [u8], &mut Vec<u8>>> {
fn transport(out: &mut Vec<u8>, stateful: bool) -> Transport<Connection<&'static [u8], &mut Vec<u8>>> {
Transport {
inner: gix_transport::client::git::Connection::new(
inner: Connection::new(
&[],
out,
Protocol::V1, // does not matter
Expand Down
8 changes: 4 additions & 4 deletions gix-protocol/tests/protocol/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ pub fn transport<W: futures_io::AsyncWrite + Unpin>(
path: &str,
desired_version: gix_transport::Protocol,
mode: gix_transport::client::git::ConnectMode,
) -> gix_transport::client::git::Connection<Cursor, W> {
) -> gix_transport::client::git::async_io::Connection<Cursor, W> {
let response = fixture_bytes(path);
gix_transport::client::git::Connection::new(
gix_transport::client::git::async_io::Connection::new(
Cursor::new(response),
out,
desired_version,
Expand All @@ -321,9 +321,9 @@ pub fn transport<W: std::io::Write>(
path: &str,
version: gix_transport::Protocol,
mode: gix_transport::client::git::ConnectMode,
) -> gix_transport::client::git::Connection<Cursor, W> {
) -> gix_transport::client::git::blocking_io::Connection<Cursor, W> {
let response = fixture_bytes(path);
gix_transport::client::git::Connection::new(
gix_transport::client::git::blocking_io::Connection::new(
Cursor::new(response),
out,
version,
Expand Down
2 changes: 1 addition & 1 deletion gix-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async-client = [

#! ### Other
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
serde = ["dep:serde"]
serde = ["dep:serde", "bstr/serde"]

[[test]]
name = "blocking-transport"
Expand Down
4 changes: 2 additions & 2 deletions gix-transport/src/client/async_io/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub use crate::client::non_io_types::connect::{Error, Options};

#[cfg(feature = "async-std")]
pub(crate) mod function {
use crate::client::{async_io::Transport, git, non_io_types::connect::Error};
use crate::client::{async_io::Transport, git::async_io::Connection, non_io_types::connect::Error};

/// A general purpose connector connecting to a repository identified by the given `url`.
///
Expand All @@ -26,7 +26,7 @@ pub(crate) mod function {
}
let path = std::mem::take(&mut url.path);
Box::new(
git::Connection::new_tcp(
Connection::new_tcp(
url.host().expect("host is present in url"),
url.port,
path,
Expand Down
2 changes: 1 addition & 1 deletion gix-transport/src/client/blocking_io/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use crate::client::non_io_types::connect::{Error, Options};
pub(crate) mod function {
#[cfg(feature = "http-client-curl")]
use crate::client::blocking_io::http::curl::Curl;
#[cfg(feature = "http-client-reqwest")]
#[cfg(all(feature = "http-client-reqwest", not(feature = "http-client-curl")))]
use crate::client::blocking_io::http::reqwest::Remote as Reqwest;
use crate::client::{blocking_io::Transport, non_io_types::connect::Error};

Expand Down
7 changes: 4 additions & 3 deletions gix-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::{
http::options::{HttpVersion, SslVersionRangeInclusive},
ExtendedBufRead, HandleProgress, RequestWriter, SetServiceResponse,
},
capabilities, Capabilities, MessageKind,
capabilities::blocking_recv::Outcome,
MessageKind,
},
packetline::{blocking_io::StreamingPeekableIter, PacketLineRef},
Protocol, Service,
Expand Down Expand Up @@ -402,11 +403,11 @@ impl<H: Http> blocking_io::Transport for Transport<H> {
line_reader.as_read().read_to_end(&mut Vec::new())?;
}

let capabilities::recv::Outcome {
let Outcome {
capabilities,
refs,
protocol: actual_protocol,
} = Capabilities::from_lines_with_version_detection(line_reader)?;
} = Outcome::from_lines_with_version_detection(line_reader)?;
self.actual_version = actual_protocol;
self.service = Some(service);
Ok(SetServiceResponse {
Expand Down
14 changes: 7 additions & 7 deletions gix-transport/src/client/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Capabilities {

#[cfg(feature = "blocking-client")]
///
pub mod recv {
pub mod blocking_recv {
use std::io;

use bstr::ByteVec;
Expand All @@ -178,7 +178,7 @@ pub mod recv {
Protocol,
};

/// Success outcome of [`Capabilities::from_lines_with_version_detection`].
/// Success outcome of [`Outcome::from_lines_with_version_detection`].
pub struct Outcome<'a> {
/// The [`Capabilities`] the remote advertised.
pub capabilities: Capabilities,
Expand All @@ -191,7 +191,7 @@ pub mod recv {
pub protocol: Protocol,
}

impl Capabilities {
impl Outcome<'_> {
/// Read the capabilities and version advertisement from the given packetline reader.
///
/// If [`Protocol::V1`] was requested, or the remote decided to downgrade, the remote refs
Expand Down Expand Up @@ -253,10 +253,10 @@ pub mod recv {
}
}

#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
#[cfg(feature = "async-client")]
#[allow(missing_docs)]
///
pub mod recv {
pub mod async_recv {
use bstr::ByteVec;
use futures_io::AsyncRead;

Expand All @@ -266,7 +266,7 @@ pub mod recv {
Protocol,
};

/// Success outcome of [`Capabilities::from_lines_with_version_detection`].
/// Success outcome of [`Outcome::from_lines_with_version_detection`].
pub struct Outcome<'a> {
/// The [`Capabilities`] the remote advertised.
pub capabilities: Capabilities,
Expand All @@ -279,7 +279,7 @@ pub mod recv {
pub protocol: Protocol,
}

impl Capabilities {
impl Outcome<'_> {
/// Read the capabilities and version advertisement from the given packetline reader.
///
/// If [`Protocol::V1`] was requested, or the remote decided to downgrade, the remote refs
Expand Down
20 changes: 11 additions & 9 deletions gix-transport/src/client/git/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use crate::{
client::{
self,
async_io::{RequestWriter, SetServiceResponse},
capabilities,
capabilities::async_recv::Outcome,
git::{self, ConnectionState},
Capabilities,
},
packetline::{
async_io::{StreamingPeekableIter, Writer},
Expand Down Expand Up @@ -97,11 +96,11 @@ where
line_writer.flush().await?;
}

let capabilities::recv::Outcome {
let Outcome {
capabilities,
refs,
protocol: actual_protocol,
} = Capabilities::from_lines_with_version_detection(&mut self.line_provider).await?;
} = Outcome::from_lines_with_version_detection(&mut self.line_provider).await?;
Ok(SetServiceResponse {
actual_protocol,
capabilities,
Expand Down Expand Up @@ -164,9 +163,12 @@ mod async_net {

use async_std::net::TcpStream;

use crate::client::{git, Error};
use crate::client::{
git::{async_io::Connection, ConnectMode},
Error,
};

impl git::Connection<TcpStream, TcpStream> {
impl Connection<TcpStream, TcpStream> {
/// Create a new TCP connection using the `git` protocol of `desired_version`, and make a connection to `host`
/// at `port` for accessing the repository at `path` on the server side.
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
Expand All @@ -176,20 +178,20 @@ mod async_net {
path: bstr::BString,
desired_version: crate::Protocol,
trace: bool,
) -> Result<git::Connection<TcpStream, TcpStream>, Error> {
) -> Result<Self, Error> {
let read = async_std::io::timeout(
Duration::from_secs(5),
TcpStream::connect(&(host, port.unwrap_or(9418))),
)
.await?;
let write = read.clone();
Ok(git::Connection::new(
Ok(Self::new(
read,
write,
desired_version,
path,
None::<(String, _)>,
git::ConnectMode::Daemon,
ConnectMode::Daemon,
trace,
))
}
Expand Down
7 changes: 3 additions & 4 deletions gix-transport/src/client/git/blocking_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use crate::{
client::{
self,
blocking_io::{RequestWriter, SetServiceResponse},
capabilities,
capabilities::blocking_recv::Outcome,
git::{self, ConnectionState},
Capabilities,
},
packetline::{
blocking_io::{StreamingPeekableIter, Writer},
Expand Down Expand Up @@ -92,11 +91,11 @@ where
line_writer.flush()?;
}

let capabilities::recv::Outcome {
let Outcome {
capabilities,
refs,
protocol: actual_protocol,
} = Capabilities::from_lines_with_version_detection(&mut self.line_provider)?;
} = Outcome::from_lines_with_version_detection(&mut self.line_provider)?;
Ok(SetServiceResponse {
actual_protocol,
capabilities,
Expand Down
12 changes: 5 additions & 7 deletions gix-transport/src/client/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,10 @@ mod message {
}
}

#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
pub(crate) mod async_io;
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
pub use async_io::Connection;
///
#[cfg(feature = "async-client")]
pub mod async_io;

///
#[cfg(feature = "blocking-client")]
pub(crate) mod blocking_io;
#[cfg(feature = "blocking-client")]
pub use blocking_io::{connect, Connection};
pub mod blocking_io;
2 changes: 1 addition & 1 deletion gix-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
#[cfg(feature = "async-client")]
pub mod async_io;

mod traits;
Expand Down
6 changes: 5 additions & 1 deletion gix-transport/tests/client/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use bstr::ByteSlice;
use gix_packetline::async_io::{encode, StreamingPeekableIter};
#[cfg(all(feature = "blocking-client", not(feature = "async-client")))]
use gix_packetline::blocking_io::{encode, StreamingPeekableIter};
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
use gix_transport::client::capabilities::async_recv::Outcome;
#[cfg(all(feature = "blocking-client", not(feature = "async-client")))]
use gix_transport::client::capabilities::blocking_recv::Outcome;
use gix_transport::client::Capabilities;

#[test]
Expand Down Expand Up @@ -59,7 +63,7 @@ async fn from_lines_with_version_detection_v0() -> crate::Result {
let mut buf = Vec::<u8>::new();
encode::flush_to_write(&mut buf).await?;
let mut stream = StreamingPeekableIter::new(buf.as_slice(), &[gix_packetline::PacketLineRef::Flush], false);
let caps = Capabilities::from_lines_with_version_detection(&mut stream)
let caps = Outcome::from_lines_with_version_detection(&mut stream)
.await
.expect("we can parse V0 as very special case, useful for testing stateful connections in other crates")
.capabilities;
Expand Down
20 changes: 13 additions & 7 deletions gix-transport/tests/client/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ use bstr::ByteSlice;
use futures_lite::{AsyncBufReadExt, AsyncWriteExt, StreamExt};
use gix_packetline::read::ProgressAction;
#[cfg(feature = "async-client")]
use gix_transport::client::async_io::{Transport, TransportV2Ext};
use gix_transport::client::{
async_io::{Transport, TransportV2Ext},
git::async_io::Connection,
};
#[cfg(feature = "blocking-client")]
use gix_transport::client::blocking_io::{Transport, TransportV2Ext};
use gix_transport::client::{
blocking_io::{Transport, TransportV2Ext},
git::blocking_io::Connection,
};
use gix_transport::{
client,
client::{git, TransportWithoutIO},
Expand All @@ -25,7 +31,7 @@ use crate::fixture_bytes;
async fn handshake_v1_and_request() -> crate::Result {
let mut out = Vec::new();
let server_response = fixture_bytes("v1/clone.response");
let c = git::Connection::new(
let c = Connection::new(
server_response.as_slice(),
&mut out,
Protocol::V1,
Expand Down Expand Up @@ -157,7 +163,7 @@ async fn handshake_v1_and_request() -> crate::Result {
async fn push_v1_simulated() -> crate::Result {
let mut out = Vec::new();
let server_response = fixture_bytes("v1/push.response");
let mut c = git::Connection::new(
let mut c = Connection::new(
server_response.as_slice(),
&mut out,
Protocol::V1,
Expand Down Expand Up @@ -223,7 +229,7 @@ async fn push_v1_simulated() -> crate::Result {
async fn handshake_v1_process_mode() -> crate::Result {
let mut out = Vec::new();
let server_response = fixture_bytes("v1/clone.response");
let mut c = git::Connection::new(
let mut c = Connection::new(
server_response.as_slice(),
&mut out,
Protocol::V1,
Expand All @@ -246,7 +252,7 @@ async fn handshake_v1_process_mode() -> crate::Result {
async fn handshake_v2_downgrade_to_v1() -> crate::Result {
let mut out = Vec::new();
let input = fixture_bytes("v1/clone.response");
let mut c = git::Connection::new(
let mut c = Connection::new(
input.as_slice(),
&mut out,
Protocol::V2,
Expand Down Expand Up @@ -293,7 +299,7 @@ async fn handshake_v2_and_request() -> crate::Result {
async fn handshake_v2_and_request_inner() -> crate::Result {
let mut out = Vec::new();
let input = fixture_bytes("v2/clone.response");
let mut c = git::Connection::new(
let mut c = Connection::new(
input.as_slice(),
&mut out,
Protocol::V2,
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ check:
cargo check --workspace
cargo check --no-default-features --features small
cargo check -p gix-packetline --all-features 2>/dev/null
cargo check -p gix-transport --all-features 2>/dev/null
# assure compile error occurs
! cargo check --features lean-async 2>/dev/null
! cargo check -p gitoxide-core --all-features 2>/dev/null
! cargo check -p gix-transport --all-features 2>/dev/null
! cargo check -p gix-protocol --all-features 2>/dev/null
# warning happens if nothing found, no exit code :/
cargo --color=never tree -p gix --no-default-features -e normal -i imara-diff \
Expand Down
Loading