-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support reading the fetch algorithm from configuration
- Loading branch information
Showing
10 changed files
with
156 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::{ | ||
config, | ||
config::tree::{keys, Fetch, Key, Section}, | ||
}; | ||
|
||
impl Fetch { | ||
/// The `fetch.negotiationAlgorithm` key. | ||
pub const NEGOTIATION_ALGORITHM: NegotiationAlgorithm = NegotiationAlgorithm::new_with_validate( | ||
"negotiationAlgorithm", | ||
&config::Tree::FETCH, | ||
validate::NegotiationAlgorithm, | ||
); | ||
} | ||
|
||
impl Section for Fetch { | ||
fn name(&self) -> &str { | ||
"fetch" | ||
} | ||
|
||
fn keys(&self) -> &[&dyn Key] { | ||
&[&Self::NEGOTIATION_ALGORITHM] | ||
} | ||
} | ||
|
||
/// The `fetch.negotiationAlgorithm` key. | ||
pub type NegotiationAlgorithm = keys::Any<validate::NegotiationAlgorithm>; | ||
|
||
mod algorithm { | ||
use gix_object::bstr::ByteSlice; | ||
use std::borrow::Cow; | ||
|
||
use crate::remote::fetch::negotiate; | ||
use crate::{ | ||
bstr::BStr, | ||
config::{key::GenericErrorWithValue, tree::sections::fetch::NegotiationAlgorithm}, | ||
}; | ||
|
||
impl NegotiationAlgorithm { | ||
/// Derive the negotiation algorithm identified by `name`, case-sensitively. | ||
pub fn try_into_negotiation_algorithm( | ||
&'static self, | ||
name: Cow<'_, BStr>, | ||
) -> Result<negotiate::Algorithm, GenericErrorWithValue> { | ||
Ok(match name.as_ref().as_bytes() { | ||
b"noop" => negotiate::Algorithm::Noop, | ||
b"consecutive" | b"default" => negotiate::Algorithm::Consecutive, | ||
b"skipping" => negotiate::Algorithm::Skipping, | ||
_ => return Err(GenericErrorWithValue::from_value(self, name.into_owned())), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
mod validate { | ||
use crate::{ | ||
bstr::BStr, | ||
config::tree::{keys, Fetch}, | ||
}; | ||
|
||
pub struct NegotiationAlgorithm; | ||
impl keys::Validate for NegotiationAlgorithm { | ||
fn validate(&self, value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { | ||
Fetch::NEGOTIATION_ALGORITHM.try_into_negotiation_algorithm(value.into())?; | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters