]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: allow setting superprefix for init_submodule()
authorAtharva Raykar <raykar.ath@gmail.com>
Sat, 5 Mar 2022 00:13:57 +0000 (16:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 5 Mar 2022 00:39:12 +0000 (16:39 -0800)
We allow callers of the `init_submodule()` function to optionally
override the superprefix from the environment.

We need to enable this option because in our conversion of the update
command that will follow, the '--init' option will be handled through
this API. We will need to change the superprefix at that time to ensure
the display paths show correctly in the output messages.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Shourya Shukla <periperidip@gmail.com>
Signed-off-by: Atharva Raykar <raykar.ath@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c

index 52d4f47ffc78f533730a1d34ee08a58994d759bf..c6df64bf6a58b732765637e49708e7cf2ed379f0 100644 (file)
@@ -594,18 +594,22 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
 
 struct init_cb {
        const char *prefix;
+       const char *superprefix;
        unsigned int flags;
 };
 #define INIT_CB_INIT { 0 }
 
 static void init_submodule(const char *path, const char *prefix,
-                          unsigned int flags)
+                          const char *superprefix, unsigned int flags)
 {
        const struct submodule *sub;
        struct strbuf sb = STRBUF_INIT;
        char *upd = NULL, *url = NULL, *displaypath;
 
-       displaypath = get_submodule_displaypath(path, prefix);
+       /* try superprefix from the environment, if it is not passed explicitly */
+       if (!superprefix)
+               superprefix = get_super_prefix();
+       displaypath = do_get_submodule_displaypath(path, prefix, superprefix);
 
        sub = submodule_from_path(the_repository, null_oid(), path);
 
@@ -679,7 +683,7 @@ static void init_submodule(const char *path, const char *prefix,
 static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)
 {
        struct init_cb *info = cb_data;
-       init_submodule(list_item->name, info->prefix, info->flags);
+       init_submodule(list_item->name, info->prefix, info->superprefix, info->flags);
 }
 
 static int module_init(int argc, const char **argv, const char *prefix)