| @@ -12,34 +12,19 @@ pub enum Error { · 11 unmodified lines |
| 12 | ParsePattern(#[from] gix_pathspec::parse::Error), | 12 | ParsePattern(#[from] gix_pathspec::parse::Error), |
| 13 | } | 13 | } |
| 14 | | 14 | |
| 15 | /// | | |
| 16 | pub mod is_active { | | |
| 17 | /// The error returned by the iterator of [File::names_and_active_state](crate::File::names_and_active_state()). | | |
| 18 | #[derive(Debug, thiserror::Error)] | | |
| 19 | #[allow(missing_docs)] | | |
| 20 | pub enum Error { | | |
| 21 | #[error("The value of the 'active' field of a submodule could not be decoded")] | | |
| 22 | ActiveField(#[from] gix_config::value::Error), | | |
| 23 | #[error(transparent)] | | |
| 24 | Url(#[from] crate::config::url::Error), | | |
| 25 | } | | |
| 26 | } | | |
| 27 | | | |
| 28 | impl IsActivePlatform { | 15 | impl IsActivePlatform { |
| 29 | /// Returns `true` if the submodule named `name` is active or `false` otherwise. | 16 | /// Returns `true` if the submodule named `name` is active or `false` otherwise. |
| 30 | /// `modules` is the instance that [is_active_platform()](crate::File::is_active_platform()) was called on, and | 17 | /// `config` is the configuration that was passed to the originating [modules file](crate::File). |
| 31 | /// `config` is the configuration that was passed there as well. | 18 | /// `attributes(relative_path, case, is_dir, outcome)` provides a way to resolve the attributes mentioned |
| 32 | /// `attributes(relative_path, case, is_dir, outcome)` provides a way to resolve the attributes mentioned in `submodule.active` pathspecs | 19 | /// in `submodule.active` pathspecs that are evaluated in the platforms git configuration. |
| 33 | /// that are evaluated in the platforms git configuration. | | |
| 34 | /// | 20 | /// |
| 35 | /// A submodule's active state is determined in the following order | 21 | /// A submodule's active state is determined in the following order |
| 36 | /// | 22 | /// |
| 37 | /// * it's `submodule.<name>.active` configuration is set | 23 | /// * it's `submodule.<name>.active` is set in `config` |
| 38 | /// * it matches a `submodule.active` pathspec either positively or negatively via `:!<spec>` | 24 | /// * it matches a `submodule.active` pathspec either positively or negatively via `:!<spec>` |
| 39 | /// * it's active if it has a `url` | 25 | /// * it's active if it has any `url` set in `config` |
| 40 | pub fn is_active( | 26 | pub fn is_active( |
| 41 | &mut self, | 27 | &mut self, |
| 42 | modules: &crate::File, | | |
| 43 | config: &gix_config::File<'static>, | 28 | config: &gix_config::File<'static>, |
| 44 | name: &BStr, | 29 | name: &BStr, |
| 45 | attributes: impl FnMut( | 30 | attributes: impl FnMut( |
| @@ -48,7 +33,7 @@ impl IsActivePlatform { · 2 unmodified lines |
| 48 | bool, | 33 | bool, |
| 49 | &mut gix_pathspec::attributes::search::Outcome, | 34 | &mut gix_pathspec::attributes::search::Outcome, |
| 50 | ) -> bool, | 35 | ) -> bool, |
| 51 | ) -> Result<bool, is_active::Error> { | 36 | ) -> Result<bool, gix_config::value::Error> { |
| 52 | if let Some(val) = config.boolean("submodule", Some(name), "active").transpose()? { | 37 | if let Some(val) = config.boolean("submodule", Some(name), "active").transpose()? { |
| 53 | return Ok(val); | 38 | return Ok(val); |
| 54 | }; | 39 | }; |
| @@ -59,10 +44,6 @@ impl IsActivePlatform { · 4 unmodified lines |
| 59 | }) { | 44 | }) { |
| 60 | return Ok(val); | 45 | return Ok(val); |
| 61 | } | 46 | } |
| 62 | Ok(match modules.url(name) { | 47 | Ok(config.string("submodule", Some(name), "url").is_some()) |
| 63 | Ok(_) => true, | | |
| 64 | Err(crate::config::url::Error::Missing { .. }) => false, | | |
| 65 | Err(err) => return Err(err.into()), | | |
| 66 | }) | | |
| 67 | } | 48 | } |
| 68 | } | 49 | } |