@@ -1643,7 +1643,10 @@ struct module_clone_data {
16431643 unsigned int require_init : 1 ;
16441644 int single_branch ;
16451645};
1646- #define MODULE_CLONE_DATA_INIT { .reference = STRING_LIST_INIT_NODUP, .single_branch = -1 }
1646+ #define MODULE_CLONE_DATA_INIT { \
1647+ .reference = STRING_LIST_INIT_NODUP, \
1648+ .single_branch = -1, \
1649+ }
16471650
16481651struct submodule_alternate_setup {
16491652 const char * submodule_name ;
@@ -1967,26 +1970,11 @@ struct update_clone_data {
19671970};
19681971
19691972struct submodule_update_clone {
1970- /* index into 'list', the list of submodules to look into for cloning */
1973+ /* index into 'update_data. list', the list of submodules to look into for cloning */
19711974 int current ;
1972- struct module_list list ;
1973- unsigned warn_if_uninitialized : 1 ;
1974-
1975- /* update parameter passed via commandline */
1976- struct submodule_update_strategy update ;
19771975
19781976 /* configuration parameters which are passed on to the children */
1979- int progress ;
1980- int quiet ;
1981- int recommend_shallow ;
1982- struct string_list references ;
1983- int dissociate ;
1984- unsigned require_init ;
1985- const char * depth ;
1986- const char * recursive_prefix ;
1987- const char * prefix ;
1988- int single_branch ;
1989- struct list_objects_filter_options * filter_options ;
1977+ struct update_data * update_data ;
19901978
19911979 /* to be consumed by git-submodule.sh */
19921980 struct update_clone_data * update_clone ;
@@ -1998,34 +1986,45 @@ struct submodule_update_clone {
19981986 /* failed clones to be retried again */
19991987 const struct cache_entry * * failed_clones ;
20001988 int failed_clones_nr , failed_clones_alloc ;
2001-
2002- int max_jobs ;
2003- unsigned int init ;
20041989};
2005- #define SUBMODULE_UPDATE_CLONE_INIT { \
2006- .list = MODULE_LIST_INIT, \
2007- .update = SUBMODULE_UPDATE_STRATEGY_INIT, \
2008- .recommend_shallow = -1, \
2009- .references = STRING_LIST_INIT_DUP, \
2010- .single_branch = -1, \
2011- .max_jobs = 1, \
2012- }
1990+ #define SUBMODULE_UPDATE_CLONE_INIT { 0 }
20131991
20141992struct update_data {
1993+ const char * prefix ;
20151994 const char * recursive_prefix ;
20161995 const char * sm_path ;
20171996 const char * displaypath ;
1997+ const char * update_default ;
20181998 struct object_id oid ;
20191999 struct object_id suboid ;
2000+ struct string_list references ;
20202001 struct submodule_update_strategy update_strategy ;
2002+ struct list_objects_filter_options * filter_options ;
2003+ struct module_list list ;
20212004 int depth ;
2005+ int max_jobs ;
2006+ int single_branch ;
2007+ int recommend_shallow ;
2008+ unsigned int require_init ;
20222009 unsigned int force ;
20232010 unsigned int quiet ;
20242011 unsigned int nofetch ;
20252012 unsigned int just_cloned ;
20262013 unsigned int remote ;
2014+ unsigned int progress ;
2015+ unsigned int dissociate ;
2016+ unsigned int init ;
2017+ unsigned int warn_if_uninitialized ;
20272018};
2028- #define UPDATE_DATA_INIT { .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT }
2019+ #define UPDATE_DATA_INIT { \
2020+ .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT, \
2021+ .list = MODULE_LIST_INIT, \
2022+ .recommend_shallow = -1, \
2023+ .references = STRING_LIST_INIT_DUP, \
2024+ .single_branch = -1, \
2025+ .max_jobs = 1, \
2026+ .warn_if_uninitialized = 1, \
2027+ }
20292028
20302029static void next_submodule_warn_missing (struct submodule_update_clone * suc ,
20312030 struct strbuf * out , const char * displaypath )
@@ -2034,7 +2033,7 @@ static void next_submodule_warn_missing(struct submodule_update_clone *suc,
20342033 * Only mention uninitialized submodules when their
20352034 * paths have been specified.
20362035 */
2037- if (suc -> warn_if_uninitialized ) {
2036+ if (suc -> update_data -> warn_if_uninitialized ) {
20382037 strbuf_addf (out ,
20392038 _ ("Submodule path '%s' not initialized" ),
20402039 displaypath );
@@ -2066,8 +2065,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
20662065 int need_free_url = 0 ;
20672066
20682067 if (ce_stage (ce )) {
2069- if (suc -> recursive_prefix )
2070- strbuf_addf (& sb , "%s/%s" , suc -> recursive_prefix , ce -> name );
2068+ if (suc -> update_data -> recursive_prefix )
2069+ strbuf_addf (& sb , "%s/%s" , suc -> update_data -> recursive_prefix , ce -> name );
20712070 else
20722071 strbuf_addstr (& sb , ce -> name );
20732072 strbuf_addf (out , _ ("Skipping unmerged submodule %s" ), sb .buf );
@@ -2077,8 +2076,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
20772076
20782077 sub = submodule_from_path (the_repository , null_oid (), ce -> name );
20792078
2080- if (suc -> recursive_prefix )
2081- displaypath = relative_path (suc -> recursive_prefix ,
2079+ if (suc -> update_data -> recursive_prefix )
2080+ displaypath = relative_path (suc -> update_data -> recursive_prefix ,
20822081 ce -> name , & displaypath_sb );
20832082 else
20842083 displaypath = ce -> name ;
@@ -2096,8 +2095,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
20962095 }
20972096 free (key );
20982097
2099- if (suc -> update .type == SM_UPDATE_NONE
2100- || (suc -> update .type == SM_UPDATE_UNSPECIFIED
2098+ if (suc -> update_data -> update_strategy .type == SM_UPDATE_NONE
2099+ || (suc -> update_data -> update_strategy .type == SM_UPDATE_UNSPECIFIED
21012100 && update_type == SM_UPDATE_NONE )) {
21022101 strbuf_addf (out , _ ("Skipping submodule '%s'" ), displaypath );
21032102 strbuf_addch (out , '\n' );
@@ -2141,33 +2140,33 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
21412140 child -> err = -1 ;
21422141 strvec_push (& child -> args , "submodule--helper" );
21432142 strvec_push (& child -> args , "clone" );
2144- if (suc -> progress )
2143+ if (suc -> update_data -> progress )
21452144 strvec_push (& child -> args , "--progress" );
2146- if (suc -> quiet )
2145+ if (suc -> update_data -> quiet )
21472146 strvec_push (& child -> args , "--quiet" );
2148- if (suc -> prefix )
2149- strvec_pushl (& child -> args , "--prefix" , suc -> prefix , NULL );
2150- if (suc -> recommend_shallow && sub -> recommend_shallow == 1 )
2147+ if (suc -> update_data -> prefix )
2148+ strvec_pushl (& child -> args , "--prefix" , suc -> update_data -> prefix , NULL );
2149+ if (suc -> update_data -> recommend_shallow && sub -> recommend_shallow == 1 )
21512150 strvec_push (& child -> args , "--depth=1" );
2152- if (suc -> filter_options && suc -> filter_options -> choice )
2151+ else if (suc -> update_data -> depth )
2152+ strvec_pushf (& child -> args , "--depth=%d" , suc -> update_data -> depth );
2153+ if (suc -> update_data -> filter_options && suc -> update_data -> filter_options -> choice )
21532154 strvec_pushf (& child -> args , "--filter=%s" ,
2154- expand_list_objects_filter_spec (suc -> filter_options ));
2155- if (suc -> require_init )
2155+ expand_list_objects_filter_spec (suc -> update_data -> filter_options ));
2156+ if (suc -> update_data -> require_init )
21562157 strvec_push (& child -> args , "--require-init" );
21572158 strvec_pushl (& child -> args , "--path" , sub -> path , NULL );
21582159 strvec_pushl (& child -> args , "--name" , sub -> name , NULL );
21592160 strvec_pushl (& child -> args , "--url" , url , NULL );
2160- if (suc -> references .nr ) {
2161+ if (suc -> update_data -> references .nr ) {
21612162 struct string_list_item * item ;
2162- for_each_string_list_item (item , & suc -> references )
2163+ for_each_string_list_item (item , & suc -> update_data -> references )
21632164 strvec_pushl (& child -> args , "--reference" , item -> string , NULL );
21642165 }
2165- if (suc -> dissociate )
2166+ if (suc -> update_data -> dissociate )
21662167 strvec_push (& child -> args , "--dissociate" );
2167- if (suc -> depth )
2168- strvec_push (& child -> args , suc -> depth );
2169- if (suc -> single_branch >= 0 )
2170- strvec_push (& child -> args , suc -> single_branch ?
2168+ if (suc -> update_data -> single_branch >= 0 )
2169+ strvec_push (& child -> args , suc -> update_data -> single_branch ?
21712170 "--single-branch" :
21722171 "--no-single-branch" );
21732172
@@ -2189,8 +2188,8 @@ static int update_clone_get_next_task(struct child_process *child,
21892188 const struct cache_entry * ce ;
21902189 int index ;
21912190
2192- for (; suc -> current < suc -> list .nr ; suc -> current ++ ) {
2193- ce = suc -> list .entries [suc -> current ];
2191+ for (; suc -> current < suc -> update_data -> list .nr ; suc -> current ++ ) {
2192+ ce = suc -> update_data -> list .entries [suc -> current ];
21942193 if (prepare_to_clone_next_submodule (ce , child , suc , err )) {
21952194 int * p = xmalloc (sizeof (* p ));
21962195 * p = suc -> current ;
@@ -2205,7 +2204,7 @@ static int update_clone_get_next_task(struct child_process *child,
22052204 * stragglers again, which we can imagine as an extension of the
22062205 * entry list.
22072206 */
2208- index = suc -> current - suc -> list .nr ;
2207+ index = suc -> current - suc -> update_data -> list .nr ;
22092208 if (index < suc -> failed_clones_nr ) {
22102209 int * p ;
22112210 ce = suc -> failed_clones [index ];
@@ -2250,8 +2249,8 @@ static int update_clone_task_finished(int result,
22502249 if (!result )
22512250 return 0 ;
22522251
2253- if (idx < suc -> list .nr ) {
2254- ce = suc -> list .entries [idx ];
2252+ if (idx < suc -> update_data -> list .nr ) {
2253+ ce = suc -> update_data -> list .entries [idx ];
22552254 strbuf_addf (err , _ ("Failed to clone '%s'. Retry scheduled" ),
22562255 ce -> name );
22572256 strbuf_addch (err , '\n' );
@@ -2261,7 +2260,7 @@ static int update_clone_task_finished(int result,
22612260 suc -> failed_clones [suc -> failed_clones_nr ++ ] = ce ;
22622261 return 0 ;
22632262 } else {
2264- idx -= suc -> list .nr ;
2263+ idx -= suc -> update_data -> list .nr ;
22652264 ce = suc -> failed_clones [idx ];
22662265 strbuf_addf (err , _ ("Failed to clone '%s' a second time, aborting" ),
22672266 ce -> name );
@@ -2468,13 +2467,15 @@ static void update_submodule(struct update_clone_data *ucd)
24682467 ucd -> sub -> path );
24692468}
24702469
2471- static int update_submodules (struct submodule_update_clone * suc )
2470+ static int update_submodules (struct update_data * update_data )
24722471{
24732472 int i ;
2473+ struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT ;
24742474
2475- run_processes_parallel_tr2 (suc -> max_jobs , update_clone_get_next_task ,
2475+ suc .update_data = update_data ;
2476+ run_processes_parallel_tr2 (suc .update_data -> max_jobs , update_clone_get_next_task ,
24762477 update_clone_start_failure ,
2477- update_clone_task_finished , suc , "submodule" ,
2478+ update_clone_task_finished , & suc , "submodule" ,
24782479 "parallel/update" );
24792480
24802481 /*
@@ -2485,41 +2486,40 @@ static int update_submodules(struct submodule_update_clone *suc)
24852486 * checkout involve more straightforward sequential I/O.
24862487 * - the listener can avoid doing any work if fetching failed.
24872488 */
2488- if (suc -> quickstop )
2489+ if (suc . quickstop )
24892490 return 1 ;
24902491
2491- for (i = 0 ; i < suc -> update_clone_nr ; i ++ )
2492- update_submodule (& suc -> update_clone [i ]);
2492+ for (i = 0 ; i < suc . update_clone_nr ; i ++ )
2493+ update_submodule (& suc . update_clone [i ]);
24932494
24942495 return 0 ;
24952496}
24962497
24972498static int update_clone (int argc , const char * * argv , const char * prefix )
24982499{
2499- const char * update = NULL ;
25002500 struct pathspec pathspec ;
2501- struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT ;
2501+ struct update_data opt = UPDATE_DATA_INIT ;
25022502 struct list_objects_filter_options filter_options ;
25032503 int ret ;
25042504
25052505 struct option module_update_clone_options [] = {
25062506 OPT_BOOL (0 , "init" , & opt .init ,
25072507 N_ ("initialize uninitialized submodules before update" )),
2508- OPT_STRING (0 , "prefix" , & prefix ,
2508+ OPT_STRING (0 , "prefix" , & opt . prefix ,
25092509 N_ ("path" ),
25102510 N_ ("path into the working tree" )),
25112511 OPT_STRING (0 , "recursive-prefix" , & opt .recursive_prefix ,
25122512 N_ ("path" ),
25132513 N_ ("path into the working tree, across nested "
25142514 "submodule boundaries" )),
2515- OPT_STRING (0 , "update" , & update ,
2515+ OPT_STRING (0 , "update" , & opt . update_default ,
25162516 N_ ("string" ),
25172517 N_ ("rebase, merge, checkout or none" )),
25182518 OPT_STRING_LIST (0 , "reference" , & opt .references , N_ ("repo" ),
25192519 N_ ("reference repository" )),
25202520 OPT_BOOL (0 , "dissociate" , & opt .dissociate ,
25212521 N_ ("use --reference only while cloning" )),
2522- OPT_STRING (0 , "depth" , & opt .depth , "<depth>" ,
2522+ OPT_INTEGER (0 , "depth" , & opt .depth ,
25232523 N_ ("create a shallow clone truncated to the "
25242524 "specified number of revisions" )),
25252525 OPT_INTEGER ('j' , "jobs" , & opt .max_jobs ,
@@ -2546,7 +2546,6 @@ static int update_clone(int argc, const char **argv, const char *prefix)
25462546 " [--recursive] [--[no-]single-branch] [--] [<path>...]" ),
25472547 NULL
25482548 };
2549- opt .prefix = prefix ;
25502549
25512550 update_clone_config_from_gitmodules (& opt .max_jobs );
25522551 git_config (git_update_clone_config , & opt .max_jobs );
@@ -2569,8 +2568,9 @@ static int update_clone(int argc, const char **argv, const char *prefix)
25692568
25702569 opt .filter_options = & filter_options ;
25712570
2572- if (update )
2573- if (parse_submodule_update_strategy (update , & opt .update ) < 0 )
2571+ if (opt .update_default )
2572+ if (parse_submodule_update_strategy (opt .update_default ,
2573+ & opt .update_strategy ) < 0 )
25742574 die (_ ("bad value for update parameter" ));
25752575
25762576 if (module_list_compute (argc , argv , prefix , & pathspec , & opt .list ) < 0 ) {
@@ -2611,7 +2611,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
26112611
26122612static int run_update_procedure (int argc , const char * * argv , const char * prefix )
26132613{
2614- char * prefixed_path , * update = NULL ;
2614+ char * prefixed_path ;
26152615 struct update_data update_data = UPDATE_DATA_INIT ;
26162616
26172617 struct option options [] = {
@@ -2627,7 +2627,7 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
26272627 OPT_STRING (0 , "prefix" , & prefix ,
26282628 N_ ("path" ),
26292629 N_ ("path into the working tree" )),
2630- OPT_STRING (0 , "update" , & update ,
2630+ OPT_STRING (0 , "update" , & update_data . update_default ,
26312631 N_ ("string" ),
26322632 N_ ("rebase, merge, checkout or none" )),
26332633 OPT_STRING (0 , "recursive-prefix" , & update_data .recursive_prefix , N_ ("path" ),
@@ -2661,7 +2661,7 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
26612661 update_data .displaypath = get_submodule_displaypath (prefixed_path , prefix );
26622662
26632663 determine_submodule_update_strategy (the_repository , update_data .just_cloned ,
2664- update_data .sm_path , update ,
2664+ update_data .sm_path , update_data . update_default ,
26652665 & update_data .update_strategy );
26662666
26672667 free (prefixed_path );
0 commit comments