submodule--helper: convert "foreach" to its own "--super-prefix"

As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper foreach" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git" itself. See that earlier commit for the rationale and background. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Dec 20, 2022 at 13:39 UTC 677c981260854f0acc1b7cd4cce85d46f1b76f06
1 file changed +7 -5
builtin/submodule--helper.c
+7 -5
@@ -278,6 +278,7 @@ struct foreach_cb {
278 int argc;
279 const char **argv;
280 const char *prefix;
281 + const char *super_prefix;
282 int quiet;
283 int recursive;
284 };
@@ -294,7 +295,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
295 char *displaypath;
296
297 displaypath = get_submodule_displaypath(path, info->prefix,
297 - get_super_prefix());
298 + info->super_prefix);
299
300 sub = submodule_from_path(the_repository, null_oid(), path);
301
@@ -364,10 +365,10 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
365 cpr.dir = path;
366 prepare_submodule_repo_env(&cpr.env);
367
367 - strvec_pushl(&cpr.args, "--super-prefix", NULL);
368 - strvec_pushf(&cpr.args, "%s/", displaypath);
368 strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive",
369 NULL);
370 + strvec_pushl(&cpr.args, "--super-prefix", NULL);
371 + strvec_pushf(&cpr.args, "%s/", displaypath);
372
373 if (info->quiet)
374 strvec_push(&cpr.args, "--quiet");
@@ -391,6 +392,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
392 struct pathspec pathspec = { 0 };
393 struct module_list list = MODULE_LIST_INIT;
394 struct option module_foreach_options[] = {
395 + OPT__SUPER_PREFIX(&info.super_prefix),
396 OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")),
397 OPT_BOOL(0, "recursive", &info.recursive,
398 N_("recurse into nested submodules")),
@@ -3390,8 +3392,8 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
3392 subcmd = argv[0];
3393
3394 if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") &&
3393 - strcmp(subcmd, "foreach") && strcmp(subcmd, "status") &&
3394 - strcmp(subcmd, "sync") && get_super_prefix())
3395 + strcmp(subcmd, "status") && strcmp(subcmd, "sync") &&
3396 + get_super_prefix())
3397 /*
3398 * xstrfmt() rather than "%s %s" to keep the translated
3399 * string identical to git.c's.