History

[git-transport] put request writer into general spot…

…even though only a little bit can be shread soon once ExtendedBufRead is available in async. Clearly a mistake to try this one first :D

Sebastian Thiel committed 5 years ago

Commit af07ebf1 parent 5f98ac13 files · +41 −29Browse files

Unified · Split

3 files
  1. git-transport/src/client/blocking_io/mod.rs +17 −15
  2. git-transport/src/client/mod.rs +14 −8
  3. git-transport/src/client/request.rs +10 −6
git-transport/src/client/blocking_io/mod.rs+17−15
@@ -1,3 +1,14 @@
1use std::io;
2
3pub use bufread_ext::{ExtendedBufRead, HandleProgress};
4pub use trait_ext::TransportV2Ext;
5
6pub use crate::client::RequestWriter;
7use crate::{
8 client::{capabilities, Capabilities, Error, Identity, MessageKind, WriteMode},
9 Protocol, Service,
10};
11
1///12///
2pub mod connect;13pub mod connect;
3 14
@@ -9,21 +20,10 @@ pub mod git; · 5 unmodified lines
9#[cfg(feature = "http-client-curl")]20#[cfg(feature = "http-client-curl")]
10pub mod http;21pub mod http;
11 22
12pub mod request;
13pub use request::RequestWriter;
14
15mod bufread_ext;23mod bufread_ext;
16pub use bufread_ext::{ExtendedBufRead, HandleProgress};
17
18///24///
19pub mod ssh;25pub mod ssh;
20 26
21use crate::{
22 client::{capabilities, Capabilities, Error, Identity, MessageKind, WriteMode},
23 Protocol, Service,
24};
25use std::io;
26
27/// The response of the [`handshake()`][Transport::handshake()] method.27/// The response of the [`handshake()`][Transport::handshake()] method.
28pub struct SetServiceResponse<'a> {28pub struct SetServiceResponse<'a> {
29 /// The protocol the service can provide. May be different from the requested one29 /// The protocol the service can provide. May be different from the requested one
@@ -88,10 +88,12 @@ pub trait Transport { · 58 unmodified lines
88}88}
89 89
90mod trait_ext {90mod trait_ext {
91 use crate::client::{Error, ExtendedBufRead, MessageKind, Transport, WriteMode};
92 use bstr::BString;
93 use std::io::Write;91 use std::io::Write;
94 92
93 use bstr::BString;
94
95 use crate::client::{Error, ExtendedBufRead, MessageKind, Transport, WriteMode};
96
95 /// An extension trait to add more methods to everything implementing [`Transport`].97 /// An extension trait to add more methods to everything implementing [`Transport`].
96 pub trait TransportV2Ext {98 pub trait TransportV2Ext {
97 /// Invoke a protocol V2 style `command` with given `capabilities` and optional command specific `arguments`.99 /// Invoke a protocol V2 style `command` with given `capabilities` and optional command specific `arguments`.
@@ -130,14 +132,14 @@ mod trait_ext { · 32 unmodified lines
130 }132 }
131 }133 }
132}134}
133pub use trait_ext::TransportV2Ext;
134 135
135mod box_impl {136mod box_impl {
137 use std::ops::{Deref, DerefMut};
138
136 use crate::{139 use crate::{
137 client::{self, Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},140 client::{self, Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
138 Protocol, Service,141 Protocol, Service,
139 };142 };
140 use std::ops::{Deref, DerefMut};
141 143
142 // Would be nice if the box implementation could auto-forward to all implemented traits.144 // Would be nice if the box implementation could auto-forward to all implemented traits.
143 impl<T: client::Transport + ?Sized> client::Transport for Box<T> {145 impl<T: client::Transport + ?Sized> client::Transport for Box<T> {
git-transport/src/client/mod.rs+14−8
@@ -1,11 +1,10 @@
1#[cfg(feature = "blocking-client")]1#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]
2mod blocking_io;2pub use async_io::{SetServiceResponse, Transport};
3#[cfg(all(feature = "blocking-client", feature = "http-client-curl"))]3#[cfg(all(feature = "blocking-client", feature = "http-client-curl"))]
4pub use blocking_io::http;4pub use blocking_io::http;
5#[cfg(feature = "blocking-client")]5#[cfg(feature = "blocking-client")]
6pub use blocking_io::{6pub use blocking_io::{
7 connect, file, git, ssh, ExtendedBufRead, HandleProgress, RequestWriter, SetServiceResponse, Transport,7 connect, file, git, ssh, ExtendedBufRead, HandleProgress, SetServiceResponse, Transport, TransportV2Ext,
8 TransportV2Ext,
9};8};
10#[cfg(feature = "blocking-client")]9#[cfg(feature = "blocking-client")]
11#[doc(inline)]10#[doc(inline)]
@@ -13,13 +12,20 @@ pub use connect::connect; · 1 unmodified line
13 12
14#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]13#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]
15mod async_io;14mod async_io;
16#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]15#[cfg(feature = "blocking-client")]
17pub use async_io::{SetServiceResponse, Transport};16mod blocking_io;
17
18///
19pub mod capabilities;
20#[doc(inline)]
21pub use capabilities::Capabilities;
18 22
19mod non_io_types;23mod non_io_types;
20pub use non_io_types::{Error, Identity, MessageKind, WriteMode};24pub use non_io_types::{Error, Identity, MessageKind, WriteMode};
21 25
22///26///
23pub mod capabilities;27#[cfg(feature = "blocking-client")]
28pub mod request;
24#[doc(inline)]29#[doc(inline)]
25pub use capabilities::Capabilities;30#[cfg(feature = "blocking-client")]
31pub use request::RequestWriter;
git-transport/src/client/request.rsrenamed from git-transport/src/client/blocking_io/request.rs+10−6
@@ -20,6 +20,7 @@ impl<'a> io::Write for RequestWriter<'a> { · 19 unmodified lines
20 }20 }
21}21}
22 22
23/// methods with bonds to IO
23impl<'a> RequestWriter<'a> {24impl<'a> RequestWriter<'a> {
24 /// Create a new instance from a `writer` (commonly a socket), a `reader` into which to transform once the25 /// Create a new instance from a `writer` (commonly a socket), a `reader` into which to transform once the
25 /// writes are finished, along with configuration for the `write_mode` and information about which message to write26 /// writes are finished, along with configuration for the `write_mode` and information about which message to write
@@ -42,12 +43,6 @@ impl<'a> RequestWriter<'a> { · 16 unmodified lines
42 }43 }
43 }44 }
44 45
45 /// Discard the ability to write and turn this instance into the reader for obtaining the other side's response.
46 pub fn into_read(mut self) -> io::Result<Box<dyn ExtendedBufRead + 'a>> {
47 self.write_message(self.on_into_read)?;
48 Ok(self.reader)
49 }
50
51 /// Write the given message as packet line.46 /// Write the given message as packet line.
52 pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> {47 pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> {
53 match message {48 match message {
@@ -59,3 +54,12 @@ impl<'a> RequestWriter<'a> { · 5 unmodified lines
59 .map(|_| ())54 .map(|_| ())
60 }55 }
61}56}
57
58/// TODO: make this general
59impl<'a> RequestWriter<'a> {
60 /// Discard the ability to write and turn this instance into the reader for obtaining the other side's response.
61 pub fn into_read(mut self) -> io::Result<Box<dyn ExtendedBufRead + 'a>> {
62 self.write_message(self.on_into_read)?;
63 Ok(self.reader)
64 }
65}