Skip to content

Commit d61a8fb

Browse files
committed
refactor!: inline RefMap::fetch() into Handshake::fetch_or_extract_refmap()
1 parent d997b00 commit d61a8fb

File tree

4 files changed

+18
-64
lines changed

4 files changed

+18
-64
lines changed

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 [`RefMap::fetch()`].
114+
/// - The references known on the remote, as previously obtained with [`crate::Handshake::fetch_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: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
use std::borrow::Cow;
2-
31
use bstr::{BString, ByteSlice};
4-
use gix_features::progress::Progress;
52
use gix_transport::client::Capabilities;
63

7-
#[cfg(feature = "async-client")]
8-
use crate::transport::client::async_io::Transport;
9-
#[cfg(feature = "blocking-client")]
10-
use crate::transport::client::blocking_io::Transport;
114
use crate::{
125
fetch::{
136
refmap::{Mapping, Source, SpecIndex},
@@ -16,7 +9,7 @@ use crate::{
169
handshake::Ref,
1710
};
1811

19-
/// The error returned by [`RefMap::fetch()`].
12+
/// The error returned by [`crate::Handshake::fetch_or_extract_refmap()`].
2013
#[derive(Debug, thiserror::Error)]
2114
#[allow(missing_docs)]
2215
pub enum Error {
@@ -28,7 +21,7 @@ pub enum Error {
2821
ListRefs(#[from] crate::ls_refs::Error),
2922
}
3023

31-
/// For use in [`RefMap::fetch()`].
24+
/// For use in [`RefMap::from_refs()`].
3225
#[derive(Debug, Clone)]
3326
pub struct Context {
3427
/// All explicit refspecs to identify references on the remote that you are interested in.
@@ -41,49 +34,14 @@ pub struct Context {
4134
}
4235

4336
impl Context {
44-
fn aggregate_refspecs(&self) -> Vec<gix_refspec::RefSpec> {
37+
pub(crate) fn aggregate_refspecs(&self) -> Vec<gix_refspec::RefSpec> {
4538
let mut all_refspecs = self.fetch_refspecs.clone();
4639
all_refspecs.extend(self.extra_refspecs.iter().cloned());
4740
all_refspecs
4841
}
4942
}
5043

5144
impl RefMap {
52-
/// Create a new instance by obtaining all references on the remote that have been filtered through our remote's specs
53-
/// for _fetching_.
54-
///
55-
/// * `progress` is used if `ls-refs` is invoked on the remote. Always the case when V2 is used.
56-
/// * `capabilities` are the capabilities of the server, obtained by a [handshake](crate::handshake()).
57-
/// * `transport` is a way to communicate with the server to obtain the reference listing.
58-
/// * `user_agent` is passed to the server.
59-
/// * `trace_packetlines` traces all packet lines if `true`, for debugging primarily.
60-
/// * `prefix_from_spec_as_filter_on_remote`
61-
/// - Use a two-component prefix derived from the ref-spec's source, like `refs/heads/` to let the server pre-filter refs
62-
/// with great potential for savings in traffic and local CPU time.
63-
/// * `context` to provide more [configuration](Context).
64-
#[allow(clippy::result_large_err)]
65-
#[maybe_async::maybe_async]
66-
pub async fn fetch<T>(
67-
mut progress: impl Progress,
68-
capabilities: &Capabilities,
69-
transport: &mut T,
70-
user_agent: (&'static str, Option<Cow<'static, str>>),
71-
trace_packetlines: bool,
72-
prefix_from_spec_as_filter_on_remote: bool,
73-
context: Context,
74-
) -> Result<Self, Error>
75-
where
76-
T: Transport,
77-
{
78-
let _span = gix_trace::coarse!("gix_protocol::fetch::RefMap::new()");
79-
let all_refspecs = context.aggregate_refspecs();
80-
let prefix_refspecs = prefix_from_spec_as_filter_on_remote.then_some(&all_refspecs[..]);
81-
let remote_refs = crate::LsRefsCommand::new(prefix_refspecs, capabilities, user_agent)
82-
.invoke(transport, &mut progress, trace_packetlines)
83-
.await?;
84-
Self::from_refs(remote_refs, capabilities, context)
85-
}
86-
8745
/// Create a ref-map from already obtained `remote_refs`. Use `context` to pass in refspecs.
8846
/// `capabilities` are used to determine the object format.
8947
pub fn from_refs(remote_refs: Vec<Ref>, capabilities: &Capabilities, context: Context) -> Result<RefMap, 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 [`RefMap::fetch()`] and [`fetch`](crate::fetch()).
21+
/// For use in [`crate::Handshake::fetch_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 [`RefMap::fetch()`] or the `fetch` call in [`fetch()`](crate::fetch()).
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()).
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: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub(crate) mod hero {
7575
use crate::transport::client::async_io::Transport;
7676
#[cfg(feature = "blocking-client")]
7777
use crate::transport::client::blocking_io::Transport;
78-
use crate::Handshake;
78+
use crate::{fetch::RefMap, Handshake};
7979
use gix_features::progress::Progress;
8080
use std::borrow::Cow;
8181

@@ -96,21 +96,17 @@ pub(crate) mod hero {
9696
where
9797
T: Transport,
9898
{
99-
Ok(match self.refs.take() {
100-
Some(refs) => crate::fetch::RefMap::from_refs(refs, &self.capabilities, refmap_context)?,
101-
None => {
102-
crate::fetch::RefMap::fetch(
103-
&mut progress,
104-
&self.capabilities,
105-
transport,
106-
user_agent,
107-
trace_packetlines,
108-
prefix_from_spec_as_filter_on_remote,
109-
refmap_context,
110-
)
111-
.await?
112-
}
113-
})
99+
if let Some(refs) = self.refs.take() {
100+
return crate::fetch::RefMap::from_refs(refs, &self.capabilities, refmap_context);
101+
}
102+
103+
let _span = gix_trace::coarse!("gix_protocol::handshake::fetch_or_extract_refmap()");
104+
let all_refspecs = refmap_context.aggregate_refspecs();
105+
let prefix_refspecs = prefix_from_spec_as_filter_on_remote.then_some(&all_refspecs[..]);
106+
let remote_refs = crate::LsRefsCommand::new(prefix_refspecs, &self.capabilities, user_agent)
107+
.invoke(transport, &mut progress, trace_packetlines)
108+
.await?;
109+
RefMap::from_refs(remote_refs, &self.capabilities, refmap_context)
114110
}
115111
}
116112
}

0 commit comments

Comments
 (0)