1
1
use crate :: config:: { Branch , FetchRecurse , Ignore , Update } ;
2
- use crate :: { config, File } ;
2
+ use crate :: { config, File , IsActivePlatform } ;
3
3
use bstr:: BStr ;
4
4
use std:: borrow:: Cow ;
5
5
use std:: collections:: HashSet ;
@@ -40,17 +40,7 @@ impl File {
40
40
} )
41
41
}
42
42
43
- /// Return an iterator of names along with a boolean that indicates the submodule is active (`true`) or inactive (`false`).
44
- /// If the boolean was wrapped in an error, there was a configuration error.
45
- /// Use `defaults` for parsing the pathspecs used to match on names via `submodule.active` configuration retrieved from `config`.
46
- /// `attributes` provides a way to resolve the attributes mentioned in pathspecs.
47
- ///
48
- /// Inactive submodules should not participate in any operations that are applying to all submodules.
49
- ///
50
- /// Note that the entirety of sections in `config` are considered, not just the ones of the configuration for the repository itself.
51
- /// `submodule.active` pathspecs are considered to be top-level specs and match the name of submodules, which may be considered active
52
- /// on match. However, there is a [hierarchy of rules](https://git-scm.com/docs/gitsubmodules#_active_submodules) that's
53
- /// implemented here, but pathspecs add the most complexity.
43
+ /// Similar to [Self::is_active_platform()], but automatically applies it to each name to learn if a submodule is active or not.
54
44
pub fn names_and_active_state < ' a > (
55
45
& ' a self ,
56
46
config : & ' a gix_config:: File < ' static > ,
@@ -63,12 +53,30 @@ impl File {
63
53
) -> bool
64
54
+ ' a ,
65
55
) -> Result <
66
- impl Iterator < Item = ( & BStr , Result < bool , config :: names_and_active_state :: iter :: Error > ) > + ' a ,
67
- config :: names_and_active_state :: Error ,
56
+ impl Iterator < Item = ( & BStr , Result < bool , crate :: is_active_platform :: is_active :: Error > ) > + ' a ,
57
+ crate :: is_active_platform :: Error ,
68
58
> {
69
- let mut search = config
59
+ let mut platform = self . is_active_platform ( config, defaults) ?;
60
+ let iter = self
61
+ . names ( )
62
+ . map ( move |name| ( name, platform. is_active ( self , config, name, & mut attributes) ) ) ;
63
+ Ok ( iter)
64
+ }
65
+
66
+ /// Return a platform which allows to check if a submodule name is active or inactive.
67
+ /// Use `defaults` for parsing the pathspecs used to later match on names via `submodule.active` configuration retrieved from `config`.
68
+ ///
69
+ /// All `submodule.active` pathspecs are considered to be top-level specs and match the name of submodules, which are active
70
+ /// on inclusive match.
71
+ /// The full algorithm is described as [hierarchy of rules](https://git-scm.com/docs/gitsubmodules#_active_submodules).
72
+ pub fn is_active_platform (
73
+ & self ,
74
+ config : & gix_config:: File < ' _ > ,
75
+ defaults : gix_pathspec:: Defaults ,
76
+ ) -> Result < IsActivePlatform , crate :: is_active_platform:: Error > {
77
+ let search = config
70
78
. strings_by_key ( "submodule.active" )
71
- . map ( |patterns| -> Result < _ , config :: names_and_active_state :: Error > {
79
+ . map ( |patterns| -> Result < _ , crate :: is_active_platform :: Error > {
72
80
let patterns = patterns
73
81
. into_iter ( )
74
82
. map ( |pattern| gix_pathspec:: parse ( & pattern, defaults) )
@@ -80,27 +88,7 @@ impl File {
80
88
) ?)
81
89
} )
82
90
. transpose ( ) ?;
83
- let iter = self . names ( ) . map ( move |name| {
84
- let active = ( || -> Result < _ , config:: names_and_active_state:: iter:: Error > {
85
- if let Some ( val) = config. boolean ( "submodule" , Some ( name) , "active" ) . transpose ( ) ? {
86
- return Ok ( val) ;
87
- } ;
88
- if let Some ( val) = search
89
- . as_mut ( )
90
- . and_then ( |search| search. pattern_matching_relative_path ( name, Some ( true ) , & mut attributes) )
91
- . map ( |m| !m. is_excluded ( ) )
92
- {
93
- return Ok ( val) ;
94
- }
95
- Ok ( match self . url ( name) {
96
- Ok ( _) => true ,
97
- Err ( config:: url:: Error :: Missing { .. } ) => false ,
98
- Err ( err) => return Err ( err. into ( ) ) ,
99
- } )
100
- } ) ( ) ;
101
- ( name, active)
102
- } ) ;
103
- Ok ( iter)
91
+ Ok ( IsActivePlatform { search } )
104
92
}
105
93
106
94
/// Given the `relative_path` (as seen from the root of the worktree) of a submodule with possibly platform-specific
0 commit comments