Unified · Split
| @@ -58,13 +58,15 @@ async fn ref_in_want() -> crate::Result { · 57 unmodified lines | ||
| 58 | 58 | want_refs: vec!["refs/heads/main".into()], |
| 59 | 59 | ..CloneRefInWantDelegate::default() |
| 60 | 60 | }; |
| 61 | − let (delegate, out) = git_protocol::fetch( | |
| 62 | − transport( | |
| 63 | − out, | |
| 64 | − "v2/clone-ref-in-want.response", | |
| 65 | − Protocol::V2, | |
| 66 | − git_transport::client::git::ConnectMode::Daemon, | |
| 67 | − ), | |
| 61 | + let mut transport = transport( | |
| 62 | + out, | |
| 63 | + "v2/clone-ref-in-want.response", | |
| 64 | + Protocol::V2, | |
| 65 | + git_transport::client::git::ConnectMode::Daemon, | |
| 66 | + ); | |
| 67 | + | |
| 68 | + let (delegate, _) = git_protocol::fetch( | |
| 69 | + &mut transport, | |
| 68 | 70 | delegate, |
| 69 | 71 | git_protocol::credentials::helper, |
| 70 | 72 | progress::Discard, |
| @@ -81,7 +83,7 @@ async fn ref_in_want() -> crate::Result { · 10 unmodified lines | ||
| 81 | 83 | ); |
| 82 | 84 | assert_eq!(delegate.pack_bytes, 641, "Should get packfile"); |
| 83 | 85 | assert_eq!( |
| 84 | − out.into_inner().1.as_bstr(), | |
| 86 | + transport.into_inner().1.as_bstr(), | |
| 85 | 87 | format!( |
| 86 | 88 | "002fgit-upload-pack does/not/matter\0\0version=2\00012command=fetch |
| 87 | 89 | 001aagent={} |
| @@ -61,6 +61,22 @@ impl<T: Transport + ?Sized> Transport for Box<T> { · 60 unmodified lines | ||
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | +// Would be nice if the box implementation could auto-forward to all implemented traits. | |
| 65 | +#[async_trait(?Send)] | |
| 66 | +impl<T: Transport + ?Sized> Transport for &mut T { | |
| 67 | + async fn handshake<'a>( | |
| 68 | + &mut self, | |
| 69 | + service: Service, | |
| 70 | + extra_parameters: &'a [(&'a str, Option<&'a str>)], | |
| 71 | + ) -> Result<SetServiceResponse<'_>, Error> { | |
| 72 | + self.deref_mut().handshake(service, extra_parameters).await | |
| 73 | + } | |
| 74 | + | |
| 75 | + async fn close(&mut self) -> Result<(), Error> { | |
| 76 | + self.deref_mut().close().await | |
| 77 | + } | |
| 78 | +} | |
| 79 | + | |
| 64 | 80 | /// An extension trait to add more methods to everything implementing [`Transport`]. |
| 65 | 81 | #[async_trait(?Send)] |
| 66 | 82 | pub trait TransportV2Ext { |
| @@ -57,6 +57,20 @@ impl<T: Transport + ?Sized> Transport for Box<T> { · 56 unmodified lines | ||
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | +impl<T: Transport + ?Sized> Transport for &mut T { | |
| 61 | + fn handshake<'a>( | |
| 62 | + &mut self, | |
| 63 | + service: Service, | |
| 64 | + extra_parameters: &'a [(&'a str, Option<&'a str>)], | |
| 65 | + ) -> Result<SetServiceResponse<'_>, Error> { | |
| 66 | + self.deref_mut().handshake(service, extra_parameters) | |
| 67 | + } | |
| 68 | + | |
| 69 | + fn close(&mut self) -> Result<(), Error> { | |
| 70 | + self.deref_mut().close() | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 60 | 74 | /// An extension trait to add more methods to everything implementing [`Transport`]. |
| 61 | 75 | pub trait TransportV2Ext { |
| 62 | 76 | /// Invoke a protocol V2 style `command` with given `capabilities` and optional command specific `arguments`. |
| @@ -80,3 +80,26 @@ impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> { · 79 unmodified lines | ||
| 80 | 80 | self.deref().is_stateful() |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | + | |
| 84 | +impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for &mut T { | |
| 85 | + fn set_identity(&mut self, identity: Identity) -> Result<(), Error> { | |
| 86 | + self.deref_mut().set_identity(identity) | |
| 87 | + } | |
| 88 | + | |
| 89 | + #[cfg(any(feature = "blocking-client", feature = "async-client"))] | |
| 90 | + fn request(&mut self, write_mode: WriteMode, on_into_read: MessageKind) -> Result<RequestWriter<'_>, Error> { | |
| 91 | + self.deref_mut().request(write_mode, on_into_read) | |
| 92 | + } | |
| 93 | + | |
| 94 | + fn to_url(&self) -> String { | |
| 95 | + self.deref().to_url() | |
| 96 | + } | |
| 97 | + | |
| 98 | + fn supported_protocol_versions(&self) -> &[Protocol] { | |
| 99 | + self.deref().supported_protocol_versions() | |
| 100 | + } | |
| 101 | + | |
| 102 | + fn is_stateful(&self) -> bool { | |
| 103 | + self.deref().is_stateful() | |
| 104 | + } | |
| 105 | +} | |