Skip to content

Commit 1e593cd

Browse files
committed
refactor!: store all_refspecs in Options
1 parent b8fdc5d commit 1e593cd

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,37 @@ pub enum Error {
3434
pub struct Options {
3535
/// All explicit refspecs to identify references on the remote that you are interested in.
3636
/// 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>,
37+
fetch_refspecs: Vec<gix_refspec::RefSpec>,
3838
/// Use a two-component prefix derived from the ref-spec's source, like `refs/heads/` to let the server pre-filter refs
3939
/// with great potential for savings in traffic and local CPU time. Defaults to `true`.
40-
pub prefix_from_spec_as_filter_on_remote: bool,
40+
prefix_from_spec_as_filter_on_remote: bool,
4141
/// A list of refspecs to use as implicit refspecs which won't be saved or otherwise be part of the remote in question.
4242
///
4343
/// This is useful for handling `remote.<name>.tagOpt` for example.
44-
pub extra_refspecs: Vec<gix_refspec::RefSpec>,
44+
extra_refspecs: Vec<gix_refspec::RefSpec>,
45+
all_refspecs: Vec<gix_refspec::RefSpec>,
4546
}
4647

4748
impl Options {
4849
/// Create options to fetch the given `fetch_refspecs`.
4950
pub fn fetch(fetch_refspecs: Vec<gix_refspec::RefSpec>) -> Self {
50-
Options {
51-
fetch_refspecs,
52-
prefix_from_spec_as_filter_on_remote: true,
53-
extra_refspecs: Vec::new(),
51+
Self::new(fetch_refspecs, true, Vec::new())
52+
}
53+
54+
/// Specify all options for fetching.
55+
pub fn new(
56+
fetch_refspecs: Vec<gix_refspec::RefSpec>,
57+
prefix_from_spec_as_filter_on_remote: bool,
58+
extra_refspecs: Vec<gix_refspec::RefSpec>,
59+
) -> Self {
60+
let mut all_refspecs = fetch_refspecs.clone();
61+
all_refspecs.extend(extra_refspecs.iter().cloned());
62+
63+
Self {
64+
all_refspecs,
65+
fetch_refspecs: fetch_refspecs.clone(),
66+
prefix_from_spec_as_filter_on_remote,
67+
extra_refspecs,
5468
}
5569
}
5670
}
@@ -75,17 +89,13 @@ impl RefMap {
7589
fetch_refspecs,
7690
prefix_from_spec_as_filter_on_remote,
7791
extra_refspecs,
92+
all_refspecs,
7893
}: Options,
7994
) -> Result<Self, Error>
8095
where
8196
T: Transport,
8297
{
8398
let _span = gix_trace::coarse!("gix_protocol::fetch::RefMap::new()");
84-
let all_refspecs = {
85-
let mut s: Vec<_> = fetch_refspecs.to_vec();
86-
s.extend(extra_refspecs.clone());
87-
s
88-
};
8999
let remote_refs = match handshake.refs.take() {
90100
Some(refs) => refs,
91101
None => {

gix/src/remote/connection/ref_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ where
156156
&mut self.transport.inner,
157157
self.remote.repo.config.user_agent_tuple(),
158158
self.trace,
159-
gix_protocol::fetch::refmap::init::Options {
160-
fetch_refspecs: self.remote.fetch_specs.clone(),
159+
gix_protocol::fetch::refmap::init::Options::new(
160+
self.remote.fetch_specs.clone(),
161161
prefix_from_spec_as_filter_on_remote,
162162
extra_refspecs,
163-
},
163+
),
164164
)
165165
.await?;
166166
self.handshake = Some(handshake);

0 commit comments

Comments
 (0)