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 @@
1+use std::io;
2+
3+pub use bufread_ext::{ExtendedBufRead, HandleProgress};
4+pub use trait_ext::TransportV2Ext;
5+
6+pub use crate::client::RequestWriter;
7+use crate::{
8+ client::{capabilities, Capabilities, Error, Identity, MessageKind, WriteMode},
9+ Protocol, Service,
10+};
11+
112 ///
213 pub mod connect;
314
@@ -9,21 +20,10 @@ pub mod git; · 5 unmodified lines
920 #[cfg(feature = "http-client-curl")]
1021 pub mod http;
1122
12−pub mod request;
13−pub use request::RequestWriter;
14−
1523 mod bufread_ext;
16−pub use bufread_ext::{ExtendedBufRead, HandleProgress};
17−
1824 ///
1925 pub mod ssh;
2026
21−use crate::{
22− client::{capabilities, Capabilities, Error, Identity, MessageKind, WriteMode},
23− Protocol, Service,
24−};
25−use std::io;
26−
2727 /// The response of the [`handshake()`][Transport::handshake()] method.
2828 pub struct SetServiceResponse<'a> {
2929 /// The protocol the service can provide. May be different from the requested one
@@ -88,10 +88,12 @@ pub trait Transport { · 58 unmodified lines
8888 }
8989
9090 mod trait_ext {
91− use crate::client::{Error, ExtendedBufRead, MessageKind, Transport, WriteMode};
92− use bstr::BString;
9391 use std::io::Write;
9492
93+ use bstr::BString;
94+
95+ use crate::client::{Error, ExtendedBufRead, MessageKind, Transport, WriteMode};
96+
9597 /// An extension trait to add more methods to everything implementing [`Transport`].
9698 pub trait TransportV2Ext {
9799 /// Invoke a protocol V2 style `command` with given `capabilities` and optional command specific `arguments`.
@@ -130,14 +132,14 @@ mod trait_ext { · 32 unmodified lines
130132 }
131133 }
132134 }
133−pub use trait_ext::TransportV2Ext;
134135
135136 mod box_impl {
137+ use std::ops::{Deref, DerefMut};
138+
136139 use crate::{
137140 client::{self, Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
138141 Protocol, Service,
139142 };
140− use std::ops::{Deref, DerefMut};
141143
142144 // Would be nice if the box implementation could auto-forward to all implemented traits.
143145 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")]
2−mod blocking_io;
1+#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]
2+pub use async_io::{SetServiceResponse, Transport};
33 #[cfg(all(feature = "blocking-client", feature = "http-client-curl"))]
44 pub use blocking_io::http;
55 #[cfg(feature = "blocking-client")]
66 pub use blocking_io::{
7− connect, file, git, ssh, ExtendedBufRead, HandleProgress, RequestWriter, SetServiceResponse, Transport,
8− TransportV2Ext,
7+ connect, file, git, ssh, ExtendedBufRead, HandleProgress, SetServiceResponse, Transport, TransportV2Ext,
98 };
109 #[cfg(feature = "blocking-client")]
1110 #[doc(inline)]
@@ -13,13 +12,20 @@ pub use connect::connect; · 1 unmodified line
1312
1413 #[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]
1514 mod async_io;
16−#[cfg(all(not(feature = "blocking-client"), feature = "async-client"))]
17−pub use async_io::{SetServiceResponse, Transport};
15+#[cfg(feature = "blocking-client")]
16+mod blocking_io;
17+
18+///
19+pub mod capabilities;
20+#[doc(inline)]
21+pub use capabilities::Capabilities;
1822
1923 mod non_io_types;
2024 pub use non_io_types::{Error, Identity, MessageKind, WriteMode};
2125
2226 ///
23−pub mod capabilities;
27+#[cfg(feature = "blocking-client")]
28+pub mod request;
2429 #[doc(inline)]
25−pub use capabilities::Capabilities;
30+#[cfg(feature = "blocking-client")]
31+pub 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
2020 }
2121 }
2222
23+/// methods with bonds to IO
2324 impl<'a> RequestWriter<'a> {
2425 /// Create a new instance from a `writer` (commonly a socket), a `reader` into which to transform once the
2526 /// 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
4243 }
4344 }
4445
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−
5146 /// Write the given message as packet line.
5247 pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> {
5348 match message {
@@ -59,3 +54,12 @@ impl<'a> RequestWriter<'a> { · 5 unmodified lines
5954 .map(|_| ())
6055 }
6156 }
57+
58+/// TODO: make this general
59+impl<'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+}