pub use crate::client::non_io_types::connect::{Error, Options}; pub(crate) mod function { use std::convert::TryInto; use crate::client::{non_io_types::connect::Error, Transport}; /// A general purpose connector connecting to a repository identified by the given `url`. /// /// This includes connections to /// [local repositories][crate::client::file::connect()], /// [repositories over ssh][crate::client::ssh::connect()], /// [git daemons][crate::client::git::connect()], /// and if compiled in connections to [git repositories over https][crate::client::http::connect()]. /// /// Use `options` to further control specifics of the transport resulting from the connection. pub fn connect(url: Url, options: super::Options) -> Result, Error> where Url: TryInto, git_url::parse::Error: From, { let mut url = url.try_into().map_err(git_url::parse::Error::from)?; Ok(match url.scheme { git_url::Scheme::Ext(_) => return Err(Error::UnsupportedScheme(url.scheme)), git_url::Scheme::File => { if url.user().is_some() || url.host().is_some() || url.port.is_some() { return Err(Error::UnsupportedUrlTokens { url: url.to_bstring(), scheme: url.scheme, }); } Box::new( crate::client::blocking_io::file::connect(url.path, options.version) .map_err(|e| Box::new(e) as Box)?, ) } git_url::Scheme::Ssh => Box::new({ crate::client::blocking_io::ssh::connect(url, options.version, options.ssh) .map_err(|e| Box::new(e) as Box)? }), git_url::Scheme::Git => { if url.user().is_some() { return Err(Error::UnsupportedUrlTokens { url: url.to_bstring(), scheme: url.scheme, }); } Box::new({ let path = std::mem::take(&mut url.path); crate::client::git::connect( url.host().expect("host is present in url"), path, options.version, url.port, ) .map_err(|e| Box::new(e) as Box)? }) } #[cfg(not(any(feature = "http-client-curl", feature = "http-client-reqwest")))] git_url::Scheme::Https | git_url::Scheme::Http => return Err(Error::CompiledWithoutHttp(url.scheme)), #[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))] git_url::Scheme::Https | git_url::Scheme::Http => Box::new(crate::client::http::connect( &url.to_bstring().to_string(), options.version, )), }) } }