Skip to content

Commit 7a60e78

Browse files
committed
refactor!: move prefix argument handling into LsRefsCommand::new()
1 parent 37a42bd commit 7a60e78

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,10 @@ impl RefMap {
7777
{
7878
let _span = gix_trace::coarse!("gix_protocol::fetch::RefMap::new()");
7979
let all_refspecs = context.aggregate_refspecs();
80-
let mut refs_cmd = crate::LsRefsCommand::new(capabilities, user_agent);
81-
if prefix_from_spec_as_filter_on_remote {
82-
refs_cmd.push_prefix_arguments(&all_refspecs);
83-
}
84-
85-
let remote_refs = refs_cmd.invoke(transport, &mut progress, trace_packetlines).await?;
80+
let prefix_refspecs = prefix_from_spec_as_filter_on_remote.then_some(&all_refspecs[..]);
81+
let remote_refs = crate::LsRefsCommand::new(prefix_refspecs, capabilities, user_agent)
82+
.invoke(transport, &mut progress, trace_packetlines)
83+
.await?;
8684
Self::from_refs(remote_refs, capabilities, context)
8785
}
8886

gix-protocol/src/ls_refs.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ pub(crate) mod function {
5858
impl<'a> LsRefsCommand<'a> {
5959
/// Build a command to list refs from the given server `capabilities`,
6060
/// using `agent` information to identify ourselves.
61-
pub fn new(capabilities: &'a Capabilities, agent: (&'static str, Option<Cow<'static, str>>)) -> Self {
61+
pub fn new(
62+
prefix_refspecs: Option<&[gix_refspec::RefSpec]>,
63+
capabilities: &'a Capabilities,
64+
agent: (&'static str, Option<Cow<'static, str>>),
65+
) -> Self {
6266
let _span =
6367
gix_features::trace::detail!("gix_protocol::LsRefsCommand::new()", capabilities = ?capabilities);
6468
let ls_refs = Command::LsRefs;
@@ -73,6 +77,21 @@ pub(crate) mod function {
7377
arguments.push("unborn".into());
7478
}
7579

80+
if let Some(refspecs) = prefix_refspecs {
81+
let mut seen = HashSet::new();
82+
for spec in refspecs {
83+
let spec = spec.to_ref();
84+
if seen.insert(spec.instruction()) {
85+
let mut prefixes = Vec::with_capacity(1);
86+
spec.expand_prefixes(&mut prefixes);
87+
for mut prefix in prefixes {
88+
prefix.insert_str(0, "ref-prefix ");
89+
arguments.push(prefix);
90+
}
91+
}
92+
}
93+
}
94+
7695
Self {
7796
capabilities,
7897
features,
@@ -114,20 +133,5 @@ pub(crate) mod function {
114133
.await?;
115134
Ok(from_v2_refs(&mut remote_refs).await?)
116135
}
117-
118-
pub(crate) fn push_prefix_arguments(&mut self, all_refspecs: &[gix_refspec::RefSpec]) {
119-
let mut seen = HashSet::new();
120-
for spec in all_refspecs {
121-
let spec = spec.to_ref();
122-
if seen.insert(spec.instruction()) {
123-
let mut prefixes = Vec::with_capacity(1);
124-
spec.expand_prefixes(&mut prefixes);
125-
for mut prefix in prefixes {
126-
prefix.insert_str(0, "ref-prefix ");
127-
self.arguments.push(prefix);
128-
}
129-
}
130-
}
131-
}
132136
}
133137
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ mod fetch_fn {
106106
None => match delegate.action() {
107107
Ok(RefsAction::Skip) => Vec::new(),
108108
Ok(RefsAction::Continue) => {
109-
LsRefsCommand::new(&capabilities, ("agent", Some(Cow::Owned(agent.clone()))))
109+
LsRefsCommand::new(None, &capabilities, ("agent", Some(Cow::Owned(agent.clone()))))
110110
.invoke(&mut transport, &mut progress, trace)
111111
.await?
112112
}

0 commit comments

Comments
 (0)