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
14 changes: 8 additions & 6 deletions gitoxide-core/src/net.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use std::str::FromStr;

#[cfg(feature = "async-client")]
use gix::protocol::transport::client::async_io as io_mode;
#[cfg(feature = "blocking-client")]
use gix::protocol::transport::client::blocking_io as io_mode;

#[derive(Default, Clone, Eq, PartialEq, Debug)]
pub enum Protocol {
V1,
Expand Down Expand Up @@ -39,17 +44,14 @@ mod impls {
#[gix::protocol::maybe_async::maybe_async]
pub async fn connect<Url, E>(
url: Url,
options: gix::protocol::transport::client::connect::Options,
) -> Result<
gix::protocol::SendFlushOnDrop<Box<dyn gix::protocol::transport::client::Transport + Send>>,
gix::protocol::transport::client::connect::Error,
>
options: io_mode::connect::Options,
) -> Result<gix::protocol::SendFlushOnDrop<Box<dyn io_mode::Transport + Send>>, io_mode::connect::Error>
where
Url: TryInto<gix::url::Url, Error = E>,
gix::url::parse::Error: From<E>,
{
Ok(gix::protocol::SendFlushOnDrop::new(
gix::protocol::transport::connect(url, options).await?,
io_mode::connect::connect(url, options).await?,
false,
))
}
6 changes: 5 additions & 1 deletion gitoxide-core/src/pack/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use std::{
sync::{atomic::AtomicBool, Arc},
};

#[cfg(feature = "async-client")]
use gix::protocol::transport::client::async_io::connect;
#[cfg(feature = "blocking-client")]
use gix::protocol::transport::client::blocking_io::connect;
use gix::{config::tree::Key, protocol::maybe_async, remote::fetch::Error, DynNestedProgress};
pub use gix::{
hash::ObjectId,
Expand Down Expand Up @@ -47,7 +51,7 @@ where
{
let mut transport = net::connect(
url,
gix::protocol::transport::client::connect::Options {
connect::Options {
version: protocol.unwrap_or_default().into(),
..Default::default()
},
Expand Down
9 changes: 6 additions & 3 deletions gix-protocol/src/fetch/arguments/async_io.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use futures_lite::io::AsyncWriteExt;
use gix_transport::{client, client::TransportV2Ext};
use gix_transport::client::{
self,
async_io::{ExtendedBufRead, Transport, TransportV2Ext},
};

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

impl Arguments {
/// Send fetch arguments to the server, and indicate this is the end of negotiations only if `add_done_argument` is present.
pub async fn send<'a, T: client::Transport + 'a>(
pub async fn send<'a, T: Transport + 'a>(
&mut self,
transport: &'a mut T,
add_done_argument: bool,
) -> Result<Box<dyn client::ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
) -> Result<Box<dyn ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
if self.haves.is_empty() {
assert!(add_done_argument, "If there are no haves, is_done must be true.");
}
Expand Down
9 changes: 6 additions & 3 deletions gix-protocol/src/fetch/arguments/blocking_io.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use std::io::Write;

use gix_transport::{client, client::TransportV2Ext};
use gix_transport::client::{
self,
blocking_io::{ExtendedBufRead, Transport, TransportV2Ext},
};

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

impl Arguments {
/// Send fetch arguments to the server, and indicate this is the end of negotiations only if `add_done_argument` is present.
pub fn send<'a, T: client::Transport + 'a>(
pub fn send<'a, T: Transport + 'a>(
&mut self,
transport: &'a mut T,
add_done_argument: bool,
) -> Result<Box<dyn client::ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
) -> Result<Box<dyn ExtendedBufRead<'a> + Unpin + 'a>, client::Error> {
if self.haves.is_empty() {
assert!(add_done_argument, "If there are no haves, is_done must be true.");
}
Expand Down
11 changes: 7 additions & 4 deletions gix-protocol/src/fetch/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use std::{

use gix_features::progress::DynNestedProgress;

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

fn setup_remote_progress<'a>(
progress: &mut dyn gix_features::progress::DynNestedProgress,
reader: &mut Box<dyn crate::transport::client::ExtendedBufRead<'a> + Unpin + 'a>,
reader: &mut Box<dyn ExtendedBufRead<'a> + Unpin + 'a>,
should_interrupt: &'a AtomicBool,
) {
use crate::transport::client::ExtendedBufRead;
reader.set_progress_handler(Some(Box::new({
let mut remote_progress = progress.add_child_with_id("remote".to_string(), ProgressId::RemoteProgress.into());
move |is_err: bool, data: &[u8]| {
Expand All @@ -265,5 +268,5 @@ fn setup_remote_progress<'a>(
ProgressAction::Continue
}
}
}) as crate::transport::client::HandleProgress<'a>));
}) as HandleProgress<'a>));
}
8 changes: 6 additions & 2 deletions gix-protocol/src/fetch/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use gix_features::progress::Progress;
use gix_transport::{client, Service};
use gix_transport::Service;
use maybe_async::maybe_async;

#[cfg(feature = "async-client")]
use crate::transport::client::async_io::Transport;
#[cfg(feature = "blocking-client")]
use crate::transport::client::blocking_io::Transport;
use crate::{
credentials,
handshake::{Error, Outcome},
Expand All @@ -21,7 +25,7 @@ pub async fn upload_pack<AuthFn, T>(
) -> Result<Outcome, Error>
where
AuthFn: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
T: client::Transport,
T: Transport,
{
crate::handshake(transport, Service::UploadPack, authenticate, extra_parameters, progress).await
}
5 changes: 4 additions & 1 deletion gix-protocol/src/fetch/refmap/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ use std::collections::HashSet;
use bstr::{BString, ByteVec};
use gix_features::progress::Progress;

#[cfg(feature = "async-client")]
use crate::transport::client::async_io::Transport;
#[cfg(feature = "blocking-client")]
use crate::transport::client::blocking_io::Transport;
use crate::{
fetch,
fetch::{
refmap::{Mapping, Source, SpecIndex},
RefMap,
},
transport::client::Transport,
};

/// The error returned by [`RefMap::new()`].
Expand Down
5 changes: 3 additions & 2 deletions gix-protocol/src/fetch/response/async_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::io;

use crate::transport::client::async_io::ExtendedBufRead;
use gix_transport::{client, Protocol};

use crate::fetch::{
Expand All @@ -10,7 +11,7 @@ use crate::fetch::{

async fn parse_v2_section<T>(
line: &mut String,
reader: &mut (impl client::ExtendedBufRead<'_> + Unpin),
reader: &mut (impl ExtendedBufRead<'_> + Unpin),
res: &mut Vec<T>,
parse: impl Fn(&str) -> Result<T, response::Error>,
) -> Result<bool, response::Error> {
Expand Down Expand Up @@ -44,7 +45,7 @@ impl Response {
/// that `git` has to use to predict how many acks are supposed to be read. We also genuinely hope that this covers it all….
pub async fn from_line_reader(
version: Protocol,
reader: &mut (impl client::ExtendedBufRead<'_> + Unpin),
reader: &mut (impl ExtendedBufRead<'_> + Unpin),
client_expects_pack: bool,
wants_to_negotiate: bool,
) -> Result<Response, response::Error> {
Expand Down
11 changes: 6 additions & 5 deletions gix-protocol/src/fetch/response/blocking_io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io;

use gix_transport::{client, Protocol};
use crate::transport::client::blocking_io::ExtendedBufRead;
use crate::transport::{client::MessageKind, Protocol};

use crate::fetch::{
response,
Expand All @@ -10,7 +11,7 @@ use crate::fetch::{

fn parse_v2_section<'a, T>(
line: &mut String,
reader: &mut impl client::ExtendedBufRead<'a>,
reader: &mut impl ExtendedBufRead<'a>,
res: &mut Vec<T>,
parse: impl Fn(&str) -> Result<T, response::Error>,
) -> Result<bool, response::Error> {
Expand All @@ -20,7 +21,7 @@ fn parse_v2_section<'a, T>(
line.clear();
}
// End of message, or end of section?
Ok(if reader.stopped_at() == Some(client::MessageKind::Delimiter) {
Ok(if reader.stopped_at() == Some(MessageKind::Delimiter) {
// try reading more sections
reader.reset(Protocol::V2);
false
Expand All @@ -44,7 +45,7 @@ impl Response {
/// that `git` has to use to predict how many acks are supposed to be read. We also genuinely hope that this covers it all….
pub fn from_line_reader<'a>(
version: Protocol,
reader: &mut impl client::ExtendedBufRead<'a>,
reader: &mut impl ExtendedBufRead<'a>,
client_expects_pack: bool,
wants_to_negotiate: bool,
) -> Result<Response, response::Error> {
Expand All @@ -71,7 +72,7 @@ impl Response {
// maybe we saw a shallow flush packet, let's reset and retry
debug_assert_eq!(
reader.stopped_at(),
Some(client::MessageKind::Flush),
Some(MessageKind::Flush),
"If this isn't a flush packet, we don't know what's going on"
);
reader.readline_str(&mut line)?;
Expand Down
8 changes: 6 additions & 2 deletions gix-protocol/src/handshake/function.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use gix_features::{progress, progress::Progress};
use gix_transport::{client, client::SetServiceResponse, Service};
use gix_transport::{client, Service};
use maybe_async::maybe_async;

use super::{Error, Outcome};
#[cfg(feature = "async-client")]
use crate::transport::client::async_io::{SetServiceResponse, Transport};
#[cfg(feature = "blocking-client")]
use crate::transport::client::blocking_io::{SetServiceResponse, Transport};
use crate::{credentials, handshake::refs};

/// Perform a handshake with the server on the other side of `transport`, with `authenticate` being used if authentication
Expand All @@ -20,7 +24,7 @@ pub async fn handshake<AuthFn, T>(
) -> Result<Outcome, Error>
where
AuthFn: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
T: client::Transport,
T: Transport,
{
let _span = gix_features::trace::detail!("gix_protocol::handshake()", service = ?service, extra_parameters = ?extra_parameters);
let (server_protocol_version, refs, capabilities) = {
Expand Down
5 changes: 3 additions & 2 deletions gix-protocol/src/handshake/refs/async_io.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::transport::client::async_io::ReadlineBufRead;
use crate::{
fetch::response::ShallowUpdate,
handshake::{refs, refs::parse::Error, Ref},
};

/// Parse refs from the given input line by line. Protocol V2 is required for this to succeed.
pub async fn from_v2_refs(in_refs: &mut dyn gix_transport::client::ReadlineBufRead) -> Result<Vec<Ref>, Error> {
pub async fn from_v2_refs(in_refs: &mut dyn ReadlineBufRead) -> Result<Vec<Ref>, Error> {
let mut out_refs = Vec::new();
while let Some(line) = in_refs
.readline()
Expand All @@ -27,7 +28,7 @@ pub async fn from_v2_refs(in_refs: &mut dyn gix_transport::client::ReadlineBufRe
/// Symbolic refs are shoe-horned into server capabilities whereas refs (without symbolic ones) are sent automatically as
/// part of the handshake. Both symbolic and peeled refs need to be combined to fit into the [`Ref`] type provided here.
pub async fn from_v1_refs_received_as_part_of_handshake_and_capabilities<'a>(
in_refs: &mut dyn gix_transport::client::ReadlineBufRead,
in_refs: &mut dyn ReadlineBufRead,
capabilities: impl Iterator<Item = gix_transport::client::capabilities::Capability<'a>>,
) -> Result<(Vec<Ref>, Vec<ShallowUpdate>), refs::parse::Error> {
let mut out_refs = refs::shared::from_capabilities(capabilities)?;
Expand Down
5 changes: 3 additions & 2 deletions gix-protocol/src/handshake/refs/blocking_io.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::transport::client::blocking_io::ReadlineBufRead;
use crate::{
fetch::response::ShallowUpdate,
handshake::{refs, refs::parse::Error, Ref},
};

/// Parse refs from the given input line by line. Protocol V2 is required for this to succeed.
pub fn from_v2_refs(in_refs: &mut dyn gix_transport::client::ReadlineBufRead) -> Result<Vec<Ref>, Error> {
pub fn from_v2_refs(in_refs: &mut dyn ReadlineBufRead) -> Result<Vec<Ref>, Error> {
let mut out_refs = Vec::new();
while let Some(line) = in_refs.readline().transpose()?.transpose()?.and_then(|l| l.as_bstr()) {
out_refs.push(refs::shared::parse_v2(line)?);
Expand All @@ -21,7 +22,7 @@ pub fn from_v2_refs(in_refs: &mut dyn gix_transport::client::ReadlineBufRead) ->
/// Symbolic refs are shoe-horned into server capabilities whereas refs (without symbolic ones) are sent automatically as
/// part of the handshake. Both symbolic and peeled refs need to be combined to fit into the [`Ref`] type provided here.
pub fn from_v1_refs_received_as_part_of_handshake_and_capabilities<'a>(
in_refs: &mut dyn gix_transport::client::ReadlineBufRead,
in_refs: &mut dyn ReadlineBufRead,
capabilities: impl Iterator<Item = gix_transport::client::capabilities::Capability<'a>>,
) -> Result<(Vec<Ref>, Vec<ShallowUpdate>), Error> {
let mut out_refs = refs::shared::from_capabilities(capabilities)?;
Expand Down
2 changes: 1 addition & 1 deletion gix-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Generally, there is the following order of operations.
//!
//! * create a [`Transport`](gix_transport::client::Transport)
//! * create a `Transport`, either blocking or async
//! * perform a [`handshake()`]
//! * execute a [`Command`]
//! - [list references](ls_refs())
Expand Down
6 changes: 5 additions & 1 deletion gix-protocol/src/ls_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ pub(crate) mod function {

use bstr::BString;
use gix_features::progress::Progress;
use gix_transport::client::{Capabilities, Transport, TransportV2Ext};
use gix_transport::client::Capabilities;
use maybe_async::maybe_async;

use super::{Action, Error};
#[cfg(feature = "async-client")]
use crate::transport::client::async_io::{Transport, TransportV2Ext};
#[cfg(feature = "blocking-client")]
use crate::transport::client::blocking_io::{Transport, TransportV2Ext};
use crate::{
handshake::{refs::from_v2_refs, Ref},
indicate_end_of_interaction, Command,
Expand Down
7 changes: 5 additions & 2 deletions gix-protocol/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ pub fn agent(name: impl Into<String>) -> String {
}
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
mod with_transport {
use gix_transport::client::Transport;
#[cfg(feature = "async-client")]
use gix_transport::client::async_io::Transport;
#[cfg(feature = "blocking-client")]
use gix_transport::client::blocking_io::Transport;

/// Send a message to indicate the remote side that there is nothing more to expect from us, indicating a graceful shutdown.
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
#[maybe_async::maybe_async]
pub async fn indicate_end_of_interaction(
mut transport: impl gix_transport::client::Transport,
mut transport: impl Transport,
trace: bool,
) -> Result<(), gix_transport::client::Error> {
// An empty request marks the (early) end of the interaction. Only relevant in stateful transports though.
Expand Down
15 changes: 8 additions & 7 deletions gix-protocol/tests/protocol/fetch/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ mod fetch_fn {
fetch::{Arguments, Response},
indicate_end_of_interaction, Command,
};
use gix_transport::client;
#[cfg(feature = "async-client")]
use gix_transport::client::async_io::{ExtendedBufRead, HandleProgress, Transport};
#[cfg(feature = "blocking-client")]
use gix_transport::client::blocking_io::{ExtendedBufRead, HandleProgress, Transport};
use maybe_async::maybe_async;

use super::{Action, Delegate};
Expand Down Expand Up @@ -67,7 +70,7 @@ mod fetch_fn {
where
F: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
D: Delegate,
T: client::Transport,
T: Transport,
P: NestedProgress + 'static,
P::SubProgress: 'static,
{
Expand Down Expand Up @@ -171,10 +174,8 @@ mod fetch_fn {
Ok(())
}

fn setup_remote_progress<P>(
progress: &mut P,
reader: &mut Box<dyn gix_transport::client::ExtendedBufRead<'_> + Unpin + '_>,
) where
fn setup_remote_progress<'a, P>(progress: &mut P, reader: &mut Box<dyn ExtendedBufRead<'a> + Unpin + 'a>)
where
P: NestedProgress,
P::SubProgress: 'static,
{
Expand All @@ -184,7 +185,7 @@ mod fetch_fn {
gix_protocol::RemoteProgress::translate_to_progress(is_err, data, &mut remote_progress);
gix_transport::packetline::read::ProgressAction::Continue
}
}) as gix_transport::client::HandleProgress<'_>));
}) as HandleProgress<'a>));
}
}
pub use fetch_fn::{legacy_fetch as fetch, FetchConnection};
Expand Down
Loading
Loading