Skip to content

Commit

Permalink
[transport] async transports support extra params
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 27, 2021
1 parent 6026dcc commit a0d6756
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
27 changes: 20 additions & 7 deletions git-transport/src/client/async_io/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ pub struct SetServiceResponse<'a> {
/// **Note that** whenever a `Read` trait or `Write` trait is produced, it must be exhausted.
#[async_trait(?Send)]
pub trait Transport: TransportWithoutIO {
/// Initiate connection to the given service.
/// Initiate connection to the given service and send the given `extra_parameters` along with it.
///
/// `extra_parameters` are interpreted as `key=value` pairs if the second parameter is `Some` or as `key`
/// if it is None.
///
/// Returns the service capabilities according according to the actual [Protocol] it supports,
/// and possibly a list of refs to be obtained.
/// This means that asking for an unsupported protocol will result in a protocol downgrade to the given one.
/// using the `read_line(…)` function of the given [BufReader][SetServiceResponse::refs].
/// It must be exhausted, that is, read to the end before the next method can be invoked.
async fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, Error>;
/// This means that asking for an unsupported protocol might result in a protocol downgrade to the given one
/// if [TransportWithoutIO::supported_protocol_versions()] includes it.
/// Exhaust the returned [BufReader][SetServiceResponse::refs] for a list of references in case of protocol V1
/// before making another request.
async fn handshake<'a>(
&mut self,
service: Service,
extra_parameters: &[(&str, Option<&str>)],
) -> Result<SetServiceResponse<'_>, Error>;

/// Closes the connection to indicate no further requests will be made.
async fn close(&mut self) -> Result<(), Error>;
Expand All @@ -39,8 +48,12 @@ pub trait Transport: TransportWithoutIO {
// Would be nice if the box implementation could auto-forward to all implemented traits.
#[async_trait(?Send)]
impl<T: Transport + ?Sized> Transport for Box<T> {
async fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, Error> {
self.deref_mut().handshake(service).await
async fn handshake<'a>(
&mut self,
service: Service,
extra_parameters: &[(&str, Option<&str>)],
) -> Result<SetServiceResponse<'_>, Error> {
self.deref_mut().handshake(service, extra_parameters).await
}

async fn close(&mut self) -> Result<(), Error> {
Expand Down
7 changes: 6 additions & 1 deletion git-transport/src/client/git/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ where
R: AsyncRead + Unpin,
W: AsyncWrite + Unpin,
{
async fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, client::Error> {
async fn handshake<'a>(
&mut self,
service: Service,
extra_parameters: &[(&str, Option<&str>)],
) -> Result<SetServiceResponse<'_>, client::Error> {
if self.mode == git::ConnectMode::Daemon {
let mut line_writer = git_packetline::Writer::new(&mut self.writer).binary_mode();
line_writer
Expand All @@ -66,6 +70,7 @@ where
self.desired_version,
&self.path,
self.virtual_host.as_ref(),
extra_parameters,
))
.await?;
line_writer.flush().await?;
Expand Down

0 comments on commit a0d6756

Please sign in to comment.