Skip to content

Commit 6e89afa

Browse files
authored
Merge pull request #2236 from djc/additive-transport
transport: make I/O mode features additive
2 parents ff073d3 + c2050d0 commit 6e89afa

File tree

45 files changed

+222
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+222
-150
lines changed

gitoxide-core/src/net.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use std::str::FromStr;
22

3+
#[cfg(feature = "async-client")]
4+
use gix::protocol::transport::client::async_io as io_mode;
5+
#[cfg(feature = "blocking-client")]
6+
use gix::protocol::transport::client::blocking_io as io_mode;
7+
38
#[derive(Default, Clone, Eq, PartialEq, Debug)]
49
pub enum Protocol {
510
V1,
@@ -39,17 +44,14 @@ mod impls {
3944
#[gix::protocol::maybe_async::maybe_async]
4045
pub async fn connect<Url, E>(
4146
url: Url,
42-
options: gix::protocol::transport::client::connect::Options,
43-
) -> Result<
44-
gix::protocol::SendFlushOnDrop<Box<dyn gix::protocol::transport::client::Transport + Send>>,
45-
gix::protocol::transport::client::connect::Error,
46-
>
47+
options: io_mode::connect::Options,
48+
) -> Result<gix::protocol::SendFlushOnDrop<Box<dyn io_mode::Transport + Send>>, io_mode::connect::Error>
4749
where
4850
Url: TryInto<gix::url::Url, Error = E>,
4951
gix::url::parse::Error: From<E>,
5052
{
5153
Ok(gix::protocol::SendFlushOnDrop::new(
52-
gix::protocol::transport::connect(url, options).await?,
54+
io_mode::connect::connect(url, options).await?,
5355
false,
5456
))
5557
}

gitoxide-core/src/pack/receive.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use std::{
44
sync::{atomic::AtomicBool, Arc},
55
};
66

7+
#[cfg(feature = "async-client")]
8+
use gix::protocol::transport::client::async_io::connect;
9+
#[cfg(feature = "blocking-client")]
10+
use gix::protocol::transport::client::blocking_io::connect;
711
use gix::{config::tree::Key, protocol::maybe_async, remote::fetch::Error, DynNestedProgress};
812
pub use gix::{
913
hash::ObjectId,
@@ -47,7 +51,7 @@ where
4751
{
4852
let mut transport = net::connect(
4953
url,
50-
gix::protocol::transport::client::connect::Options {
54+
connect::Options {
5155
version: protocol.unwrap_or_default().into(),
5256
..Default::default()
5357
},

gix-protocol/src/fetch/arguments/async_io.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
use futures_lite::io::AsyncWriteExt;
2-
use gix_transport::{client, client::TransportV2Ext};
2+
use gix_transport::client::{
3+
self,
4+
async_io::{ExtendedBufRead, Transport, TransportV2Ext},
5+
};
36

47
use crate::{fetch::Arguments, Command};
58

69
impl Arguments {
710
/// Send fetch arguments to the server, and indicate this is the end of negotiations only if `add_done_argument` is present.
8-
pub async fn send<'a, T: client::Transport + 'a>(
11+
pub async fn send<'a, T: Transport + 'a>(
912
&mut self,
1013
transport: &'a mut T,
1114
add_done_argument: bool,
12-
) -> Result<Box<dyn client::ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
15+
) -> Result<Box<dyn ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
1316
if self.haves.is_empty() {
1417
assert!(add_done_argument, "If there are no haves, is_done must be true.");
1518
}

gix-protocol/src/fetch/arguments/blocking_io.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
use std::io::Write;
22

3-
use gix_transport::{client, client::TransportV2Ext};
3+
use gix_transport::client::{
4+
self,
5+
blocking_io::{ExtendedBufRead, Transport, TransportV2Ext},
6+
};
47

58
use crate::{fetch::Arguments, Command};
69

710
impl Arguments {
811
/// Send fetch arguments to the server, and indicate this is the end of negotiations only if `add_done_argument` is present.
9-
pub fn send<'a, T: client::Transport + 'a>(
12+
pub fn send<'a, T: Transport + 'a>(
1013
&mut self,
1114
transport: &'a mut T,
1215
add_done_argument: bool,
13-
) -> Result<Box<dyn client::ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
16+
) -> Result<Box<dyn ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
1417
if self.haves.is_empty() {
1518
assert!(add_done_argument, "If there are no haves, is_done must be true.");
1619
}

gix-protocol/src/fetch/function.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use std::{
55

66
use gix_features::progress::DynNestedProgress;
77

8+
#[cfg(feature = "async-client")]
9+
use crate::transport::client::async_io::{ExtendedBufRead, HandleProgress, Transport};
10+
#[cfg(feature = "blocking-client")]
11+
use crate::transport::client::blocking_io::{ExtendedBufRead, HandleProgress, Transport};
812
use crate::{
913
fetch::{
1014
negotiate, Arguments, Context, Error, Negotiate, NegotiateOutcome, Options, Outcome, ProgressId, Shallow, Tags,
@@ -56,7 +60,7 @@ pub async fn fetch<P, T, E>(
5660
where
5761
P: gix_features::progress::NestedProgress,
5862
P::SubProgress: 'static,
59-
T: gix_transport::client::Transport,
63+
T: Transport,
6064
E: Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
6165
{
6266
let _span = gix_trace::coarse!("gix_protocol::fetch()");
@@ -251,10 +255,9 @@ fn add_shallow_args(
251255

252256
fn setup_remote_progress<'a>(
253257
progress: &mut dyn gix_features::progress::DynNestedProgress,
254-
reader: &mut Box<dyn crate::transport::client::ExtendedBufRead<'a> + Unpin + 'a>,
258+
reader: &mut Box<dyn ExtendedBufRead<'a> + Unpin + 'a>,
255259
should_interrupt: &'a AtomicBool,
256260
) {
257-
use crate::transport::client::ExtendedBufRead;
258261
reader.set_progress_handler(Some(Box::new({
259262
let mut remote_progress = progress.add_child_with_id("remote".to_string(), ProgressId::RemoteProgress.into());
260263
move |is_err: bool, data: &[u8]| {
@@ -265,5 +268,5 @@ fn setup_remote_progress<'a>(
265268
ProgressAction::Continue
266269
}
267270
}
268-
}) as crate::transport::client::HandleProgress<'a>));
271+
}) as HandleProgress<'a>));
269272
}

gix-protocol/src/fetch/handshake.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use gix_features::progress::Progress;
2-
use gix_transport::{client, Service};
2+
use gix_transport::Service;
33
use maybe_async::maybe_async;
44

5+
#[cfg(feature = "async-client")]
6+
use crate::transport::client::async_io::Transport;
7+
#[cfg(feature = "blocking-client")]
8+
use crate::transport::client::blocking_io::Transport;
59
use crate::{
610
credentials,
711
handshake::{Error, Outcome},
@@ -21,7 +25,7 @@ pub async fn upload_pack<AuthFn, T>(
2125
) -> Result<Outcome, Error>
2226
where
2327
AuthFn: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
24-
T: client::Transport,
28+
T: Transport,
2529
{
2630
crate::handshake(transport, Service::UploadPack, authenticate, extra_parameters, progress).await
2731
}

gix-protocol/src/fetch/refmap/init.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ use std::collections::HashSet;
33
use bstr::{BString, ByteVec};
44
use gix_features::progress::Progress;
55

6+
#[cfg(feature = "async-client")]
7+
use crate::transport::client::async_io::Transport;
8+
#[cfg(feature = "blocking-client")]
9+
use crate::transport::client::blocking_io::Transport;
610
use crate::{
711
fetch,
812
fetch::{
913
refmap::{Mapping, Source, SpecIndex},
1014
RefMap,
1115
},
12-
transport::client::Transport,
1316
};
1417

1518
/// The error returned by [`RefMap::new()`].

gix-protocol/src/fetch/response/async_io.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::io;
22

3+
use crate::transport::client::async_io::ExtendedBufRead;
34
use gix_transport::{client, Protocol};
45

56
use crate::fetch::{
@@ -10,7 +11,7 @@ use crate::fetch::{
1011

1112
async fn parse_v2_section<T>(
1213
line: &mut String,
13-
reader: &mut (impl client::ExtendedBufRead<'_> + Unpin),
14+
reader: &mut (impl ExtendedBufRead<'_> + Unpin),
1415
res: &mut Vec<T>,
1516
parse: impl Fn(&str) -> Result<T, response::Error>,
1617
) -> Result<bool, response::Error> {
@@ -44,7 +45,7 @@ impl Response {
4445
/// that `git` has to use to predict how many acks are supposed to be read. We also genuinely hope that this covers it all….
4546
pub async fn from_line_reader(
4647
version: Protocol,
47-
reader: &mut (impl client::ExtendedBufRead<'_> + Unpin),
48+
reader: &mut (impl ExtendedBufRead<'_> + Unpin),
4849
client_expects_pack: bool,
4950
wants_to_negotiate: bool,
5051
) -> Result<Response, response::Error> {

gix-protocol/src/fetch/response/blocking_io.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::io;
22

3-
use gix_transport::{client, Protocol};
3+
use crate::transport::client::blocking_io::ExtendedBufRead;
4+
use crate::transport::{client::MessageKind, Protocol};
45

56
use crate::fetch::{
67
response,
@@ -10,7 +11,7 @@ use crate::fetch::{
1011

1112
fn parse_v2_section<'a, T>(
1213
line: &mut String,
13-
reader: &mut impl client::ExtendedBufRead<'a>,
14+
reader: &mut impl ExtendedBufRead<'a>,
1415
res: &mut Vec<T>,
1516
parse: impl Fn(&str) -> Result<T, response::Error>,
1617
) -> Result<bool, response::Error> {
@@ -20,7 +21,7 @@ fn parse_v2_section<'a, T>(
2021
line.clear();
2122
}
2223
// End of message, or end of section?
23-
Ok(if reader.stopped_at() == Some(client::MessageKind::Delimiter) {
24+
Ok(if reader.stopped_at() == Some(MessageKind::Delimiter) {
2425
// try reading more sections
2526
reader.reset(Protocol::V2);
2627
false
@@ -44,7 +45,7 @@ impl Response {
4445
/// that `git` has to use to predict how many acks are supposed to be read. We also genuinely hope that this covers it all….
4546
pub fn from_line_reader<'a>(
4647
version: Protocol,
47-
reader: &mut impl client::ExtendedBufRead<'a>,
48+
reader: &mut impl ExtendedBufRead<'a>,
4849
client_expects_pack: bool,
4950
wants_to_negotiate: bool,
5051
) -> Result<Response, response::Error> {
@@ -71,7 +72,7 @@ impl Response {
7172
// maybe we saw a shallow flush packet, let's reset and retry
7273
debug_assert_eq!(
7374
reader.stopped_at(),
74-
Some(client::MessageKind::Flush),
75+
Some(MessageKind::Flush),
7576
"If this isn't a flush packet, we don't know what's going on"
7677
);
7778
reader.readline_str(&mut line)?;

gix-protocol/src/handshake/function.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use gix_features::{progress, progress::Progress};
2-
use gix_transport::{client, client::SetServiceResponse, Service};
2+
use gix_transport::{client, Service};
33
use maybe_async::maybe_async;
44

55
use super::{Error, Outcome};
6+
#[cfg(feature = "async-client")]
7+
use crate::transport::client::async_io::{SetServiceResponse, Transport};
8+
#[cfg(feature = "blocking-client")]
9+
use crate::transport::client::blocking_io::{SetServiceResponse, Transport};
610
use crate::{credentials, handshake::refs};
711

812
/// Perform a handshake with the server on the other side of `transport`, with `authenticate` being used if authentication
@@ -20,7 +24,7 @@ pub async fn handshake<AuthFn, T>(
2024
) -> Result<Outcome, Error>
2125
where
2226
AuthFn: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
23-
T: client::Transport,
27+
T: Transport,
2428
{
2529
let _span = gix_features::trace::detail!("gix_protocol::handshake()", service = ?service, extra_parameters = ?extra_parameters);
2630
let (server_protocol_version, refs, capabilities) = {

0 commit comments

Comments
 (0)