@@ -1643,7 +1643,10 @@ struct module_clone_data {
1643
1643
unsigned int require_init : 1 ;
1644
1644
int single_branch ;
1645
1645
};
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
+ }
1647
1650
1648
1651
struct submodule_alternate_setup {
1649
1652
const char * submodule_name ;
@@ -1967,26 +1970,11 @@ struct update_clone_data {
1967
1970
};
1968
1971
1969
1972
struct 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 */
1971
1974
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 ;
1977
1975
1978
1976
/* 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 ;
1990
1978
1991
1979
/* to be consumed by git-submodule.sh */
1992
1980
struct update_clone_data * update_clone ;
@@ -1998,34 +1986,45 @@ struct submodule_update_clone {
1998
1986
/* failed clones to be retried again */
1999
1987
const struct cache_entry * * failed_clones ;
2000
1988
int failed_clones_nr , failed_clones_alloc ;
2001
-
2002
- int max_jobs ;
2003
- unsigned int init ;
2004
1989
};
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 }
2013
1991
2014
1992
struct update_data {
1993
+ const char * prefix ;
2015
1994
const char * recursive_prefix ;
2016
1995
const char * sm_path ;
2017
1996
const char * displaypath ;
1997
+ const char * update_default ;
2018
1998
struct object_id oid ;
2019
1999
struct object_id suboid ;
2000
+ struct string_list references ;
2020
2001
struct submodule_update_strategy update_strategy ;
2002
+ struct list_objects_filter_options * filter_options ;
2003
+ struct module_list list ;
2021
2004
int depth ;
2005
+ int max_jobs ;
2006
+ int single_branch ;
2007
+ int recommend_shallow ;
2008
+ unsigned int require_init ;
2022
2009
unsigned int force ;
2023
2010
unsigned int quiet ;
2024
2011
unsigned int nofetch ;
2025
2012
unsigned int just_cloned ;
2026
2013
unsigned int remote ;
2014
+ unsigned int progress ;
2015
+ unsigned int dissociate ;
2016
+ unsigned int init ;
2017
+ unsigned int warn_if_uninitialized ;
2027
2018
};
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
+ }
2029
2028
2030
2029
static void next_submodule_warn_missing (struct submodule_update_clone * suc ,
2031
2030
struct strbuf * out , const char * displaypath )
@@ -2034,7 +2033,7 @@ static void next_submodule_warn_missing(struct submodule_update_clone *suc,
2034
2033
* Only mention uninitialized submodules when their
2035
2034
* paths have been specified.
2036
2035
*/
2037
- if (suc -> warn_if_uninitialized ) {
2036
+ if (suc -> update_data -> warn_if_uninitialized ) {
2038
2037
strbuf_addf (out ,
2039
2038
_ ("Submodule path '%s' not initialized" ),
2040
2039
displaypath );
@@ -2066,8 +2065,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
2066
2065
int need_free_url = 0 ;
2067
2066
2068
2067
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 );
2071
2070
else
2072
2071
strbuf_addstr (& sb , ce -> name );
2073
2072
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,
2077
2076
2078
2077
sub = submodule_from_path (the_repository , null_oid (), ce -> name );
2079
2078
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 ,
2082
2081
ce -> name , & displaypath_sb );
2083
2082
else
2084
2083
displaypath = ce -> name ;
@@ -2096,8 +2095,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
2096
2095
}
2097
2096
free (key );
2098
2097
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
2101
2100
&& update_type == SM_UPDATE_NONE )) {
2102
2101
strbuf_addf (out , _ ("Skipping submodule '%s'" ), displaypath );
2103
2102
strbuf_addch (out , '\n' );
@@ -2141,33 +2140,33 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
2141
2140
child -> err = -1 ;
2142
2141
strvec_push (& child -> args , "submodule--helper" );
2143
2142
strvec_push (& child -> args , "clone" );
2144
- if (suc -> progress )
2143
+ if (suc -> update_data -> progress )
2145
2144
strvec_push (& child -> args , "--progress" );
2146
- if (suc -> quiet )
2145
+ if (suc -> update_data -> quiet )
2147
2146
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 )
2151
2150
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 )
2153
2154
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 )
2156
2157
strvec_push (& child -> args , "--require-init" );
2157
2158
strvec_pushl (& child -> args , "--path" , sub -> path , NULL );
2158
2159
strvec_pushl (& child -> args , "--name" , sub -> name , NULL );
2159
2160
strvec_pushl (& child -> args , "--url" , url , NULL );
2160
- if (suc -> references .nr ) {
2161
+ if (suc -> update_data -> references .nr ) {
2161
2162
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 )
2163
2164
strvec_pushl (& child -> args , "--reference" , item -> string , NULL );
2164
2165
}
2165
- if (suc -> dissociate )
2166
+ if (suc -> update_data -> dissociate )
2166
2167
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 ?
2171
2170
"--single-branch" :
2172
2171
"--no-single-branch" );
2173
2172
@@ -2189,8 +2188,8 @@ static int update_clone_get_next_task(struct child_process *child,
2189
2188
const struct cache_entry * ce ;
2190
2189
int index ;
2191
2190
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 ];
2194
2193
if (prepare_to_clone_next_submodule (ce , child , suc , err )) {
2195
2194
int * p = xmalloc (sizeof (* p ));
2196
2195
* p = suc -> current ;
@@ -2205,7 +2204,7 @@ static int update_clone_get_next_task(struct child_process *child,
2205
2204
* stragglers again, which we can imagine as an extension of the
2206
2205
* entry list.
2207
2206
*/
2208
- index = suc -> current - suc -> list .nr ;
2207
+ index = suc -> current - suc -> update_data -> list .nr ;
2209
2208
if (index < suc -> failed_clones_nr ) {
2210
2209
int * p ;
2211
2210
ce = suc -> failed_clones [index ];
@@ -2250,8 +2249,8 @@ static int update_clone_task_finished(int result,
2250
2249
if (!result )
2251
2250
return 0 ;
2252
2251
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 ];
2255
2254
strbuf_addf (err , _ ("Failed to clone '%s'. Retry scheduled" ),
2256
2255
ce -> name );
2257
2256
strbuf_addch (err , '\n' );
@@ -2261,7 +2260,7 @@ static int update_clone_task_finished(int result,
2261
2260
suc -> failed_clones [suc -> failed_clones_nr ++ ] = ce ;
2262
2261
return 0 ;
2263
2262
} else {
2264
- idx -= suc -> list .nr ;
2263
+ idx -= suc -> update_data -> list .nr ;
2265
2264
ce = suc -> failed_clones [idx ];
2266
2265
strbuf_addf (err , _ ("Failed to clone '%s' a second time, aborting" ),
2267
2266
ce -> name );
@@ -2468,13 +2467,15 @@ static void update_submodule(struct update_clone_data *ucd)
2468
2467
ucd -> sub -> path );
2469
2468
}
2470
2469
2471
- static int update_submodules (struct submodule_update_clone * suc )
2470
+ static int update_submodules (struct update_data * update_data )
2472
2471
{
2473
2472
int i ;
2473
+ struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT ;
2474
2474
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 ,
2476
2477
update_clone_start_failure ,
2477
- update_clone_task_finished , suc , "submodule" ,
2478
+ update_clone_task_finished , & suc , "submodule" ,
2478
2479
"parallel/update" );
2479
2480
2480
2481
/*
@@ -2485,41 +2486,40 @@ static int update_submodules(struct submodule_update_clone *suc)
2485
2486
* checkout involve more straightforward sequential I/O.
2486
2487
* - the listener can avoid doing any work if fetching failed.
2487
2488
*/
2488
- if (suc -> quickstop )
2489
+ if (suc . quickstop )
2489
2490
return 1 ;
2490
2491
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 ]);
2493
2494
2494
2495
return 0 ;
2495
2496
}
2496
2497
2497
2498
static int update_clone (int argc , const char * * argv , const char * prefix )
2498
2499
{
2499
- const char * update = NULL ;
2500
2500
struct pathspec pathspec ;
2501
- struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT ;
2501
+ struct update_data opt = UPDATE_DATA_INIT ;
2502
2502
struct list_objects_filter_options filter_options ;
2503
2503
int ret ;
2504
2504
2505
2505
struct option module_update_clone_options [] = {
2506
2506
OPT_BOOL (0 , "init" , & opt .init ,
2507
2507
N_ ("initialize uninitialized submodules before update" )),
2508
- OPT_STRING (0 , "prefix" , & prefix ,
2508
+ OPT_STRING (0 , "prefix" , & opt . prefix ,
2509
2509
N_ ("path" ),
2510
2510
N_ ("path into the working tree" )),
2511
2511
OPT_STRING (0 , "recursive-prefix" , & opt .recursive_prefix ,
2512
2512
N_ ("path" ),
2513
2513
N_ ("path into the working tree, across nested "
2514
2514
"submodule boundaries" )),
2515
- OPT_STRING (0 , "update" , & update ,
2515
+ OPT_STRING (0 , "update" , & opt . update_default ,
2516
2516
N_ ("string" ),
2517
2517
N_ ("rebase, merge, checkout or none" )),
2518
2518
OPT_STRING_LIST (0 , "reference" , & opt .references , N_ ("repo" ),
2519
2519
N_ ("reference repository" )),
2520
2520
OPT_BOOL (0 , "dissociate" , & opt .dissociate ,
2521
2521
N_ ("use --reference only while cloning" )),
2522
- OPT_STRING (0 , "depth" , & opt .depth , "<depth>" ,
2522
+ OPT_INTEGER (0 , "depth" , & opt .depth ,
2523
2523
N_ ("create a shallow clone truncated to the "
2524
2524
"specified number of revisions" )),
2525
2525
OPT_INTEGER ('j' , "jobs" , & opt .max_jobs ,
@@ -2546,7 +2546,6 @@ static int update_clone(int argc, const char **argv, const char *prefix)
2546
2546
" [--recursive] [--[no-]single-branch] [--] [<path>...]" ),
2547
2547
NULL
2548
2548
};
2549
- opt .prefix = prefix ;
2550
2549
2551
2550
update_clone_config_from_gitmodules (& opt .max_jobs );
2552
2551
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)
2569
2568
2570
2569
opt .filter_options = & filter_options ;
2571
2570
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 )
2574
2574
die (_ ("bad value for update parameter" ));
2575
2575
2576
2576
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)
2611
2611
2612
2612
static int run_update_procedure (int argc , const char * * argv , const char * prefix )
2613
2613
{
2614
- char * prefixed_path , * update = NULL ;
2614
+ char * prefixed_path ;
2615
2615
struct update_data update_data = UPDATE_DATA_INIT ;
2616
2616
2617
2617
struct option options [] = {
@@ -2627,7 +2627,7 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
2627
2627
OPT_STRING (0 , "prefix" , & prefix ,
2628
2628
N_ ("path" ),
2629
2629
N_ ("path into the working tree" )),
2630
- OPT_STRING (0 , "update" , & update ,
2630
+ OPT_STRING (0 , "update" , & update_data . update_default ,
2631
2631
N_ ("string" ),
2632
2632
N_ ("rebase, merge, checkout or none" )),
2633
2633
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)
2661
2661
update_data .displaypath = get_submodule_displaypath (prefixed_path , prefix );
2662
2662
2663
2663
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 ,
2665
2665
& update_data .update_strategy );
2666
2666
2667
2667
free (prefixed_path );
0 commit comments