History

allow stopping fetches after preparing it (#450)

Sebastian Thiel committed 4 years ago

Commit 249c54e1 parent 4b1e3b33 files · +38 −11Browse files

Unified · Split

3 files
  1. git-repository/src/remote/connection/fetch.rs +31 −6
  2. git-repository/src/remote/connection/ref_map.rs +1 −1
  3. git-repository/tests/remote/fetch.rs +6 −4
git-repository/src/remote/connection/fetch.rs+31−6
@@ -9,17 +9,42 @@ where · 8 unmodified lines
9 P: Progress,9 P: Progress,
10{10{
11 /// Perform a handshake with the remote and obtain a ref-map with `options`, and from there one11 /// 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 /// method, as it will be consumed here.13 /// method, as it will be consumed here.
14 #[allow(missing_docs)]14 ///
15 pub fn prepare_fetch(self, _options: ref_map::Options) -> Result<Prepare<'remote, 'repo, T, P>, ref_map::Error> {15 /// From there additional properties of the fetch can be adjusted to override the defaults that are configured via git-config.
16 todo!()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/// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.31/// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.
21#[allow(dead_code)]32#[allow(dead_code)]
22pub struct Prepare<'remote, 'repo, T, P> {33pub struct Prepare<'remote, 'repo, T, P>
23 con: Connection<'remote, 'repo, T, P>,34where
35 T: Transport,
36{
37 con: Option<Connection<'remote, 'repo, T, P>>,
24 ref_map: RefMap<'remote>,38 ref_map: RefMap<'remote>,
25}39}
40
41impl<'remote, 'repo, T, P> Drop for Prepare<'remote, 'repo, T, P>
42where
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}
git-repository/src/remote/connection/ref_map.rs+1−1
@@ -69,7 +69,7 @@ where · 68 unmodified lines
69 }69 }
70 70
71 #[git_protocol::maybe_async::maybe_async]71 #[git_protocol::maybe_async::maybe_async]
72 async fn ref_map_inner(72 pub(crate) async fn ref_map_inner(
73 &mut self,73 &mut self,
74 Options {74 Options {
75 prefix_from_spec_as_filter_on_remote,75 prefix_from_spec_as_filter_on_remote,
git-repository/tests/remote/fetch.rs+6−4
@@ -7,7 +7,6 @@ mod blocking_io { · 6 unmodified lines
7 use crate::remote;7 use crate::remote;
8 8
9 #[test]9 #[test]
10 #[ignore]
11 fn fetch_pack() -> crate::Result {10 fn fetch_pack() -> crate::Result {
12 for version in [11 for version in [
13 None,12 None,
@@ -25,9 +24,12 @@ mod blocking_io { · 11 unmodified lines
25 }24 }
26 25
27 let remote = repo.find_remote("origin")?;26 let remote = repo.find_remote("origin")?;
28 remote27 {
29 .connect(Fetch, progress::Discard)?28 remote
30 .prepare_fetch(Default::default())?;29 .connect(Fetch, progress::Discard)?
30 .prepare_fetch(Default::default())?;
31 // early drops are fine and won't block.
32 }
31 }33 }
32 Ok(())34 Ok(())
33 }35 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t