submodule.c & submodule--helper: pass along "super_prefix" param

Start passing the "super_prefix" along as a parameter to get_submodule_displaypath() and absorb_git_dir_into_superproject(), rather than get the value directly as a global. This is in preparation for subsequent commits, where we'll gradually phase out get_super_prefix() for an alternative way of getting the "super_prefix". Most of the users of this get a get_super_prefix() value, either directly or by indirection. The exceptions are: - builtin/rm.c: Doesn't declare SUPPORT_SUPER_PREFIX, so we'd have died if this was provided, so it's safe to pass "NULL". - deinit_submodule(): The "deinit_submodule()" function has never been able to use the "git -super-prefix". It will call "absorb_git_dir_into_superproject()", but it will only do so from the top-level project. If "absorbgitdirs" recurses will use the "path" passed to "absorb_git_dir_into_superproject()" in "deinit_submodule()" as its starting "--super-prefix". So we can safely remove the get_super_prefix() call here, and pass NULL instead. 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 f0a5e5ad57ae729d9971bdb6bdaa82c1d85bd062
4 files changed +34 -21
builtin/rm.c
+1 -1
@@ -86,7 +86,7 @@ static void submodules_absorb_gitdir_if_needed(void)
86 continue;
87
88 if (!submodule_uses_gitfile(name))
89 - absorb_git_dir_into_superproject(name);
89 + absorb_git_dir_into_superproject(name, NULL);
90 }
91 }
92
builtin/submodule--helper.c
+22 -13
@@ -113,10 +113,9 @@ static char *resolve_relative_url(const char *rel_url, const char *up_path, int
113 }
114
115 /* the result should be freed by the caller. */
116 -static char *get_submodule_displaypath(const char *path, const char *prefix)
116 +static char *get_submodule_displaypath(const char *path, const char *prefix,
117 + const char *super_prefix)
118 {
118 - const char *super_prefix = get_super_prefix();
119 -
119 if (prefix && super_prefix) {
120 BUG("cannot have prefix '%s' and superprefix '%s'",
121 prefix, super_prefix);
@@ -294,7 +293,8 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
293 struct child_process cp = CHILD_PROCESS_INIT;
294 char *displaypath;
295
297 - displaypath = get_submodule_displaypath(path, info->prefix);
296 + displaypath = get_submodule_displaypath(path, info->prefix,
297 + get_super_prefix());
298
299 sub = submodule_from_path(the_repository, null_oid(), path);
300
@@ -447,7 +447,8 @@ static void init_submodule(const char *path, const char *prefix,
447 const char *upd;
448 char *url = NULL, *displaypath;
449
450 - displaypath = get_submodule_displaypath(path, prefix);
450 + displaypath = get_submodule_displaypath(path, prefix,
451 + get_super_prefix());
452
453 sub = submodule_from_path(the_repository, null_oid(), path);
454
@@ -624,7 +625,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
625 die(_("no submodule mapping found in .gitmodules for path '%s'"),
626 path);
627
627 - displaypath = get_submodule_displaypath(path, prefix);
628 + displaypath = get_submodule_displaypath(path, prefix,
629 + get_super_prefix());
630
631 if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) {
632 print_status(flags, 'U', path, null_oid(), displaypath);
@@ -948,7 +950,8 @@ static void generate_submodule_summary(struct summary_cb *info,
950 dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7);
951 }
952
951 - displaypath = get_submodule_displaypath(p->sm_path, info->prefix);
953 + displaypath = get_submodule_displaypath(p->sm_path, info->prefix,
954 + get_super_prefix());
955
956 if (!missing_src && !missing_dst) {
957 struct child_process cp_rev_list = CHILD_PROCESS_INIT;
@@ -1239,7 +1242,8 @@ static void sync_submodule(const char *path, const char *prefix,
1242 super_config_url = xstrdup("");
1243 }
1244
1242 - displaypath = get_submodule_displaypath(path, prefix);
1245 + displaypath = get_submodule_displaypath(path, prefix,
1246 + get_super_prefix());
1247
1248 if (!(flags & OPT_QUIET))
1249 printf(_("Synchronizing submodule url for '%s'\n"),
@@ -1365,7 +1369,7 @@ static void deinit_submodule(const char *path, const char *prefix,
1369 if (!sub || !sub->name)
1370 goto cleanup;
1371
1368 - displaypath = get_submodule_displaypath(path, prefix);
1372 + displaypath = get_submodule_displaypath(path, prefix, NULL);
1373
1374 /* remove the submodule work tree (unless the user already did it) */
1375 if (is_directory(path)) {
@@ -1379,7 +1383,7 @@ static void deinit_submodule(const char *path, const char *prefix,
1383 ".git file by using absorbgitdirs."),
1384 displaypath);
1385
1382 - absorb_git_dir_into_superproject(path);
1386 + absorb_git_dir_into_superproject(path, NULL);
1387
1388 }
1389
@@ -1958,7 +1962,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1962 enum submodule_update_type update_type;
1963 char *key;
1964 const struct update_data *ud = suc->update_data;
1961 - char *displaypath = get_submodule_displaypath(ce->name, ud->prefix);
1965 + char *displaypath = get_submodule_displaypath(ce->name, ud->prefix,
1966 + get_super_prefix());
1967 struct strbuf sb = STRBUF_INIT;
1968 int needs_cloning = 0;
1969 int need_free_url = 0;
@@ -2608,7 +2613,8 @@ static int update_submodules(struct update_data *update_data)
2613 goto fail;
2614
2615 update_data->displaypath = get_submodule_displaypath(
2611 - update_data->sm_path, update_data->prefix);
2616 + update_data->sm_path, update_data->prefix,
2617 + get_super_prefix());
2618 code = update_submodule(update_data);
2619 FREE_AND_NULL(update_data->displaypath);
2620 fail:
@@ -2828,6 +2834,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2834 int i;
2835 struct pathspec pathspec = { 0 };
2836 struct module_list list = MODULE_LIST_INIT;
2837 + const char *super_prefix;
2838 struct option embed_gitdir_options[] = {
2839 OPT_END()
2840 };
@@ -2843,8 +2850,10 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2850 if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
2851 goto cleanup;
2852
2853 + super_prefix = get_super_prefix();
2854 for (i = 0; i < list.nr; i++)
2847 - absorb_git_dir_into_superproject(list.entries[i]->name);
2855 + absorb_git_dir_into_superproject(list.entries[i]->name,
2856 + super_prefix);
2857
2858 ret = 0;
2859 cleanup:
submodule.c
+9 -6
@@ -2145,7 +2145,8 @@ int submodule_move_head(const char *path,
2145 if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) {
2146 if (old_head) {
2147 if (!submodule_uses_gitfile(path))
2148 - absorb_git_dir_into_superproject(path);
2148 + absorb_git_dir_into_superproject(path,
2149 + get_super_prefix());
2150 } else {
2151 struct strbuf gitdir = STRBUF_INIT;
2152 submodule_name_to_gitdir(&gitdir, the_repository,
@@ -2315,7 +2316,8 @@ static void relocate_single_git_dir_into_superproject(const char *path)
2316 strbuf_release(&new_gitdir);
2317 }
2318
2318 -static void absorb_git_dir_into_superproject_recurse(const char *path)
2319 +static void absorb_git_dir_into_superproject_recurse(const char *path,
2320 + const char *super_prefix)
2321 {
2322
2323 struct child_process cp = CHILD_PROCESS_INIT;
@@ -2323,8 +2325,8 @@ static void absorb_git_dir_into_superproject_recurse(const char *path)
2325 cp.dir = path;
2326 cp.git_cmd = 1;
2327 cp.no_stdin = 1;
2326 - strvec_pushf(&cp.args, "--super-prefix=%s%s/",
2327 - get_super_prefix_or_empty(), path);
2328 + strvec_pushf(&cp.args, "--super-prefix=%s%s/", super_prefix ?
2329 + super_prefix : "", path);
2330 strvec_pushl(&cp.args, "submodule--helper",
2331 "absorbgitdirs", NULL);
2332 prepare_submodule_repo_env(&cp.env);
@@ -2337,7 +2339,8 @@ static void absorb_git_dir_into_superproject_recurse(const char *path)
2339 * having its git directory within the working tree to the git dir nested
2340 * in its superprojects git dir under modules/.
2341 */
2340 -void absorb_git_dir_into_superproject(const char *path)
2342 +void absorb_git_dir_into_superproject(const char *path,
2343 + const char *super_prefix)
2344 {
2345 int err_code;
2346 const char *sub_git_dir;
@@ -2386,7 +2389,7 @@ void absorb_git_dir_into_superproject(const char *path)
2389 }
2390 strbuf_release(&gitdir);
2391
2389 - absorb_git_dir_into_superproject_recurse(path);
2392 + absorb_git_dir_into_superproject_recurse(path, super_prefix);
2393 }
2394
2395 int get_superproject_working_tree(struct strbuf *buf)
submodule.h
+2 -1
@@ -164,7 +164,8 @@ void submodule_unset_core_worktree(const struct submodule *sub);
164 */
165 void prepare_submodule_repo_env(struct strvec *env);
166
167 -void absorb_git_dir_into_superproject(const char *path);
167 +void absorb_git_dir_into_superproject(const char *path,
168 + const char *super_prefix);
169
170 /*
171 * Return the absolute path of the working tree of the superproject, which this