Skip to content

Commit 9d936fb

Browse files
committed
refactor
1 parent ab3cce4 commit 9d936fb

File tree

7 files changed

+32
-28
lines changed

7 files changed

+32
-28
lines changed

gitoxide-core/src/pack/receive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ where
8888
extra_refspecs: vec![],
8989
};
9090

91-
let fetch_refmap = handshake.fetch_or_extract_refmap(user_agent.clone(), true, context)?;
91+
let fetch_refmap = handshake.prepare_lsrefs_or_extract_refmap(user_agent.clone(), true, context)?;
9292

9393
#[cfg(feature = "async-client")]
9494
let refmap = fetch_refmap

gix-protocol/src/fetch/negotiate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct Round {
111111
/// * `graph`
112112
/// - The commit-graph for use by the `negotiator` - we populate it with tips to initialize the graph traversal.
113113
/// * `ref_map`
114-
/// - The references known on the remote, as previously obtained with [`crate::Handshake::fetch_or_extract_refmap()`].
114+
/// - The references known on the remote, as previously obtained with [`crate::Handshake::prepare_lsrefs_or_extract_refmap()`].
115115
/// * `shallow`
116116
/// - How to deal with shallow repositories. It does affect how negotiations are performed.
117117
/// * `mapping_is_ignored`

gix-protocol/src/fetch/refmap/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
handshake::Ref,
1010
};
1111

12-
/// The error returned by [`crate::Handshake::fetch_or_extract_refmap()`].
12+
/// The error returned by [`crate::Handshake::prepare_lsrefs_or_extract_refmap()`].
1313
#[derive(Debug, thiserror::Error)]
1414
#[allow(missing_docs)]
1515
pub enum Error {

gix-protocol/src/fetch/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Options<'a> {
1818
pub reject_shallow_remote: bool,
1919
}
2020

21-
/// For use in [`crate::Handshake::fetch_or_extract_refmap()`] and [`fetch`](crate::fetch()).
21+
/// For use in [`crate::Handshake::prepare_lsrefs_or_extract_refmap()`] and [`fetch`](crate::fetch()).
2222
#[cfg(feature = "handshake")]
2323
pub struct Context<'a, T> {
2424
/// The outcome of the handshake performed with the remote.
@@ -29,7 +29,7 @@ pub struct Context<'a, T> {
2929
///
3030
/// This is always done if the underlying protocol is V2, which is implied by the absence of refs in the `handshake` outcome.
3131
pub transport: &'a mut T,
32-
/// How to self-identify during the `ls-refs` call in [`crate::Handshake::fetch_or_extract_refmap()`] or the `fetch` call in [`fetch()`](crate::fetch()).
32+
/// How to self-identify during the `ls-refs` call in [`crate::Handshake::prepare_lsrefs_or_extract_refmap()`] or the `fetch` call in [`fetch()`](crate::fetch()).
3333
///
3434
/// This could be read from the `gitoxide.userAgent` configuration variable.
3535
pub user_agent: (&'static str, Option<std::borrow::Cow<'static, str>>),

