Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions gix-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ doctest = false
default = []

## If set, blocking implementations of the typical git transports become available in `crate::client::blocking_io`
##
## If used in conjunction with an async implementation, this one takes precedence.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also be something to double-check @djc, I hope it's correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the async and blocking implementations are fully parallel -- I don't remember seeing any code where either one is prioritized, and I don't intend to introduce any such code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fixed that in the other PR which is about to merge.

blocking-client = ["gix-packetline/blocking-io"]
## Implies `blocking-client`, and adds support for the http and https transports.
http-client = [
Expand All @@ -27,10 +29,12 @@ http-client = [
"gix-credentials",
]
## Implies `http-client`, and adds support for the http and https transports using the Rust bindings for `libcurl`.
##
## If used in conjunction with other blocking implementations like `http-client-reqwest`, this one takes precedence.
http-client-curl = ["curl", "http-client"]
## Implies `http-client-curl` and enables `rustls` for creating `https://` connections.
http-client-curl-rust-tls = ["http-client-curl", "curl/rustls"]
### Implies `http-client` and adds support for http and https transports using the blocking version of `reqwest`.
## Implies `http-client` and adds support for http and https transports using the blocking version of `reqwest`.
http-client-reqwest = ["reqwest", "http-client"]
## Stacks with `blocking-http-transport-reqwest` and enables `https://` via the `rustls` crate.
http-client-reqwest-rust-tls = ["http-client-reqwest", "reqwest/rustls-tls"]
Expand Down Expand Up @@ -59,7 +63,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::Handshake,
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 Handshake {
capabilities,
refs,
protocol: actual_protocol,
} = Capabilities::from_lines_with_version_detection(line_reader)?;
} = Handshake::from_lines_with_version_detection(line_reader)?;
self.actual_version = actual_protocol;
self.service = Some(service);
Ok(SetServiceResponse {
Expand Down
42 changes: 21 additions & 21 deletions gix-transport/src/client/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl Capabilities {
}
}

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

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

/// Success outcome of [`Capabilities::from_lines_with_version_detection`].
pub struct Outcome<'a> {
/// The information provided by the server upon first connection.
pub struct Handshake<'a> {
/// The [`Capabilities`] the remote advertised.
pub capabilities: Capabilities,
/// The remote refs as a [`io::BufRead`].
Expand All @@ -191,14 +191,14 @@ pub mod recv {
pub protocol: Protocol,
}

impl Capabilities {
impl Handshake<'_> {
/// 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
/// advertisement will also be included in the [`Outcome`].
/// advertisement will also be included in the [`Handshake`].
pub fn from_lines_with_version_detection<T: io::Read>(
rd: &mut StreamingPeekableIter<T>,
) -> Result<Outcome<'_>, client::Error> {
) -> Result<Handshake<'_>, client::Error> {
// NOTE that this is vitally important - it is turned on and stays on for all following requests so
// we automatically abort if the server sends an ERR line anywhere.
// We are sure this can't clash with binary data when sent due to the way the PACK
Expand All @@ -214,13 +214,13 @@ pub mod recv {
Protocol::V1 => {
let (capabilities, delimiter_position) = Capabilities::from_bytes(line.0)?;
rd.peek_buffer_replace_and_truncate(delimiter_position, b'\n');
Outcome {
Handshake {
capabilities,
refs: Some(Box::new(rd.as_read())),
protocol: Protocol::V1,
}
}
Protocol::V2 => Outcome {
Protocol::V2 => Handshake {
capabilities: {
let mut rd = rd.as_read();
let mut buf = Vec::new();
Expand All @@ -243,7 +243,7 @@ pub mod recv {
},
}
}
None => Outcome {
None => Handshake {
capabilities: Capabilities::default(),
refs: Some(Box::new(rd.as_read())),
protocol: Protocol::V0,
Expand All @@ -253,10 +253,10 @@ pub mod recv {
}
}

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

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

/// Success outcome of [`Capabilities::from_lines_with_version_detection`].
pub struct Outcome<'a> {
/// The information provided by the server upon first connection.
pub struct Handshake<'a> {
/// The [`Capabilities`] the remote advertised.
pub capabilities: Capabilities,
/// The remote refs as an [`AsyncBufRead`].
Expand All @@ -279,14 +279,14 @@ pub mod recv {
pub protocol: Protocol,
}

impl Capabilities {
impl Handshake<'_> {
/// 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
/// advertisement will also be included in the [`Outcome`].
/// advertisement will also be included in the [`Handshake`].
pub async fn from_lines_with_version_detection<T: AsyncRead + Unpin>(
rd: &mut StreamingPeekableIter<T>,
) -> Result<Outcome<'_>, client::Error> {
) -> Result<Handshake<'_>, client::Error> {
// NOTE that this is vitally important - it is turned on and stays on for all following requests so
// we automatically abort if the server sends an ERR line anywhere.
// We are sure this can't clash with binary data when sent due to the way the PACK
Expand All @@ -302,13 +302,13 @@ pub mod recv {
Protocol::V1 => {
let (capabilities, delimiter_position) = Capabilities::from_bytes(line.0)?;
rd.peek_buffer_replace_and_truncate(delimiter_position, b'\n');
Outcome {
Handshake {
capabilities,
refs: Some(Box::new(rd.as_read())),
protocol: Protocol::V1,
}
}
Protocol::V2 => Outcome {
Protocol::V2 => Handshake {
capabilities: {
let mut rd = rd.as_read();
let mut buf = Vec::new();
Expand All @@ -331,7 +331,7 @@ pub mod recv {
},
}
}
None => Outcome {
None => Handshake {
capabilities: Capabilities::default(),
refs: Some(Box::new(rd.as_read())),
protocol: Protocol::V0,
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::Handshake,
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 Handshake {
capabilities,
refs,
protocol: actual_protocol,
} = Capabilities::from_lines_with_version_detection(&mut self.line_provider).await?;
} = Handshake::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::Handshake,
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 Handshake {
capabilities,
refs,
protocol: actual_protocol,
} = Capabilities::from_lines_with_version_detection(&mut self.line_provider)?;
} = Handshake::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
Loading
Loading