Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed May 12, 2021
1 parent f16d057 commit 1412282
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 71 deletions.
6 changes: 3 additions & 3 deletions git-protocol/src/fetch/tests/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ impl<T: client::Transport> client::Transport for Transport<T> {
fn transport(
out: &mut Vec<u8>,
stateful: bool,
) -> Transport<git_transport::client::git::Connection<io::Cursor<Vec<u8>>, &mut Vec<u8>>> {
) -> Transport<git_transport::client::blocking::git::Connection<io::Cursor<Vec<u8>>, &mut Vec<u8>>> {
Transport {
inner: git_transport::client::git::Connection::new(
inner: git_transport::client::blocking::git::Connection::new(
io::Cursor::new(Vec::new()),
out,
Protocol::V1, // does not matter
b"does/not/matter".as_bstr().to_owned(),
None::<(&str, _)>,
git_transport::client::git::ConnectMode::Process, // avoid header to be sent
git_transport::client::blocking::git::ConnectMode::Process, // avoid header to be sent
),
stateful,
}
Expand Down
6 changes: 3 additions & 3 deletions git-protocol/tests/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ fn transport<'a>(
out: &'a mut Vec<u8>,
path: &str,
version: git_transport::Protocol,
) -> git_transport::client::git::Connection<std::io::Cursor<Vec<u8>>, &'a mut Vec<u8>> {
) -> git_transport::client::blocking::git::Connection<std::io::Cursor<Vec<u8>>, &'a mut Vec<u8>> {
let response = fixture_bytes(path);
git_transport::client::git::Connection::new(
git_transport::client::blocking::git::Connection::new(
std::io::Cursor::new(response),
out,
version,
b"does/not/matter".as_bstr().to_owned(),
None::<(&str, _)>,
git_transport::client::git::ConnectMode::Process,
git_transport::client::blocking::git::ConnectMode::Process,
)
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ pub fn connect(url: &[u8], desired_version: crate::Protocol) -> Result<Box<dyn T
return Err(Error::UnsupportedUrlTokens(urlb.into(), url.scheme));
}
Box::new(
crate::client::file::connect(url.path, desired_version)
crate::client::blocking::file::connect(url.path, desired_version)
.map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)?,
)
}
git_url::Scheme::Ssh => Box::new(
crate::client::ssh::connect(
crate::client::blocking::ssh::connect(
&url.host.as_ref().expect("host is present in url"),
url.path,
desired_version,
Expand All @@ -110,7 +110,7 @@ pub fn connect(url: &[u8], desired_version: crate::Protocol) -> Result<Box<dyn T
return Err(Error::UnsupportedUrlTokens(urlb.into(), url.scheme));
}
Box::new(
crate::client::git::connect(
crate::client::blocking::git::connect(
&url.host.as_ref().expect("host is present in url"),
url.path,
desired_version,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::process::{self, Command, Stdio};

use bstr::{BString, ByteSlice};

use crate::client::blocking::git;
use crate::{
client::{self, git, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
client::{self, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
Protocol, Service,
};
use bstr::{BString, ByteSlice};
use std::process::{self, Command, Stdio};

// from https://github.com/git/git/blob/20de7e7e4f4e9ae52e6cc7cfaa6469f186ddb0fa/environment.c#L115:L115
const ENV_VARS_TO_REMOVE: &[&str] = &[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use crate::{
client::{self, capabilities, SetServiceResponse},
Protocol, Service,
};
use bstr::BString;
use git_packetline::PacketLine;
use std::{
io,
io::Write,
net::{TcpStream, ToSocketAddrs},
};

use bstr::BString;
use quick_error::quick_error;

use git_packetline::PacketLine;

use crate::client::blocking::capabilities;
use crate::{
client::{self, SetServiceResponse},
Protocol, Service,
};

pub(crate) mod message {
use crate::{Protocol, Service};
use bstr::{BString, ByteVec};

use crate::{Protocol, Service};

pub fn connect(
service: Service,
version: Protocol,
Expand Down Expand Up @@ -180,7 +186,6 @@ where
}
}

use quick_error::quick_error;
quick_error! {
/// The error used in [`connect()`].
#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod message {
use crate::{client::git, Protocol, Service};
use crate::client::blocking::git;
use crate::{Protocol, Service};

#[test]
fn version_1_without_host_and_version() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::client::http;
use crate::client::blocking::http;
use git_features::io;
use std::{
sync::mpsc::{Receiver, SyncSender},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::client::http;
use crate::client::blocking::http;
use curl::easy::Easy2;
use git_features::io::pipe;
use std::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use crate::{
client::{self, capabilities, ExtendedBufRead, HandleProgress, MessageKind, RequestWriter},
Protocol, Service,
};
use git_packetline::PacketLine;
use std::{
borrow::Cow,
convert::Infallible,
io::{self, BufRead, Read},
};

use git_packetline::PacketLine;
pub use traits::{Error, GetResponse, Http, PostResponse};

use crate::client::blocking::capabilities;
use crate::{
client::{self, ExtendedBufRead, HandleProgress, MessageKind, RequestWriter},
Protocol, Service,
};

#[cfg(feature = "http-client-curl")]
pub(crate) mod curl;

///
mod traits;
pub use traits::{Error, GetResponse, Http, PostResponse};

/// The actual http client implementation.
#[cfg(feature = "http-client-curl")]
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions git-transport/src/client/blocking/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
///
pub mod capabilities;
///
pub mod connect;
///
pub mod file;
///
pub mod git;
///
#[cfg(feature = "http-client-curl")]
pub mod http;
///
pub mod request;
///
pub mod ssh;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{client, Protocol};
use bstr::BString;
use quick_error::quick_error;
use std::borrow::Cow;

use crate::client::blocking;
use crate::Protocol;

quick_error! {
/// The error used in [`connect()`].
#[derive(Debug)]
Expand Down Expand Up @@ -32,7 +34,7 @@ pub fn connect(
desired_version: crate::Protocol,
user: Option<&str>,
port: Option<u16>,
) -> Result<client::file::SpawnProcessOnDemand, Error> {
) -> Result<blocking::file::SpawnProcessOnDemand, Error> {
let ssh_cmd_line = std::env::var("GIT_SSH_COMMAND").unwrap_or_else(|_| "ssh".into());
let mut ssh_cmd_line = ssh_cmd_line.split(' ');
let ssh_cmd = ssh_cmd_line.next().expect("there is always a single item");
Expand Down Expand Up @@ -70,15 +72,15 @@ pub fn connect(
path: path.clone(),
};
Ok(match args_and_env {
Some((args, envs)) => client::file::SpawnProcessOnDemand::new_ssh(
Some((args, envs)) => blocking::file::SpawnProcessOnDemand::new_ssh(
url,
ssh_cmd.into(),
ssh_cmd_line.map(Cow::from).chain(args).chain(Some(host.into())),
envs,
path,
desired_version,
),
None => client::file::SpawnProcessOnDemand::new_ssh(
None => blocking::file::SpawnProcessOnDemand::new_ssh(
url,
ssh_cmd.into(),
ssh_cmd_line.chain(Some(host.as_str())),
Expand All @@ -91,9 +93,11 @@ pub fn connect(

#[cfg(test)]
mod tests {
use crate::{client::ssh::connect, Protocol};
use bstr::ByteSlice;

use crate::client::blocking::ssh::connect;
use crate::Protocol;

#[test]
fn connect_with_tilde_in_path() {
for (url, expected) in &[
Expand Down
29 changes: 9 additions & 20 deletions git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
use crate::{Protocol, Service};
use bstr::BString;
use std::{io, io::Write};

///
pub mod connect;
#[doc(inline)]
pub use connect::connect;
use bstr::BString;

///
pub mod file;
///
pub mod git;
///
#[cfg(feature = "http-client-curl")]
pub mod http;
///
pub mod ssh;
use crate::{Protocol, Service};

///
pub mod capabilities;
pub mod blocking;
#[doc(inline)]
pub use capabilities::Capabilities;

mod request;
pub use request::{ExtendedBufRead, HandleProgress, RequestWriter};
pub use blocking::capabilities::Capabilities;
#[doc(inline)]
pub use blocking::connect::connect;
pub use blocking::git;
pub use blocking::request::{ExtendedBufRead, HandleProgress, RequestWriter};
pub use blocking::{capabilities, http};

#[cfg(feature = "http-client-curl")]
type HttpError = http::Error;
Expand Down
16 changes: 10 additions & 6 deletions git-transport/tests/client_blocking/git.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use crate::fixture_bytes;
use bstr::ByteSlice;
use git_transport::{
client::{self, git, Transport, TransportV2Ext},
Protocol, Service,
};
use std::{
cell::RefCell,
io::{BufRead, Read, Write},
ops::Deref,
rc::Rc,
};

use bstr::ByteSlice;

use git_transport::client::blocking::git;
use git_transport::{
client::{self, Transport, TransportV2Ext},
Protocol, Service,
};

use crate::fixture_bytes;

#[test]
fn handshake_v1_and_request() -> crate::Result {
let mut out = Vec::new();
Expand Down
12 changes: 8 additions & 4 deletions git-transport/tests/client_blocking_http/http/mock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::fixture_bytes;
use bstr::ByteVec;
use git_transport::client::Transport;
use git_transport::{client::http, Protocol};
use std::{
io::{Read, Write},
net::SocketAddr,
time::Duration,
};

use bstr::ByteVec;

use git_transport::client::blocking::http;
use git_transport::client::Transport;
use git_transport::Protocol;

use crate::fixture_bytes;

enum Command {
ReadAndRespond(Vec<u8>),
}
Expand Down
18 changes: 11 additions & 7 deletions git-transport/tests/client_blocking_http/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
use crate::fixture_bytes;
use bstr::ByteSlice;
use git_transport::client::Identity;
use git_transport::{
client::{self, http, SetServiceResponse, Transport, TransportV2Ext},
Protocol, Service,
};
use std::{
cell::RefCell,
error::Error,
Expand All @@ -13,6 +6,17 @@ use std::{
rc::Rc,
};

use bstr::ByteSlice;

use git_transport::client::blocking::http;
use git_transport::client::Identity;
use git_transport::{
client::{self, SetServiceResponse, Transport, TransportV2Ext},
Protocol, Service,
};

use crate::fixture_bytes;

mod mock;

fn assert_error_status(
Expand Down

0 comments on commit 1412282

Please sign in to comment.