Skip to content

Commit 149bcfc

Browse files
committed
refactor!: take extra arguments as a separate argument
1 parent 7e08219 commit 149bcfc

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ impl RefMap {
8080
let remote_refs = crate::ls_refs(
8181
transport,
8282
capabilities,
83-
|_capabilities, arguments| {
84-
push_prefix_arguments(prefix_from_spec_as_filter_on_remote, arguments, &all_refspecs);
85-
Ok(crate::ls_refs::Action::Continue)
86-
},
83+
|_capabilities| Ok(crate::ls_refs::Action::Continue),
84+
push_prefix_arguments(prefix_from_spec_as_filter_on_remote, &all_refspecs),
8785
&mut progress,
8886
trace_packetlines,
8987
user_agent,
@@ -164,13 +162,13 @@ impl RefMap {
164162

165163
fn push_prefix_arguments(
166164
prefix_from_spec_as_filter_on_remote: bool,
167-
arguments: &mut Vec<BString>,
168165
all_refspecs: &[gix_refspec::RefSpec],
169-
) {
166+
) -> Vec<BString> {
170167
if !prefix_from_spec_as_filter_on_remote {
171-
return;
168+
return Vec::new();
172169
}
173170

171+
let mut arguments = Vec::new();
174172
let mut seen = HashSet::new();
175173
for spec in all_refspecs {
176174
let spec = spec.to_ref();
@@ -183,4 +181,6 @@ fn push_prefix_arguments(
183181
}
184182
}
185183
}
184+
185+
arguments
186186
}

gix-protocol/src/ls_refs.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ pub(crate) mod function {
6161
};
6262

6363
/// Invoke a ls-refs V2 command on `transport`, which requires a prior handshake that yielded
64-
/// server `capabilities`. `prepare_ls_refs(capabilities, arguments)` can be used to alter the _ls-refs_.
64+
/// server `capabilities`. `prepare_ls_refs(capabilities)` can be used to alter the _ls-refs_.
65+
/// `arguments` are extra arguments to send to the server.
6566
/// `progress` is used to provide feedback.
6667
/// The `agent` information will be added to the features sent to the server.
6768
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
6869
#[maybe_async]
6970
pub async fn ls_refs(
7071
mut transport: impl Transport,
7172
capabilities: &Capabilities,
72-
prepare_ls_refs: impl FnOnce(&Capabilities, &mut Vec<BString>) -> std::io::Result<Action>,
73+
prepare_ls_refs: impl FnOnce(&Capabilities) -> std::io::Result<Action>,
74+
extra_args: Vec<BString>,
7375
progress: &mut impl Progress,
7476
trace: bool,
7577
agent: (&'static str, Option<Cow<'static, str>>),
@@ -86,7 +88,9 @@ pub(crate) mod function {
8688
{
8789
ls_args.push("unborn".into());
8890
}
89-
let refs = match prepare_ls_refs(capabilities, &mut ls_args) {
91+
92+
ls_args.extend(extra_args);
93+
let refs = match prepare_ls_refs(capabilities) {
9094
Ok(Action::Skip) => Vec::new(),
9195
Ok(Action::Continue) => {
9296
ls_refs.validate_argument_prefixes(

gix-protocol/tests/protocol/fetch/_impl.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ mod fetch_fn {
9595
gix_protocol::ls_refs(
9696
&mut transport,
9797
&capabilities,
98-
|a, _b| delegate.prepare_ls_refs(a),
98+
|a| delegate.prepare_ls_refs(a),
99+
Vec::new(),
99100
&mut progress,
100101
trace,
101102
("agent", Some(Cow::Owned(agent.clone()))),
@@ -327,10 +328,7 @@ mod delegate {
327328
self.deref().handshake_extra_parameters()
328329
}
329330

330-
fn prepare_ls_refs(
331-
&mut self,
332-
_server: &Capabilities,
333-
) -> io::Result<ls_refs::Action> {
331+
fn prepare_ls_refs(&mut self, _server: &Capabilities) -> io::Result<ls_refs::Action> {
334332
self.deref_mut().prepare_ls_refs(_server)
335333
}
336334

gix-protocol/tests/protocol/fetch/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ pub struct CloneRefInWantDelegate {
102102
}
103103

104104
impl DelegateBlocking for CloneRefInWantDelegate {
105-
fn prepare_ls_refs(
106-
&mut self,
107-
_server: &Capabilities,
108-
) -> io::Result<ls_refs::Action> {
105+
fn prepare_ls_refs(&mut self, _server: &Capabilities) -> io::Result<ls_refs::Action> {
109106
Ok(ls_refs::Action::Skip)
110107
}
111108

@@ -144,10 +141,7 @@ impl DelegateBlocking for LsRemoteDelegate {
144141
fn handshake_extra_parameters(&self) -> Vec<(String, Option<String>)> {
145142
vec![("value-only".into(), None), ("key".into(), Some("value".into()))]
146143
}
147-
fn prepare_ls_refs(
148-
&mut self,
149-
_server: &Capabilities,
150-
) -> std::io::Result<ls_refs::Action> {
144+
fn prepare_ls_refs(&mut self, _server: &Capabilities) -> std::io::Result<ls_refs::Action> {
151145
match self.abort_with.take() {
152146
Some(err) => Err(err),
153147
None => Ok(ls_refs::Action::Continue),

0 commit comments

Comments
 (0)