Skip to content

Commit 29a5e9e

Browse files
chooglengitster
authored andcommitted
submodule--helper update-clone: learn --init
Teach "git submodule--helper update-clone" the --init flag and remove the corresponding shell code. When the `--init` flag is passed to the subcommand, we do not spawn a new subprocess and call `submodule--helper init` on the submodule paths, because the Git machinery is not able to pick up the configuration changes introduced by that init call. So we instead run the `init_submodule_cb()` callback over each submodule in the same process. [1] https://lore.kernel.org/git/CAP8UFD0NCQ5w_3GtT_xHr35i7h8BuLX4UcHNY6VHPGREmDVObA@mail.gmail.com/ Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ce52cb commit 29a5e9e

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

builtin/submodule--helper.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,7 @@ struct submodule_update_clone {
20002000
int failed_clones_nr, failed_clones_alloc;
20012001

20022002
int max_jobs;
2003+
unsigned int init;
20032004
};
20042005
#define SUBMODULE_UPDATE_CLONE_INIT { \
20052006
.list = MODULE_LIST_INIT, \
@@ -2509,6 +2510,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
25092510
int ret;
25102511

25112512
struct option module_update_clone_options[] = {
2513+
OPT_BOOL(0, "init", &suc.init,
2514+
N_("initialize uninitialized submodules before update")),
25122515
OPT_STRING(0, "prefix", &prefix,
25132516
N_("path"),
25142517
N_("path into the working tree")),
@@ -2567,6 +2570,29 @@ static int update_clone(int argc, const char **argv, const char *prefix)
25672570
if (pathspec.nr)
25682571
suc.warn_if_uninitialized = 1;
25692572

2573+
if (suc.init) {
2574+
struct module_list list = MODULE_LIST_INIT;
2575+
struct init_cb info = INIT_CB_INIT;
2576+
2577+
if (module_list_compute(argc, argv, suc.prefix,
2578+
&pathspec, &list) < 0)
2579+
return 1;
2580+
2581+
/*
2582+
* If there are no path args and submodule.active is set then,
2583+
* by default, only initialize 'active' modules.
2584+
*/
2585+
if (!argc && git_config_get_value_multi("submodule.active"))
2586+
module_list_active(&list);
2587+
2588+
info.prefix = suc.prefix;
2589+
info.superprefix = suc.recursive_prefix;
2590+
if (suc.quiet)
2591+
info.flags |= OPT_QUIET;
2592+
2593+
for_each_listed_submodule(&list, init_submodule_cb, &info);
2594+
}
2595+
25702596
ret = update_submodules(&suc);
25712597
list_objects_filter_release(&filter_options);
25722598
return ret;

git-submodule.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,11 @@ cmd_update()
361361
usage
362362
fi
363363

364-
if test -n "$init"
365-
then
366-
cmd_init "--" "$@" || return
367-
fi
368-
369364
{
370-
git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
365+
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update-clone \
366+
${GIT_QUIET:+--quiet} \
371367
${progress:+"--progress"} \
368+
${init:+--init} \
372369
${wt_prefix:+--prefix "$wt_prefix"} \
373370
${prefix:+--recursive-prefix "$prefix"} \
374371
${update:+--update "$update"} \

0 commit comments

Comments
 (0)