Skip to content

Commit d1f9c63

Browse files
committed
feat: add fetch::Arguments::add_feature() for unconditional additions of arguments that are supposed to be features.
This differentiation is important to support V1 and V2 correctly, which have a different notion of features with V1 special-casing them, and V2 just sees everything as arguments.
1 parent 090357e commit d1f9c63

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

gix-protocol/src/fetch/arguments/blocking_io.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ impl Arguments {
4545
}
4646
transport.invoke(
4747
Command::Fetch.as_str(),
48-
self.features
49-
.iter()
50-
.filter_map(|(k, v)| v.as_ref().map(|v| (*k, Some(v.as_ref())))),
48+
self.features.iter().filter(|(_, v)| v.is_some()).cloned(),
5149
Some(std::mem::replace(&mut self.args, retained_state).into_iter()),
5250
)
5351
}

gix-protocol/src/fetch/arguments/mod.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,30 @@ impl Arguments {
165165
pub fn use_include_tag(&mut self) {
166166
debug_assert!(self.supports_include_tag, "'include-tag' feature required");
167167
if self.supports_include_tag {
168-
match self.version {
169-
gix_transport::Protocol::V0 | gix_transport::Protocol::V1 => {
170-
let features = self
171-
.features_for_first_want
172-
.as_mut()
173-
.expect("call use_include_tag before want()");
174-
features.push("include-tag".into())
175-
}
176-
gix_transport::Protocol::V2 => {
177-
self.args.push("include-tag".into());
178-
}
168+
self.add_feature("include-tag");
169+
}
170+
}
171+
172+
/// Add the given `feature`, unconditionally.
173+
///
174+
/// Note that sending an unknown or unsupported feature may cause the remote to terminate
175+
/// the connection. Use this method if you know what you are doing *and* there is no specialized
176+
/// method for this, e.g. [`Self::use_include_tag()`].
177+
pub fn add_feature(&mut self, feature: &str) {
178+
match self.version {
179+
gix_transport::Protocol::V0 | gix_transport::Protocol::V1 => {
180+
let features = self
181+
.features_for_first_want
182+
.as_mut()
183+
.expect("call add_feature before first want()");
184+
features.push(feature.into())
185+
}
186+
gix_transport::Protocol::V2 => {
187+
self.args.push(feature.into());
179188
}
180189
}
181190
}
191+
182192
fn prefixed(&mut self, prefix: &str, value: impl fmt::Display) {
183193
self.args.push(format!("{prefix}{value}").into());
184194
}

gix-protocol/src/fetch/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ mod arguments {
319319
assert!(arguments.is_stateless(true), "V2 is stateless…");
320320
assert!(arguments.is_stateless(false), "…in all cases");
321321

322+
arguments.add_feature("no-progress");
322323
arguments.deepen(1);
323324
arguments.deepen_relative();
324325
arguments.want(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c907"));
@@ -329,6 +330,7 @@ mod arguments {
329330
b"0012command=fetch
330331
0001000ethin-pack
331332
000eofs-delta
333+
0010no-progress
332334
000ddeepen 1
333335
0014deepen-relative
334336
0032want 7b333369de1221f9bfbbe03a3a13e9a09bc1c907
@@ -347,6 +349,7 @@ mod arguments {
347349
let mut t = transport(&mut out, *is_stateful);
348350
let mut arguments = arguments_v2(Some("shallow"));
349351

352+
arguments.add_feature("no-progress");
350353
arguments.deepen(1);
351354
arguments.deepen_since(12345);
352355
arguments.shallow(id("7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff"));
@@ -362,6 +365,7 @@ mod arguments {
362365
b"0012command=fetch
363366
0001000ethin-pack
364367
000eofs-delta
368+
0010no-progress
365369
000ddeepen 1
366370
0017deepen-since 12345
367371
0035shallow 7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff
@@ -371,6 +375,7 @@ mod arguments {
371375
00000012command=fetch
372376
0001000ethin-pack
373377
000eofs-delta
378+
0010no-progress
374379
000ddeepen 1
375380
0017deepen-since 12345
376381
0035shallow 7b333369de1221f9bfbbe03a3a13e9a09bc1c9ff

0 commit comments

Comments
 (0)