gix-protocol/src/handshake/mod.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,74 +80,75 @@ pub(crate) mod hero {
8080
use std::borrow::Cow;
8181

8282
/// Intermediate state while potentially fetching a refmap after the handshake.
83-
pub enum FetchRefMap<'a> {
84-
/// We already got a refmap to use from the handshake.
85-
Map(RefMap),
86-
/// We need to invoke another command to get the refmap.
87-
Command(crate::LsRefsCommand<'a>, crate::fetch::refmap::init::Context),
83+
pub enum ObtainRefMap<'a> {
84+
/// We already got a refmap to use from the V1 handshake, which always sends them.
85+
Existing(RefMap),
86+
/// We need to invoke another `ls-refs` command to retrieve the refmap as part of the V2 protocol.
87+
LsRefsCommand(crate::LsRefsCommand<'a>, crate::fetch::refmap::init::Context),
8888
}
8989

90-
impl FetchRefMap<'_> {
91-
/// Fetch the refmap, either by returning the existing one or invoking the command.
90+
impl ObtainRefMap<'_> {
91+
/// Fetch the refmap, either by returning the existing one or invoking the `ls-refs` command.
9292
#[cfg(feature = "async-client")]
9393
#[allow(clippy::result_large_err)]
9494
pub async fn fetch_async(
9595
self,
9696
mut progress: impl Progress,
9797
transport: &mut impl async_io::Transport,
9898
trace_packetlines: bool,
99-
) -> Result<crate::fetch::RefMap, crate::fetch::refmap::init::Error> {
99+
) -> Result<RefMap, crate::fetch::refmap::init::Error> {
100100
let (cmd, cx) = match self {
101-
FetchRefMap::Map(map) => return Ok(map),
102-
FetchRefMap::Command(cmd, cx) => (cmd, cx),
101+
ObtainRefMap::Existing(map) => return Ok(map),
102+
ObtainRefMap::LsRefsCommand(cmd, cx) => (cmd, cx),
103103
};
104104

105+
let _span = gix_trace::coarse!("gix_protocol::handshake::ObtainRefMap::fetch_async()");
105106
let capabilities = cmd.capabilities;
106107
let remote_refs = cmd.invoke_async(transport, &mut progress, trace_packetlines).await?;
107108
RefMap::from_refs(remote_refs, capabilities, cx)
108109
}
109110

110-
/// Fetch the refmap, either by returning the existing one or invoking the command.
111+
/// Fetch the refmap, either by returning the existing one or invoking the `ls-refs` command.
111112
#[cfg(feature = "blocking-client")]
112113
#[allow(clippy::result_large_err)]
113114
pub fn fetch_blocking(
114115
self,
115116
mut progress: impl Progress,
116117
transport: &mut impl blocking_io::Transport,
117118
trace_packetlines: bool,
118-
) -> Result<crate::fetch::RefMap, crate::fetch::refmap::init::Error> {
119+
) -> Result<RefMap, crate::fetch::refmap::init::Error> {
119120
let (cmd, cx) = match self {
120-
FetchRefMap::Map(map) => return Ok(map),
121-
FetchRefMap::Command(cmd, cx) => (cmd, cx),
121+
ObtainRefMap::Existing(map) => return Ok(map),
122+
ObtainRefMap::LsRefsCommand(cmd, cx) => (cmd, cx),
122123
};
123124

125+
let _span = gix_trace::coarse!("gix_protocol::handshake::ObtainRefMap::fetch_blocking()");
124126
let capabilities = cmd.capabilities;
125127
let remote_refs = cmd.invoke_blocking(transport, &mut progress, trace_packetlines)?;
126128
RefMap::from_refs(remote_refs, capabilities, cx)
127129
}
128130
}
129131

130132
impl Handshake {
131-
/// Prepare fetching a [refmap](crate::fetch::RefMap) if not present in the handshake.
133+
/// Prepare fetching a [refmap](RefMap) if not present in the handshake.
132134
#[allow(clippy::result_large_err)]
133-
pub fn fetch_or_extract_refmap(
135+
pub fn prepare_lsrefs_or_extract_refmap(
134136
&mut self,
135137
user_agent: (&'static str, Option<Cow<'static, str>>),
136138
prefix_from_spec_as_filter_on_remote: bool,
137139
refmap_context: crate::fetch::refmap::init::Context,
138-
) -> Result<FetchRefMap<'_>, crate::fetch::refmap::init::Error> {
140+
) -> Result<ObtainRefMap<'_>, crate::fetch::refmap::init::Error> {
139141
if let Some(refs) = self.refs.take() {
140-
return Ok(FetchRefMap::Map(crate::fetch::RefMap::from_refs(
142+
return Ok(ObtainRefMap::Existing(RefMap::from_refs(
141143
refs,
142144
&self.capabilities,
143145
refmap_context,
144146
)?));
145147
}
146148

147-
let _span = gix_trace::coarse!("gix_protocol::handshake::fetch_or_extract_refmap()");
148149
let all_refspecs = refmap_context.aggregate_refspecs();
149150
let prefix_refspecs = prefix_from_spec_as_filter_on_remote.then_some(&all_refspecs[..]);
150-
Ok(FetchRefMap::Command(
151+
Ok(ObtainRefMap::LsRefsCommand(
151152
crate::LsRefsCommand::new(prefix_refspecs, &self.capabilities, user_agent),
152153
refmap_context,
153154
))

gix-protocol/src/ls_refs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub(crate) mod function {
4848
};
4949

5050
/// A command to list references from a remote Git repository.
51+
///
52+
/// It acts as a utility to separate the invocation into the shared blocking portion,
53+
/// and the one that performs IO either blocking or `async`.
5154
pub struct LsRefsCommand<'a> {
5255
pub(crate) capabilities: &'a Capabilities,
5356
features: Vec<(&'static str, Option<Cow<'static, str>>)>,
@@ -62,8 +65,6 @@ pub(crate) mod function {
6265
capabilities: &'a Capabilities,
6366
agent: (&'static str, Option<Cow<'static, str>>),
6467
) -> Self {
65-
let _span =
66-
gix_features::trace::detail!("gix_protocol::LsRefsCommand::new()", capabilities = ?capabilities);
6768
let ls_refs = Command::LsRefs;
6869
let mut features = ls_refs.default_features(gix_transport::Protocol::V2, capabilities);
6970
features.push(agent);
@@ -109,6 +110,7 @@ pub(crate) mod function {
109110
progress: &mut impl Progress,
110111
trace: bool,
111112
) -> Result<Vec<Ref>, Error> {
113+
let _span = gix_features::trace::detail!("gix_protocol::LsRefsCommand::invoke_async()");
112114
Command::LsRefs.validate_argument_prefixes(
113115
gix_transport::Protocol::V2,
114116
self.capabilities,
@@ -144,6 +146,7 @@ pub(crate) mod function {
144146
progress: &mut impl Progress,
145147
trace: bool,
146148
) -> Result<Vec<Ref>, Error> {
149+
let _span = gix_features::trace::detail!("gix_protocol::LsRefsCommand::invoke_blocking()");
147150
Command::LsRefs.validate_argument_prefixes(
148151
gix_transport::Protocol::V2,
149152
self.capabilities,

gix/src/remote/connection/ref_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ where
157157
extra_refspecs,
158158
};
159159

160-
let fetch_refmap = handshake.fetch_or_extract_refmap(
160+
let fetch_refmap = handshake.prepare_lsrefs_or_extract_refmap(
161161
self.remote.repo.config.user_agent_tuple(),
162162
prefix_from_spec_as_filter_on_remote,
163163
context,

0 commit comments

Comments
 (0)