Skip to content

Commit bdbf245

Browse files
committed
refactor: keep Options intact through fetching
1 parent 1e593cd commit bdbf245

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")]
@@ -67,6 +66,25 @@ impl Options {
6766
extra_refspecs,
6867
}
6968
}
69+
70+
fn push_prefix_arguments(&self, arguments: &mut Vec<BString>) {
71+
if !self.prefix_from_spec_as_filter_on_remote {
72+
return;
73+
}
74+
75+
let mut seen = HashSet::new();
76+
for spec in &self.all_refspecs {
77+
let spec = spec.to_ref();
78+
if seen.insert(spec.instruction()) {
79+
let mut prefixes = Vec::with_capacity(1);
80+
spec.expand_prefixes(&mut prefixes);
81+
for mut prefix in prefixes {
82+
prefix.insert_str(0, "ref-prefix ");
83+
arguments.push(prefix);
84+
}
85+
}
86+
}
87+
}
7088
}
7189

7290
impl RefMap {
@@ -85,12 +103,7 @@ impl RefMap {
85103
transport: &mut T,
86104
user_agent: (&'static str, Option<Cow<'static, str>>),
87105
trace_packetlines: bool,
88-
Options {
89-
fetch_refspecs,
90-
prefix_from_spec_as_filter_on_remote,
91-
extra_refspecs,
92-
all_refspecs,
93-
}: Options,
106+
options: Options,
94107
) -> Result<Self, Error>
95108
where
96109
T: Transport,
@@ -103,20 +116,7 @@ impl RefMap {
103116
transport,
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
&mut progress,
@@ -127,22 +127,17 @@ impl RefMap {
127127
}
128128
};
129129

130-
Self::from_refs(
131-
remote_refs,
132-
&handshake.capabilities,
130+
Self::from_refs(remote_refs, &handshake.capabilities, options)
131+
}
132+
133+
fn from_refs(remote_refs: Vec<Ref>, capabilities: &Capabilities, options: Options) -> Result<RefMap, Error> {
134+
let Options {
133135
fetch_refspecs,
134-
all_refspecs,
135136
extra_refspecs,
136-
)
137-
}
137+
all_refspecs,
138+
..
139+
} = options;
138140

139-
fn from_refs(
140-
remote_refs: Vec<Ref>,
141-
capabilities: &Capabilities,
142-
fetch_refspecs: Vec<RefSpec>,
143-
all_refspecs: Vec<RefSpec>,
144-
extra_refspecs: Vec<RefSpec>,
145-
) -> Result<Self, Error> {
146141
let num_explicit_specs = fetch_refspecs.len();
147142
let group = gix_refspec::MatchGroup::from_fetch_specs(all_refspecs.iter().map(gix_refspec::RefSpec::to_ref));
148143
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)