| @@ -9,17 +9,42 @@ where · 8 unmodified lines |
| 9 | 9 | P: Progress, |
| 10 | 10 | { |
| 11 | 11 | /// Perform a handshake with the remote and obtain a ref-map with `options`, and from there one |
| 12 | | − /// Note that at this point, the `transport` should be configured using the [`transport_mut()`][Self::transport_mut()] |
| 12 | + /// Note that at this point, the `transport` should already be configured using the [`transport_mut()`][Self::transport_mut()] |
| 13 | 13 | /// method, as it will be consumed here. |
| 14 | | − #[allow(missing_docs)] |
| 15 | | − pub fn prepare_fetch(self, _options: ref_map::Options) -> Result<Prepare<'remote, 'repo, T, P>, ref_map::Error> { |
| 16 | | − todo!() |
| 14 | + /// |
| 15 | + /// From there additional properties of the fetch can be adjusted to override the defaults that are configured via git-config. |
| 16 | + /// |
| 17 | + /// # Blocking Only |
| 18 | + /// |
| 19 | + /// Note that this implementation is currently limited to blocking mode as it relies on Drop semantics to close the connection |
| 20 | + /// should the fetch not be performed. Furthermore, there the code doing the fetch is inherently blocking so there is no benefit. |
| 21 | + /// It's best to unblock it by placing it into its own thread or offload it should usage in an async context be required. |
| 22 | + pub fn prepare_fetch(mut self, options: ref_map::Options) -> Result<Prepare<'remote, 'repo, T, P>, ref_map::Error> { |
| 23 | + let ref_map = self.ref_map_inner(options)?; |
| 24 | + Ok(Prepare { |
| 25 | + con: Some(self), |
| 26 | + ref_map, |
| 27 | + }) |
| 17 | 28 | } |
| 18 | 29 | } |
| 19 | 30 | |
| 20 | 31 | /// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation. |
| 21 | 32 | #[allow(dead_code)] |
| 22 | | −pub struct Prepare<'remote, 'repo, T, P> { |
| 23 | | − con: Connection<'remote, 'repo, T, P>, |
| 33 | +pub struct Prepare<'remote, 'repo, T, P> |
| 34 | +where |
| 35 | + T: Transport, |
| 36 | +{ |
| 37 | + con: Option<Connection<'remote, 'repo, T, P>>, |
| 24 | 38 | ref_map: RefMap<'remote>, |
| 25 | 39 | } |
| 40 | + |
| 41 | +impl<'remote, 'repo, T, P> Drop for Prepare<'remote, 'repo, T, P> |
| 42 | +where |
| 43 | + T: Transport, |
| 44 | +{ |
| 45 | + fn drop(&mut self) { |
| 46 | + if let Some(mut con) = self.con.take() { |
| 47 | + git_protocol::fetch::indicate_end_of_interaction(&mut con.transport).ok(); |
| 48 | + } |
| 49 | + } |
| 50 | +} |