1616#include "quote.h"
1717#include "remote.h"
1818#include "worktree.h"
19+ #include "parse-options.h"
1920
2021static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND ;
21- static int config_update_recurse_submodules = RECURSE_SUBMODULES_DEFAULT ;
22+ static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF ;
2223static int parallel_jobs = 1 ;
2324static struct string_list changed_submodule_paths = STRING_LIST_INIT_DUP ;
2425static int initialized_fetch_ref_tips ;
@@ -153,7 +154,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
153154 }
154155}
155156
156- int submodule_config (const char * var , const char * value , void * cb )
157+ /* For loading from the .gitmodules file. */
158+ static int git_modules_config (const char * var , const char * value , void * cb )
157159{
158160 if (!strcmp (var , "submodule.fetchjobs" )) {
159161 parallel_jobs = git_config_int (var , value );
@@ -169,6 +171,56 @@ int submodule_config(const char *var, const char *value, void *cb)
169171 return 0 ;
170172}
171173
174+ /* Loads all submodule settings from the config. */
175+ int submodule_config (const char * var , const char * value , void * cb )
176+ {
177+ if (!strcmp (var , "submodule.recurse" )) {
178+ int v = git_config_bool (var , value ) ?
179+ RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF ;
180+ config_update_recurse_submodules = v ;
181+ return 0 ;
182+ } else {
183+ return git_modules_config (var , value , cb );
184+ }
185+ }
186+
187+ /* Cheap function that only determines if we're interested in submodules at all */
188+ int git_default_submodule_config (const char * var , const char * value , void * cb )
189+ {
190+ if (!strcmp (var , "submodule.recurse" )) {
191+ int v = git_config_bool (var , value ) ?
192+ RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF ;
193+ config_update_recurse_submodules = v ;
194+ }
195+ return 0 ;
196+ }
197+
198+ int option_parse_recurse_submodules_worktree_updater (const struct option * opt ,
199+ const char * arg , int unset )
200+ {
201+ if (unset ) {
202+ config_update_recurse_submodules = RECURSE_SUBMODULES_OFF ;
203+ return 0 ;
204+ }
205+ if (arg )
206+ config_update_recurse_submodules =
207+ parse_update_recurse_submodules_arg (opt -> long_name ,
208+ arg );
209+ else
210+ config_update_recurse_submodules = RECURSE_SUBMODULES_ON ;
211+
212+ return 0 ;
213+ }
214+
215+ void load_submodule_cache (void )
216+ {
217+ if (config_update_recurse_submodules == RECURSE_SUBMODULES_OFF )
218+ return ;
219+
220+ gitmodules_config ();
221+ git_config (submodule_config , NULL );
222+ }
223+
172224void gitmodules_config (void )
173225{
174226 const char * work_tree = get_git_work_tree ();
@@ -196,7 +248,8 @@ void gitmodules_config(void)
196248 }
197249
198250 if (!gitmodules_is_unmerged )
199- git_config_from_file (submodule_config , gitmodules_path .buf , NULL );
251+ git_config_from_file (git_modules_config ,
252+ gitmodules_path .buf , NULL );
200253 strbuf_release (& gitmodules_path );
201254 }
202255}
@@ -207,7 +260,7 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1)
207260 unsigned char sha1 [20 ];
208261
209262 if (gitmodule_sha1_from_commit (commit_sha1 , sha1 , & rev )) {
210- git_config_from_blob_sha1 (submodule_config , rev .buf ,
263+ git_config_from_blob_sha1 (git_modules_config , rev .buf ,
211264 sha1 , NULL );
212265 }
213266 strbuf_release (& rev );
@@ -660,11 +713,6 @@ void set_config_fetch_recurse_submodules(int value)
660713 config_fetch_recurse_submodules = value ;
661714}
662715
663- void set_config_update_recurse_submodules (int value )
664- {
665- config_update_recurse_submodules = value ;
666- }
667-
668716int should_update_submodules (void )
669717{
670718 return config_update_recurse_submodules == RECURSE_SUBMODULES_ON ;
0 commit comments