]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: convert "foreach" to its own "--super-prefix"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 20 Dec 2022 12:39:52 +0000 (13:39 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Dec 2022 01:21:44 +0000 (10:21 +0900)
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>
builtin/submodule--helper.c

index b8b2bc776d1cf2d365a6f5d374d8244cfa0ad689..2a6ced13f6d40553ff82d013ecb27d0d8f189eb5 100644 (file)
@@ -278,6 +278,7 @@ struct foreach_cb {
        int argc;
        const char **argv;
        const char *prefix;
+       const char *super_prefix;
        int quiet;
        int recursive;
 };
@@ -294,7 +295,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
        char *displaypath;
 
        displaypath = get_submodule_displaypath(path, info->prefix,
-                                               get_super_prefix());
+                                               info->super_prefix);
 
        sub = submodule_from_path(the_repository, null_oid(), path);
 
@@ -364,10 +365,10 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
                cpr.dir = path;
                prepare_submodule_repo_env(&cpr.env);
 
-               strvec_pushl(&cpr.args, "--super-prefix", NULL);
-               strvec_pushf(&cpr.args, "%s/", displaypath);
                strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive",
                             NULL);
+               strvec_pushl(&cpr.args, "--super-prefix", NULL);
+               strvec_pushf(&cpr.args, "%s/", displaypath);
 
                if (info->quiet)
                        strvec_push(&cpr.args, "--quiet");
@@ -391,6 +392,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
        struct pathspec pathspec = { 0 };
        struct module_list list = MODULE_LIST_INIT;
        struct option module_foreach_options[] = {
+               OPT__SUPER_PREFIX(&info.super_prefix),
                OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")),
                OPT_BOOL(0, "recursive", &info.recursive,
                         N_("recurse into nested submodules")),
@@ -3390,8 +3392,8 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
        subcmd = argv[0];
 
        if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") &&
-           strcmp(subcmd, "foreach") && strcmp(subcmd, "status") &&
-           strcmp(subcmd, "sync") && get_super_prefix())
+           strcmp(subcmd, "status") && strcmp(subcmd, "sync") &&
+           get_super_prefix())
                /*
                 * xstrfmt() rather than "%s %s" to keep the translated
                 * string identical to git.c's.