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
99 P: Progress,
1010 {
1111 /// 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()]
1313 /// 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+ })
1728 }
1829 }
1930
2031 /// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.
2132 #[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>>,
2438 ref_map: RefMap<'remote>,
2539 }
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+}
git-repository/src/remote/connection/ref_map.rs+1−1
@@ -69,7 +69,7 @@ where · 68 unmodified lines
6969 }
7070
7171 #[git_protocol::maybe_async::maybe_async]
72− async fn ref_map_inner(
72+ pub(crate) async fn ref_map_inner(
7373 &mut self,
7474 Options {
7575 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
77 use crate::remote;
88
99 #[test]
10− #[ignore]
1110 fn fetch_pack() -> crate::Result {
1211 for version in [
1312 None,
@@ -25,9 +24,12 @@ mod blocking_io { · 11 unmodified lines
2524 }
2625
2726 let remote = repo.find_remote("origin")?;
28− remote
29− .connect(Fetch, progress::Discard)?
30− .prepare_fetch(Default::default())?;
27+ {
28+ remote
29+ .connect(Fetch, progress::Discard)?
30+ .prepare_fetch(Default::default())?;
31+ // early drops are fine and won't block.
32+ }
3133 }
3234 Ok(())
3335 }

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