…that fails to infer the type of the delegate making calls to it rather cumbersome. Maybe that will work one day.
Showing the changes to git-protocol/src/fetch/function.rs (1 of 3 files). Show all
Unified · Split
| @@ -9,7 +9,7 @@ use git_transport::{ · 8 unmodified lines | |||
| 9 | Service, | 9 | Service, |
| 10 | }; | 10 | }; |
| 11 | use maybe_async::maybe_async; | 11 | use maybe_async::maybe_async; |
| 12 | use std::io; | 12 | use std::{borrow::BorrowMut, io}; |
| 13 | 13 | ||
| 14 | /// Perform a 'fetch' operation with the server using `transport`, with `delegate` handling all server interactions. | 14 | /// Perform a 'fetch' operation with the server using `transport`, with `delegate` handling all server interactions. |
| 15 | /// **Note** that `delegate` has blocking operations and thus this entire call should be on an executor which can handle | 15 | /// **Note** that `delegate` has blocking operations and thus this entire call should be on an executor which can handle |
| @@ -21,23 +21,25 @@ use std::io; · 5 unmodified lines | |||
| 21 | /// | 21 | /// |
| 22 | /// _Note_ that depending on the `delegate`, the actual action performed can be `ls-refs`, `clone` or `fetch`. | 22 | /// _Note_ that depending on the `delegate`, the actual action performed can be `ls-refs`, `clone` or `fetch`. |
| 23 | #[maybe_async] | 23 | #[maybe_async] |
| 24 | pub async fn fetch<F, D, T>( | 24 | pub async fn fetch<F, D, T, B, P>( |
| 25 | mut transport: T, | 25 | mut transport: T, |
| 26 | mut delegate: D, | 26 | mut delegate: B, |
| 27 | mut authenticate: F, | 27 | mut authenticate: F, |
| 28 | mut progress: impl Progress, | 28 | mut progress: P, |
| 29 | ) -> Result<(), Error> | 29 | ) -> Result<(), Error> |
| 30 | where | 30 | where |
| 31 | F: FnMut(credentials::Action<'_>) -> credentials::Result, | 31 | F: FnMut(credentials::Action<'_>) -> credentials::Result, |
| 32 | D: Delegate, | 32 | D: Delegate, |
| 33 | B: BorrowMut<D>, | ||
| 33 | T: client::Transport, | 34 | T: client::Transport, |
| 35 | P: Progress, | ||
| 34 | { | 36 | { |
| 35 | let (protocol_version, parsed_refs, capabilities) = { | 37 | let (protocol_version, parsed_refs, capabilities) = { |
| 36 | progress.init(None, progress::steps()); | 38 | progress.init(None, progress::steps()); |
| 37 | progress.set_name("handshake"); | 39 | progress.set_name("handshake"); |
| 38 | progress.step(); | 40 | progress.step(); |
| 39 | 41 | ||
| 40 | let extra_parameters = delegate.handshake_extra_parameters(); | 42 | let extra_parameters = delegate.borrow_mut().handshake_extra_parameters(); |
| 41 | let extra_parameters: Vec<_> = extra_parameters | 43 | let extra_parameters: Vec<_> = extra_parameters |
| 42 | .iter() | 44 | .iter() |
| 43 | .map(|(k, v)| (k.as_str(), v.as_ref().map(|s| s.as_str()))) | 45 | .map(|(k, v)| (k.as_str(), v.as_ref().map(|s| s.as_str()))) |
| @@ -114,7 +116,9 @@ where · 70 unmodified lines | |||
| 114 | let ls_refs = Command::LsRefs; | 116 | let ls_refs = Command::LsRefs; |
| 115 | let mut ls_features = ls_refs.default_features(protocol_version, &capabilities); | 117 | let mut ls_features = ls_refs.default_features(protocol_version, &capabilities); |
| 116 | let mut ls_args = ls_refs.initial_arguments(&ls_features); | 118 | let mut ls_args = ls_refs.initial_arguments(&ls_features); |
| 117 | let next = delegate.prepare_ls_refs(&capabilities, &mut ls_args, &mut ls_features); | 119 | let next = delegate |
| 120 | .borrow_mut() | ||
| 121 | .prepare_ls_refs(&capabilities, &mut ls_args, &mut ls_features); | ||
| 118 | // User has requested to skip ls-refs, perhaps because they're using want-ref | 122 | // User has requested to skip ls-refs, perhaps because they're using want-ref |
| 119 | if next == LsRefsAction::Skip { | 123 | if next == LsRefsAction::Skip { |
| 120 | vec![] | 124 | vec![] |
| @@ -141,7 +145,9 @@ where · 20 unmodified lines | |||
| 141 | 145 | ||
| 142 | let fetch = Command::Fetch; | 146 | let fetch = Command::Fetch; |
| 143 | let mut fetch_features = fetch.default_features(protocol_version, &capabilities); | 147 | let mut fetch_features = fetch.default_features(protocol_version, &capabilities); |
| 144 | let next = delegate.prepare_fetch(protocol_version, &capabilities, &mut fetch_features, &parsed_refs); | 148 | let next = delegate |
| 149 | .borrow_mut() | ||
| 150 | .prepare_fetch(protocol_version, &capabilities, &mut fetch_features, &parsed_refs); | ||
| 145 | fetch.validate_argument_prefixes_or_panic(protocol_version, &capabilities, &[], &fetch_features); | 151 | fetch.validate_argument_prefixes_or_panic(protocol_version, &capabilities, &[], &fetch_features); |
| 146 | 152 | ||
| 147 | if next == Action::Cancel { | 153 | if next == Action::Cancel { |
| @@ -164,7 +170,9 @@ where · 16 unmodified lines | |||
| 164 | progress.step(); | 170 | progress.step(); |
| 165 | progress.set_name(format!("negotiate (round {})", round)); | 171 | progress.set_name(format!("negotiate (round {})", round)); |
| 166 | round += 1; | 172 | round += 1; |
| 167 | let action = delegate.negotiate(&parsed_refs, &mut arguments, previous_response.as_ref()); | 173 | let action = delegate |
| 174 | .borrow_mut() | ||
| 175 | .negotiate(&parsed_refs, &mut arguments, previous_response.as_ref()); | ||
| 168 | let mut reader = arguments.send(&mut transport, action == Action::Cancel).await?; | 176 | let mut reader = arguments.send(&mut transport, action == Action::Cancel).await?; |
| 169 | if sideband_all { | 177 | if sideband_all { |
| 170 | setup_remote_progress(&mut progress, &mut reader); | 178 | setup_remote_progress(&mut progress, &mut reader); |
| @@ -176,7 +184,10 @@ where · 5 unmodified lines | |||
| 176 | if !sideband_all { | 184 | if !sideband_all { |
| 177 | setup_remote_progress(&mut progress, &mut reader); | 185 | setup_remote_progress(&mut progress, &mut reader); |
| 178 | } | 186 | } |
| 179 | delegate.receive_pack(reader, progress, &parsed_refs, &response).await?; | 187 | delegate |
| 188 | .borrow_mut() | ||
| 189 | .receive_pack(reader, progress, &parsed_refs, &response) | ||
| 190 | .await?; | ||
| 180 | break 'negotiation; | 191 | break 'negotiation; |
| 181 | } else { | 192 | } else { |
| 182 | match action { | 193 | match action { |