Skip to content

Commit f0a5e5a

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1806e commit f0a5e5a

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void submodules_absorb_gitdir_if_needed(void)
8686
continue;
8787

8888
if (!submodule_uses_gitfile(name))
89-
absorb_git_dir_into_superproject(name);
89+
absorb_git_dir_into_superproject(name, NULL);
9090
}
9191
}
9292

builtin/submodule--helper.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ static char *resolve_relative_url(const char *rel_url, const char *up_path, int
113113
}
114114

115115
/* 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)
117118
{
118-
const char *super_prefix = get_super_prefix();
119-
120119
if (prefix && super_prefix) {
121120
BUG("cannot have prefix '%s' and superprefix '%s'",
122121
prefix, super_prefix);
@@ -294,7 +293,8 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
294293
struct child_process cp = CHILD_PROCESS_INIT;
295294
char *displaypath;
296295

297-
displaypath = get_submodule_displaypath(path, info->prefix);
296+
displaypath = get_submodule_displaypath(path, info->prefix,
297+
get_super_prefix());
298298

299299
sub = submodule_from_path(the_repository, null_oid(), path);
300300

@@ -447,7 +447,8 @@ static void init_submodule(const char *path, const char *prefix,
447447
const char *upd;
448448
char *url = NULL, *displaypath;
449449

450-
displaypath = get_submodule_displaypath(path, prefix);
450+
displaypath = get_submodule_displaypath(path, prefix,
451+
get_super_prefix());
451452

452453
sub = submodule_from_path(the_repository, null_oid(), path);
453454

@@ -624,7 +625,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
624625
die(_("no submodule mapping found in .gitmodules for path '%s'"),
625626
path);
626627

627-
displaypath = get_submodule_displaypath(path, prefix);
628+
displaypath = get_submodule_displaypath(path, prefix,
629+
get_super_prefix());
628630

629631
if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) {
630632
print_status(flags, 'U', path, null_oid(), displaypath);
@@ -948,7 +950,8 @@ static void generate_submodule_summary(struct summary_cb *info,
948950
dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7);
949951
}
950952

951-
displaypath = get_submodule_displaypath(p->sm_path, info->prefix);
953+
displaypath = get_submodule_displaypath(p->sm_path, info->prefix,
954+
get_super_prefix());
952955

953956
if (!missing_src && !missing_dst) {
954957
struct child_process cp_rev_list = CHILD_PROCESS_INIT;
@@ -1239,7 +1242,8 @@ static void sync_submodule(const char *path, const char *prefix,
12391242
super_config_url = xstrdup("");
12401243
}
12411244

1242-
displaypath = get_submodule_displaypath(path, prefix);
1245+
displaypath = get_submodule_displaypath(path, prefix,
1246+
get_super_prefix());
12431247

12441248
if (!(flags & OPT_QUIET))
12451249
printf(_("Synchronizing submodule url for '%s'\n"),
@@ -1365,7 +1369,7 @@ static void deinit_submodule(const char *path, const char *prefix,
13651369
if (!sub || !sub->name)
13661370
goto cleanup;
13671371

1368-
displaypath = get_submodule_displaypath(path, prefix);
1372+
displaypath = get_submodule_displaypath(path, prefix, NULL);
13691373

13701374
/* remove the submodule work tree (unless the user already did it) */
13711375
if (is_directory(path)) {
@@ -1379,7 +1383,7 @@ static void deinit_submodule(const char *path, const char *prefix,
13791383
".git file by using absorbgitdirs."),
13801384
displaypath);
13811385

1382-
absorb_git_dir_into_superproject(path);
1386+
absorb_git_dir_into_superproject(path, NULL);
13831387

13841388
}
13851389

@@ -1958,7 +1962,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
19581962
enum submodule_update_type update_type;
19591963
char *key;
19601964
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());
19621967
struct strbuf sb = STRBUF_INIT;
19631968
int needs_cloning = 0;
19641969
int need_free_url = 0;
@@ -2608,7 +2613,8 @@ static int update_submodules(struct update_data *update_data)
26082613
goto fail;
26092614

26102615
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());
26122618
code = update_submodule(update_data);
26132619
FREE_AND_NULL(update_data->displaypath);
26142620
fail:
@@ -2828,6 +2834,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
28282834
int i;
28292835
struct pathspec pathspec = { 0 };
28302836
struct module_list list = MODULE_LIST_INIT;
2837+
const char *super_prefix;
28312838
struct option embed_gitdir_options[] = {
28322839
OPT_END()
28332840
};
@@ -2843,8 +2850,10 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
28432850
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
28442851
goto cleanup;
28452852

2853+
super_prefix = get_super_prefix();
28462854
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);
28482857

28492858
ret = 0;
28502859
cleanup:

submodule.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,8 @@ int submodule_move_head(const char *path,
21452145
if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) {
21462146
if (old_head) {
21472147
if (!submodule_uses_gitfile(path))
2148-
absorb_git_dir_into_superproject(path);
2148+
absorb_git_dir_into_superproject(path,
2149+
get_super_prefix());
21492150
} else {
21502151
struct strbuf gitdir = STRBUF_INIT;
21512152
submodule_name_to_gitdir(&gitdir, the_repository,
@@ -2315,16 +2316,17 @@ static void relocate_single_git_dir_into_superproject(const char *path)
23152316
strbuf_release(&new_gitdir);
23162317
}
23172318

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)
23192321
{
23202322

23212323
struct child_process cp = CHILD_PROCESS_INIT;
23222324

23232325
cp.dir = path;
23242326
cp.git_cmd = 1;
23252327
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);
23282330
strvec_pushl(&cp.args, "submodule--helper",
23292331
"absorbgitdirs", NULL);
23302332
prepare_submodule_repo_env(&cp.env);
@@ -2337,7 +2339,8 @@ static void absorb_git_dir_into_superproject_recurse(const char *path)
23372339
* having its git directory within the working tree to the git dir nested
23382340
* in its superprojects git dir under modules/.
23392341
*/
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)
23412344
{
23422345
int err_code;
23432346
const char *sub_git_dir;
@@ -2386,7 +2389,7 @@ void absorb_git_dir_into_superproject(const char *path)
23862389
}
23872390
strbuf_release(&gitdir);
23882391

2389-
absorb_git_dir_into_superproject_recurse(path);
2392+
absorb_git_dir_into_superproject_recurse(path, super_prefix);
23902393
}
23912394

23922395
int get_superproject_working_tree(struct strbuf *buf)

submodule.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ void submodule_unset_core_worktree(const struct submodule *sub);
164164
*/
165165
void prepare_submodule_repo_env(struct strvec *env);
166166

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);
168169

169170
/*
170171
* Return the absolute path of the working tree of the superproject, which this

0 commit comments

Comments
 (0)