Skip to content

Commit c20bdd9

Browse files
committed
refactor!: turn handshake::Outcome into Handshake type.
This includes a utility to get a refmap out of a handshake, plastering over differences between V1 and V2 of the protocol.
1 parent 48fdf5d commit c20bdd9

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

gix-protocol/src/fetch/handshake.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use maybe_async::maybe_async;
66
use crate::transport::client::async_io::Transport;
77
#[cfg(feature = "blocking-client")]
88
use crate::transport::client::blocking_io::Transport;
9-
use crate::{
10-
credentials,
11-
handshake::{Error, Outcome},
12-
};
9+
use crate::{credentials, handshake::Error, Handshake};
1310

1411
/// Perform a handshake with the server on the other side of `transport`, with `authenticate` being used if authentication
1512
/// turns out to be required. `extra_parameters` are the parameters `(name, optional value)` to add to the handshake,
@@ -22,7 +19,7 @@ pub async fn upload_pack<AuthFn, T>(
2219
authenticate: AuthFn,
2320
extra_parameters: Vec<(String, Option<String>)>,
2421
progress: &mut impl Progress,
25-
) -> Result<Outcome, Error>
22+
) -> Result<Handshake, Error>
2623
where
2724
AuthFn: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
2825
T: Transport,

gix-protocol/src/fetch/response/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl Response {
185185
}
186186

187187
/// Append the given `updates` which may have been obtained from a
188-
/// (handshake::Outcome)[crate::handshake::Outcome::v1_shallow_updates].
188+
/// (handshake::Outcome)[crate::handshake::Handshake::v1_shallow_updates].
189189
///
190190
/// In V2, these are received as part of the pack, but V1 sends them early, so we
191191
/// offer to re-integrate them here.

gix-protocol/src/fetch/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Context<'a, T> {
2424
/// The outcome of the handshake performed with the remote.
2525
///
2626
/// Note that it's mutable as depending on the protocol, it may contain refs that have been sent unconditionally.
27-
pub handshake: &'a mut crate::handshake::Outcome,
27+
pub handshake: &'a mut crate::Handshake,
2828
/// The transport to use when making an `ls-refs` or `fetch` call.
2929
///
3030
/// This is always done if the underlying protocol is V2, which is implied by the absence of refs in the `handshake` outcome.

gix-protocol/src/handshake/function.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use gix_features::{progress, progress::Progress};
22
use gix_transport::{client, Service};
33
use maybe_async::maybe_async;
44

5-
use super::{Error, Outcome};
5+
use super::Error;
66
#[cfg(feature = "async-client")]
77
use crate::transport::client::async_io::{SetServiceResponse, Transport};
88
#[cfg(feature = "blocking-client")]
99
use crate::transport::client::blocking_io::{SetServiceResponse, Transport};
10+
use crate::Handshake;
1011
use crate::{credentials, handshake::refs};
1112

1213
/// Perform a handshake with the server on the other side of `transport`, with `authenticate` being used if authentication
@@ -21,7 +22,7 @@ pub async fn handshake<AuthFn, T>(
2122
mut authenticate: AuthFn,
2223
extra_parameters: Vec<(String, Option<String>)>,
2324
progress: &mut impl Progress,
24-
) -> Result<Outcome, Error>
25+
) -> Result<Handshake, Error>
2526
where
2627
AuthFn: FnMut(credentials::helper::Action) -> credentials::protocol::Result,
2728
T: Transport,
@@ -103,7 +104,7 @@ where
103104
.map(|(refs, shallow)| (Some(refs), Some(shallow)))
104105
.unwrap_or_default();
105106

106-
Ok(Outcome {
107+
Ok(Handshake {
107108
server_protocol_version,
108109
refs,
109110
v1_shallow_updates,

gix-protocol/src/handshake/mod.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,24 @@ pub enum Ref {
5050
},
5151
}
5252

53-
/// The result of the [`handshake()`][super::handshake()] function.
54-
#[derive(Default, Debug, Clone)]
55-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5653
#[cfg(feature = "handshake")]
57-
pub struct Outcome {
58-
/// The protocol version the server responded with. It might have downgraded the desired version.
59-
pub server_protocol_version: gix_transport::Protocol,
60-
/// The references reported as part of the `Protocol::V1` handshake, or `None` otherwise as V2 requires a separate request.
61-
pub refs: Option<Vec<Ref>>,
62-
/// Shallow updates as part of the `Protocol::V1`, to shallow a particular object.
63-
/// Note that unshallowing isn't supported here.
64-
pub v1_shallow_updates: Option<Vec<crate::fetch::response::ShallowUpdate>>,
65-
/// The server capabilities.
66-
pub capabilities: gix_transport::client::Capabilities,
54+
pub(crate) mod hero {
55+
use crate::handshake::Ref;
56+
57+
/// The result of the [`handshake()`](crate::handshake()) function.
58+
#[derive(Default, Debug, Clone)]
59+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
60+
pub struct Handshake {
61+
/// The protocol version the server responded with. It might have downgraded the desired version.
62+
pub server_protocol_version: gix_transport::Protocol,
63+
/// The references reported as part of the `Protocol::V1` handshake, or `None` otherwise as V2 requires a separate request.
64+
pub refs: Option<Vec<Ref>>,
65+
/// Shallow updates as part of the `Protocol::V1`, to shallow a particular object.
66+
/// Note that unshallowing isn't supported here.
67+
pub v1_shallow_updates: Option<Vec<crate::fetch::response::ShallowUpdate>>,
68+
/// The server capabilities.
69+
pub capabilities: gix_transport::client::Capabilities,
70+
}
6771
}
6872

6973
#[cfg(feature = "handshake")]

gix-protocol/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub mod handshake;
6161
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
6262
#[cfg(feature = "handshake")]
6363
pub use handshake::function::handshake;
64+
#[cfg(feature = "handshake")]
65+
pub use handshake::hero::Handshake;
6466

6567
///
6668
pub mod ls_refs;

gix-protocol/tests/protocol/fetch/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ mod fetch_fn {
7474
P: NestedProgress + 'static,
7575
P::SubProgress: 'static,
7676
{
77-
let gix_protocol::handshake::Outcome {
77+
let gix_protocol::Handshake {
7878
server_protocol_version: protocol_version,
7979
refs,
8080
v1_shallow_updates: _ignored_shallow_updates_as_it_is_deprecated,

0 commit comments

Comments
 (0)