2121#include "object-store.h"
2222#include "advice.h"
2323#include "branch.h"
24+ #include "list-objects-filter-options.h"
2425
2526#define OPT_QUIET (1 << 0)
2627#define OPT_CACHED (1 << 1)
@@ -1631,6 +1632,7 @@ struct module_clone_data {
16311632 const char * name ;
16321633 const char * url ;
16331634 const char * depth ;
1635+ struct list_objects_filter_options * filter_options ;
16341636 struct string_list reference ;
16351637 unsigned int quiet : 1 ;
16361638 unsigned int progress : 1 ;
@@ -1797,6 +1799,10 @@ static int clone_submodule(struct module_clone_data *clone_data)
17971799 strvec_push (& cp .args , "--dissociate" );
17981800 if (sm_gitdir && * sm_gitdir )
17991801 strvec_pushl (& cp .args , "--separate-git-dir" , sm_gitdir , NULL );
1802+ if (clone_data -> filter_options && clone_data -> filter_options -> choice )
1803+ strvec_pushf (& cp .args , "--filter=%s" ,
1804+ expand_list_objects_filter_spec (
1805+ clone_data -> filter_options ));
18001806 if (clone_data -> single_branch >= 0 )
18011807 strvec_push (& cp .args , clone_data -> single_branch ?
18021808 "--single-branch" :
@@ -1853,6 +1859,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18531859{
18541860 int dissociate = 0 , quiet = 0 , progress = 0 , require_init = 0 ;
18551861 struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT ;
1862+ struct list_objects_filter_options filter_options ;
18561863
18571864 struct option module_clone_options [] = {
18581865 OPT_STRING (0 , "prefix" , & clone_data .prefix ,
@@ -1882,30 +1889,34 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18821889 N_ ("disallow cloning into non-empty directory" )),
18831890 OPT_BOOL (0 , "single-branch" , & clone_data .single_branch ,
18841891 N_ ("clone only one branch, HEAD or --branch" )),
1892+ OPT_PARSE_LIST_OBJECTS_FILTER (& filter_options ),
18851893 OPT_END ()
18861894 };
18871895
18881896 const char * const git_submodule_helper_usage [] = {
18891897 N_ ("git submodule--helper clone [--prefix=<path>] [--quiet] "
18901898 "[--reference <repository>] [--name <name>] [--depth <depth>] "
1891- "[--single-branch] "
1899+ "[--single-branch] [--filter <filter-spec>] "
18921900 "--url <url> --path <path>" ),
18931901 NULL
18941902 };
18951903
1904+ memset (& filter_options , 0 , sizeof (filter_options ));
18961905 argc = parse_options (argc , argv , prefix , module_clone_options ,
18971906 git_submodule_helper_usage , 0 );
18981907
18991908 clone_data .dissociate = !!dissociate ;
19001909 clone_data .quiet = !!quiet ;
19011910 clone_data .progress = !!progress ;
19021911 clone_data .require_init = !!require_init ;
1912+ clone_data .filter_options = & filter_options ;
19031913
19041914 if (argc || !clone_data .url || !clone_data .path || !* (clone_data .path ))
19051915 usage_with_options (git_submodule_helper_usage ,
19061916 module_clone_options );
19071917
19081918 clone_submodule (& clone_data );
1919+ list_objects_filter_release (& filter_options );
19091920 return 0 ;
19101921}
19111922
@@ -1995,6 +2006,7 @@ struct submodule_update_clone {
19952006 const char * recursive_prefix ;
19962007 const char * prefix ;
19972008 int single_branch ;
2009+ struct list_objects_filter_options * filter_options ;
19982010
19992011 /* to be consumed by git-submodule.sh */
20002012 struct update_clone_data * update_clone ;
@@ -2155,6 +2167,9 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
21552167 strvec_pushl (& child -> args , "--prefix" , suc -> prefix , NULL );
21562168 if (suc -> recommend_shallow && sub -> recommend_shallow == 1 )
21572169 strvec_push (& child -> args , "--depth=1" );
2170+ if (suc -> filter_options && suc -> filter_options -> choice )
2171+ strvec_pushf (& child -> args , "--filter=%s" ,
2172+ expand_list_objects_filter_spec (suc -> filter_options ));
21582173 if (suc -> require_init )
21592174 strvec_push (& child -> args , "--require-init" );
21602175 strvec_pushl (& child -> args , "--path" , sub -> path , NULL );
@@ -2499,6 +2514,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
24992514 const char * update = NULL ;
25002515 struct pathspec pathspec ;
25012516 struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT ;
2517+ struct list_objects_filter_options filter_options ;
2518+ int ret ;
25022519
25032520 struct option module_update_clone_options [] = {
25042521 OPT_STRING (0 , "prefix" , & prefix ,
@@ -2529,6 +2546,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
25292546 N_ ("disallow cloning into non-empty directory" )),
25302547 OPT_BOOL (0 , "single-branch" , & suc .single_branch ,
25312548 N_ ("clone only one branch, HEAD or --branch" )),
2549+ OPT_PARSE_LIST_OBJECTS_FILTER (& filter_options ),
25322550 OPT_END ()
25332551 };
25342552
@@ -2541,20 +2559,26 @@ static int update_clone(int argc, const char **argv, const char *prefix)
25412559 update_clone_config_from_gitmodules (& suc .max_jobs );
25422560 git_config (git_update_clone_config , & suc .max_jobs );
25432561
2562+ memset (& filter_options , 0 , sizeof (filter_options ));
25442563 argc = parse_options (argc , argv , prefix , module_update_clone_options ,
25452564 git_submodule_helper_usage , 0 );
2565+ suc .filter_options = & filter_options ;
25462566
25472567 if (update )
25482568 if (parse_submodule_update_strategy (update , & suc .update ) < 0 )
25492569 die (_ ("bad value for update parameter" ));
25502570
2551- if (module_list_compute (argc , argv , prefix , & pathspec , & suc .list ) < 0 )
2571+ if (module_list_compute (argc , argv , prefix , & pathspec , & suc .list ) < 0 ) {
2572+ list_objects_filter_release (& filter_options );
25522573 return 1 ;
2574+ }
25532575
25542576 if (pathspec .nr )
25552577 suc .warn_if_uninitialized = 1 ;
25562578
2557- return update_submodules (& suc );
2579+ ret = update_submodules (& suc );
2580+ list_objects_filter_release (& filter_options );
2581+ return ret ;
25582582}
25592583
25602584static int run_update_procedure (int argc , const char * * argv , const char * prefix )
0 commit comments