use bstr::BStr;
use crate::IsActivePlatform;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
NormalizePattern(#[from] gix_pathspec::normalize::Error),
#[error(transparent)]
ParsePattern(#[from] gix_pathspec::parse::Error),
}
impl IsActivePlatform {
pub fn is_active(
&mut self,
config: &gix_config::File<'static>,
name: &BStr,
attributes: &mut dyn FnMut(
&BStr,
gix_pathspec::attributes::glob::pattern::Case,
bool,
&mut gix_pathspec::attributes::search::Outcome,
) -> bool,
) -> Result<bool, gix_config::value::Error> {
if let Some(val) = config.boolean(&format!("submodule.{name}.active")).transpose()? {
return Ok(val);
}
if let Some(val) = self.search.as_mut().map(|search| {
search
.pattern_matching_relative_path(name, Some(true), attributes)
.is_some_and(|m| !m.is_excluded())
}) {
return Ok(val);
}
Ok(config.string(&format!("submodule.{name}.url")).is_some())
}
}