Skip to content

Commit b8fdc5d

Browse files
committed
refactor!: store fetch refspecs in Options
1 parent be0dda2 commit b8fdc5d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

gitoxide-core/src/pack/receive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ where
8484
let user_agent = ("agent", Some(agent.clone().into()));
8585
let refmap = gix::protocol::fetch::RefMap::new(
8686
&mut progress,
87-
&fetch_refspecs,
8887
&mut handshake,
8988
&mut transport.inner,
9089
user_agent.clone(),
9190
trace_packetlines,
92-
gix::protocol::fetch::refmap::init::Options::default(),
91+
gix::protocol::fetch::refmap::init::Options::fetch(fetch_refspecs.clone()),
9392
)
9493
.await?;
9594

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub enum Error {
3232
/// For use in [`RefMap::new()`].
3333
#[derive(Debug, Clone)]
3434
pub struct Options {
35+
/// All explicit refspecs to identify references on the remote that you are interested in.
36+
/// Note that these are copied to [`RefMap::refspecs`] for convenience, as `RefMap::mappings` refer to them by index.
37+
pub fetch_refspecs: Vec<gix_refspec::RefSpec>,
3538
/// Use a two-component prefix derived from the ref-spec's source, like `refs/heads/` to let the server pre-filter refs
3639
/// with great potential for savings in traffic and local CPU time. Defaults to `true`.
3740
pub prefix_from_spec_as_filter_on_remote: bool,
@@ -41,9 +44,11 @@ pub struct Options {
4144
pub extra_refspecs: Vec<gix_refspec::RefSpec>,
4245
}
4346

44-
impl Default for Options {
45-
fn default() -> Self {
47+
impl Options {
48+
/// Create options to fetch the given `fetch_refspecs`.
49+
pub fn fetch(fetch_refspecs: Vec<gix_refspec::RefSpec>) -> Self {
4650
Options {
51+
fetch_refspecs,
4752
prefix_from_spec_as_filter_on_remote: true,
4853
extra_refspecs: Vec::new(),
4954
}
@@ -58,18 +63,16 @@ impl RefMap {
5863
/// and [options](Options) are used to further configure the call.
5964
///
6065
/// * `progress` is used if `ls-refs` is invoked on the remote. Always the case when V2 is used.
61-
/// * `fetch_refspecs` are all explicit refspecs to identify references on the remote that you are interested in.
62-
/// Note that these are copied to [`RefMap::refspecs`] for convenience, as `RefMap::mappings` refer to them by index.
6366
#[allow(clippy::result_large_err)]
6467
#[maybe_async::maybe_async]
6568
pub async fn new<T>(
6669
mut progress: impl Progress,
67-
fetch_refspecs: &[gix_refspec::RefSpec],
6870
handshake: &mut Outcome,
6971
transport: &mut T,
7072
user_agent: (&'static str, Option<Cow<'static, str>>),
7173
trace_packetlines: bool,
7274
Options {
75+
fetch_refspecs,
7376
prefix_from_spec_as_filter_on_remote,
7477
extra_refspecs,
7578
}: Options,
@@ -126,7 +129,7 @@ impl RefMap {
126129
fn from_refs(
127130
remote_refs: Vec<Ref>,
128131
capabilities: &Capabilities,
129-
fetch_refspecs: &[RefSpec],
132+
fetch_refspecs: Vec<RefSpec>,
130133
all_refspecs: Vec<RefSpec>,
131134
extra_refspecs: Vec<RefSpec>,
132135
) -> Result<Self, Error> {
@@ -182,7 +185,7 @@ impl RefMap {
182185

183186
Ok(Self {
184187
mappings,
185-
refspecs: fetch_refspecs.to_vec(),
188+
refspecs: fetch_refspecs,
186189
extra_refspecs,
187190
fixes,
188191
remote_refs,

gix/src/remote/connection/ref_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ where
152152
.await?;
153153
let refmap = gix_protocol::fetch::RefMap::new(
154154
progress,
155-
&self.remote.fetch_specs,
156155
&mut handshake,
157156
&mut self.transport.inner,
158157
self.remote.repo.config.user_agent_tuple(),
159158
self.trace,
160159
gix_protocol::fetch::refmap::init::Options {
160+
fetch_refspecs: self.remote.fetch_specs.clone(),
161161
prefix_from_spec_as_filter_on_remote,
162162
extra_refspecs,
163163
},

0 commit comments

Comments
 (0)