@@ -616,6 +616,9 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
616
616
int diff_files_result ;
617
617
struct strbuf buf = STRBUF_INIT ;
618
618
const char * git_dir ;
619
+ struct setup_revision_opt opt = {
620
+ .free_removed_argv_elements = 1 ,
621
+ };
619
622
620
623
if (!submodule_from_path (the_repository , null_oid (), path ))
621
624
die (_ ("no submodule mapping found in .gitmodules for path '%s'" ),
@@ -649,9 +652,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
649
652
650
653
repo_init_revisions (the_repository , & rev , NULL );
651
654
rev .abbrev = 0 ;
652
- diff_files_args .nr = setup_revisions (diff_files_args .nr ,
653
- diff_files_args .v ,
654
- & rev , NULL );
655
+ setup_revisions (diff_files_args .nr , diff_files_args .v , & rev , & opt );
655
656
diff_files_result = run_diff_files (& rev , 0 );
656
657
657
658
if (!diff_result_code (& rev .diffopt , diff_files_result )) {
@@ -1378,8 +1379,7 @@ static void deinit_submodule(const char *path, const char *prefix,
1378
1379
".git file by using absorbgitdirs." ),
1379
1380
displaypath );
1380
1381
1381
- absorb_git_dir_into_superproject (path ,
1382
- ABSORB_GITDIR_RECURSE_SUBMODULES );
1382
+ absorb_git_dir_into_superproject (path );
1383
1383
1384
1384
}
1385
1385
@@ -2643,9 +2643,6 @@ static int module_update(int argc, const char **argv, const char *prefix)
2643
2643
N_ ("traverse submodules recursively" )),
2644
2644
OPT_BOOL ('N' , "no-fetch" , & opt .nofetch ,
2645
2645
N_ ("don't fetch new objects from the remote site" )),
2646
- OPT_STRING (0 , "prefix" , & opt .prefix ,
2647
- N_ ("path" ),
2648
- N_ ("path into the working tree" )),
2649
2646
OPT_SET_INT (0 , "checkout" , & opt .update_default ,
2650
2647
N_ ("use the 'checkout' update strategy (default)" ),
2651
2648
SM_UPDATE_CHECKOUT ),
@@ -2701,6 +2698,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
2701
2698
}
2702
2699
2703
2700
opt .filter_options = & filter_options ;
2701
+ opt .prefix = prefix ;
2704
2702
2705
2703
if (opt .update_default )
2706
2704
opt .update_strategy .type = opt .update_default ;
@@ -2830,13 +2828,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2830
2828
int i ;
2831
2829
struct pathspec pathspec = { 0 };
2832
2830
struct module_list list = MODULE_LIST_INIT ;
2833
- unsigned flags = ABSORB_GITDIR_RECURSE_SUBMODULES ;
2834
2831
struct option embed_gitdir_options [] = {
2835
- OPT_STRING (0 , "prefix" , & prefix ,
2836
- N_ ("path" ),
2837
- N_ ("path into the working tree" )),
2838
- OPT_BIT (0 , "--recursive" , & flags , N_ ("recurse into submodules" ),
2839
- ABSORB_GITDIR_RECURSE_SUBMODULES ),
2840
2832
OPT_END ()
2841
2833
};
2842
2834
const char * const git_submodule_helper_usage [] = {
@@ -2852,7 +2844,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2852
2844
goto cleanup ;
2853
2845
2854
2846
for (i = 0 ; i < list .nr ; i ++ )
2855
- absorb_git_dir_into_superproject (list .entries [i ]-> name , flags );
2847
+ absorb_git_dir_into_superproject (list .entries [i ]-> name );
2856
2848
2857
2849
ret = 0 ;
2858
2850
cleanup :
@@ -2861,51 +2853,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2861
2853
return ret ;
2862
2854
}
2863
2855
2864
- static int module_config (int argc , const char * * argv , const char * prefix )
2865
- {
2866
- enum {
2867
- CHECK_WRITEABLE = 1 ,
2868
- DO_UNSET = 2
2869
- } command = 0 ;
2870
- struct option module_config_options [] = {
2871
- OPT_CMDMODE (0 , "check-writeable" , & command ,
2872
- N_ ("check if it is safe to write to the .gitmodules file" ),
2873
- CHECK_WRITEABLE ),
2874
- OPT_CMDMODE (0 , "unset" , & command ,
2875
- N_ ("unset the config in the .gitmodules file" ),
2876
- DO_UNSET ),
2877
- OPT_END ()
2878
- };
2879
- const char * const git_submodule_helper_usage [] = {
2880
- N_ ("git submodule--helper config <name> [<value>]" ),
2881
- N_ ("git submodule--helper config --unset <name>" ),
2882
- "git submodule--helper config --check-writeable" ,
2883
- NULL
2884
- };
2885
-
2886
- argc = parse_options (argc , argv , prefix , module_config_options ,
2887
- git_submodule_helper_usage , PARSE_OPT_KEEP_ARGV0 );
2888
-
2889
- if (argc == 1 && command == CHECK_WRITEABLE )
2890
- return is_writing_gitmodules_ok () ? 0 : -1 ;
2891
-
2892
- /* Equivalent to ACTION_GET in builtin/config.c */
2893
- if (argc == 2 && command != DO_UNSET )
2894
- return print_config_from_gitmodules (the_repository , argv [1 ]);
2895
-
2896
- /* Equivalent to ACTION_SET in builtin/config.c */
2897
- if (argc == 3 || (argc == 2 && command == DO_UNSET )) {
2898
- const char * value = (argc == 3 ) ? argv [2 ] : NULL ;
2899
-
2900
- if (!is_writing_gitmodules_ok ())
2901
- die (_ ("please make sure that the .gitmodules file is in the working tree" ));
2902
-
2903
- return config_set_in_gitmodules_file_gently (argv [1 ], value );
2904
- }
2905
-
2906
- usage_with_options (git_submodule_helper_usage , module_config_options );
2907
- }
2908
-
2909
2856
static int module_set_url (int argc , const char * * argv , const char * prefix )
2910
2857
{
2911
2858
int quiet = 0 ;
@@ -3404,48 +3351,45 @@ static int module_add(int argc, const char **argv, const char *prefix)
3404
3351
return ret ;
3405
3352
}
3406
3353
3407
- #define SUPPORT_SUPER_PREFIX (1<<0)
3408
-
3409
- struct cmd_struct {
3410
- const char * cmd ;
3411
- int (* fn )(int , const char * * , const char * );
3412
- unsigned option ;
3413
- };
3414
-
3415
- static struct cmd_struct commands [] = {
3416
- {"clone" , module_clone , SUPPORT_SUPER_PREFIX },
3417
- {"add" , module_add , 0 },
3418
- {"update" , module_update , SUPPORT_SUPER_PREFIX },
3419
- {"foreach" , module_foreach , SUPPORT_SUPER_PREFIX },
3420
- {"init" , module_init , 0 },
3421
- {"status" , module_status , SUPPORT_SUPER_PREFIX },
3422
- {"sync" , module_sync , SUPPORT_SUPER_PREFIX },
3423
- {"deinit" , module_deinit , 0 },
3424
- {"summary" , module_summary , 0 },
3425
- {"push-check" , push_check , 0 },
3426
- {"absorbgitdirs" , absorb_git_dirs , SUPPORT_SUPER_PREFIX },
3427
- {"config" , module_config , 0 },
3428
- {"set-url" , module_set_url , 0 },
3429
- {"set-branch" , module_set_branch , 0 },
3430
- {"create-branch" , module_create_branch , 0 },
3431
- };
3432
-
3433
3354
int cmd_submodule__helper (int argc , const char * * argv , const char * prefix )
3434
3355
{
3435
- int i ;
3436
- if (argc < 2 || !strcmp (argv [1 ], "-h" ))
3437
- usage ("git submodule--helper <command>" );
3438
-
3439
- for (i = 0 ; i < ARRAY_SIZE (commands ); i ++ ) {
3440
- if (!strcmp (argv [1 ], commands [i ].cmd )) {
3441
- if (get_super_prefix () &&
3442
- !(commands [i ].option & SUPPORT_SUPER_PREFIX ))
3443
- die (_ ("%s doesn't support --super-prefix" ),
3444
- commands [i ].cmd );
3445
- return commands [i ].fn (argc - 1 , argv + 1 , prefix );
3446
- }
3447
- }
3356
+ const char * cmd = argv [0 ];
3357
+ const char * subcmd ;
3358
+ parse_opt_subcommand_fn * fn = NULL ;
3359
+ const char * const usage [] = {
3360
+ N_ ("git submodule--helper <command>" ),
3361
+ NULL
3362
+ };
3363
+ struct option options [] = {
3364
+ OPT_SUBCOMMAND ("clone" , & fn , module_clone ),
3365
+ OPT_SUBCOMMAND ("add" , & fn , module_add ),
3366
+ OPT_SUBCOMMAND ("update" , & fn , module_update ),
3367
+ OPT_SUBCOMMAND ("foreach" , & fn , module_foreach ),
3368
+ OPT_SUBCOMMAND ("init" , & fn , module_init ),
3369
+ OPT_SUBCOMMAND ("status" , & fn , module_status ),
3370
+ OPT_SUBCOMMAND ("sync" , & fn , module_sync ),
3371
+ OPT_SUBCOMMAND ("deinit" , & fn , module_deinit ),
3372
+ OPT_SUBCOMMAND ("summary" , & fn , module_summary ),
3373
+ OPT_SUBCOMMAND ("push-check" , & fn , push_check ),
3374
+ OPT_SUBCOMMAND ("absorbgitdirs" , & fn , absorb_git_dirs ),
3375
+ OPT_SUBCOMMAND ("set-url" , & fn , module_set_url ),
3376
+ OPT_SUBCOMMAND ("set-branch" , & fn , module_set_branch ),
3377
+ OPT_SUBCOMMAND ("create-branch" , & fn , module_create_branch ),
3378
+ OPT_END ()
3379
+ };
3380
+ argc = parse_options (argc , argv , prefix , options , usage , 0 );
3381
+ subcmd = argv [0 ];
3382
+
3383
+ if (strcmp (subcmd , "clone" ) && strcmp (subcmd , "update" ) &&
3384
+ strcmp (subcmd , "foreach" ) && strcmp (subcmd , "status" ) &&
3385
+ strcmp (subcmd , "sync" ) && strcmp (subcmd , "absorbgitdirs" ) &&
3386
+ get_super_prefix ())
3387
+ /*
3388
+ * xstrfmt() rather than "%s %s" to keep the translated
3389
+ * string identical to git.c's.
3390
+ */
3391
+ die (_ ("%s doesn't support --super-prefix" ),
3392
+ xstrfmt ("'%s %s'" , cmd , subcmd ));
3448
3393
3449
- die (_ ("'%s' is not a valid submodule--helper "
3450
- "subcommand" ), argv [1 ]);
3394
+ return fn (argc , argv , prefix );
3451
3395
}
0 commit comments