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 <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Mar 4, 2022 at 16:13 UTC
29a5e9e1ffeadb0555fdd2f366f1cb7259462ab9
2 files changed
+29
-6
builtin/submodule--helper.c
+26
@@ -2000,6 +2000,7 @@ struct submodule_update_clone {
2000
int failed_clones_nr, failed_clones_alloc;
2001
2002
int max_jobs;
2003
+ unsigned int init;
2004
};
2005
#define SUBMODULE_UPDATE_CLONE_INIT { \
2006
.list = MODULE_LIST_INIT, \
@@ -2509,6 +2510,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
2510
int ret;
2511
2512
struct option module_update_clone_options[] = {
2513
+ OPT_BOOL(0, "init", &suc.init,
2514
+ N_("initialize uninitialized submodules before update")),
2515
OPT_STRING(0, "prefix", &prefix,
2516
N_("path"),
2517
N_("path into the working tree")),
@@ -2567,6 +2570,29 @@ static int update_clone(int argc, const char **argv, const char *prefix)
2570
if (pathspec.nr)
2571
suc.warn_if_uninitialized = 1;
2572
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
+
2596
ret = update_submodules(&suc);
2597
list_objects_filter_release(&filter_options);
2598
return ret;
git-submodule.sh
+3
-6
@@ -361,14 +361,11 @@ cmd_update()
361
usage
362
fi
363
364
- if test -n "$init"
365
- then
366
- cmd_init "--" "$@" || return
367
- fi
368
-
364
{
370
- git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
365
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update-clone \
366
+ ${GIT_QUIET:+--quiet} \
367
${progress:+"--progress"} \
368
+ ${init:+--init} \
369
${wt_prefix:+--prefix "$wt_prefix"} \
370
${prefix:+--recursive-prefix "$prefix"} \
371
${update:+--update "$update"} \