Skip to content

Commit f87d876

Browse files
committed
refactor: keep Options intact through fetching
1 parent 4de5e4f commit f87d876

File tree

1 file changed

+29
-34
lines changed
  • gix-protocol/src/fetch/refmap

1 file changed

+29
-34
lines changed

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

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{borrow::Cow, collections::HashSet};
22

33
use bstr::{BString, ByteSlice, ByteVec};
44
use gix_features::progress::Progress;
5-
use gix_refspec::RefSpec;
65
use gix_transport::client::Capabilities;
76

87
#[cfg(feature = "async-client")]
@@ -68,6 +67,25 @@ impl Options {
6867
extra_refspecs,
6968
}
7069
}
70+
71+
fn push_prefix_arguments(&self, arguments: &mut Vec<BString>) {
72+
if !self.prefix_from_spec_as_filter_on_remote {
73+
return;
74+
}
75+
76+
let mut seen = HashSet::new();
77+
for spec in &self.all_refspecs {
78+
let spec = spec.to_ref();
79+
if seen.insert(spec.instruction()) {
80+
let mut prefixes = Vec::with_capacity(1);
81+
spec.expand_prefixes(&mut prefixes);
82+
for mut prefix in prefixes {
83+
prefix.insert_str(0, "ref-prefix ");
84+
arguments.push(prefix);
85+
}
86+
}
87+
}
88+
}
7189
}
7290

7391
impl RefMap {
@@ -86,12 +104,7 @@ impl RefMap {
86104
transport: &mut T,
87105
user_agent: (&'static str, Option<Cow<'static, str>>),
88106
trace_packetlines: bool,
89-
Options {
90-
fetch_refspecs,
91-
prefix_from_spec_as_filter_on_remote,
92-
extra_refspecs,
93-
all_refspecs,
94-
}: Options,
107+
options: Options,
95108
) -> Result<Self, Error>
96109
where
97110
T: Transport,
@@ -103,20 +116,7 @@ impl RefMap {
103116
LsRefs::new(
104117
&handshake.capabilities,
105118
|_capabilities, arguments| {
106-
if prefix_from_spec_as_filter_on_remote {
107-
let mut seen = HashSet::new();
108-
for spec in &all_refspecs {
109-
let spec = spec.to_ref();
110-
if seen.insert(spec.instruction()) {
111-
let mut prefixes = Vec::with_capacity(1);
112-
spec.expand_prefixes(&mut prefixes);
113-
for mut prefix in prefixes {
114-
prefix.insert_str(0, "ref-prefix ");
115-
arguments.push(prefix);
116-
}
117-
}
118-
}
119-
}
119+
options.push_prefix_arguments(arguments);
120120
Ok(crate::ls_refs::Action::Continue)
121121
},
122122
user_agent,
@@ -126,22 +126,17 @@ impl RefMap {
126126
}
127127
};
128128

129-
Self::from_refs(
130-
remote_refs,
131-
&handshake.capabilities,
129+
Self::from_refs(remote_refs, &handshake.capabilities, options)
130+
}
131+
132+
fn from_refs(remote_refs: Vec<Ref>, capabilities: &Capabilities, options: Options) -> Result<RefMap, Error> {
133+
let Options {
132134
fetch_refspecs,
133-
all_refspecs,
134135
extra_refspecs,
135-
)
136-
}
136+
all_refspecs,
137+
..
138+
} = options;
137139

138-
fn from_refs(
139-
remote_refs: Vec<Ref>,
140-
capabilities: &Capabilities,
141-
fetch_refspecs: Vec<RefSpec>,
142-
all_refspecs: Vec<RefSpec>,
143-
extra_refspecs: Vec<RefSpec>,
144-
) -> Result<Self, Error> {
145140
let num_explicit_specs = fetch_refspecs.len();
146141
let group = gix_refspec::MatchGroup::from_fetch_specs(all_refspecs.iter().map(gix_refspec::RefSpec::to_ref));
147142
let null = gix_hash::ObjectId::null(gix_hash::Kind::Sha1); // OK to hardcode Sha1, it's not supposed to match, ever.

0 commit comments

Comments
 (0)