Skip to content

Commit f946789

Browse files
pks-tgitster
authored andcommitted
submodule: refactor submodule_to_gitdir() to accept a repo
The `submodule_to_gitdir()` function implicitly uses `the_repository` to resolve submodule paths. Refactor the function to instead accept a repo as parameter to remove the dependency on global state. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 93a8cfa commit f946789

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

builtin/submodule--helper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ static void sync_submodule(const char *path, const char *prefix,
13011301
remote_key = xstrfmt("remote.%s.url", default_remote);
13021302
free(default_remote);
13031303

1304-
submodule_to_gitdir(&sb, path);
1304+
submodule_to_gitdir(the_repository, &sb, path);
13051305
strbuf_addstr(&sb, "/config");
13061306

13071307
if (git_config_set_in_file_gently(sb.buf, remote_key, NULL, sub_origin_url))

path.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static int do_submodule_path(struct strbuf *buf, const char *path,
567567
struct strbuf git_submodule_dir = STRBUF_INIT;
568568
int ret;
569569

570-
ret = submodule_to_gitdir(&git_submodule_dir, path);
570+
ret = submodule_to_gitdir(the_repository, &git_submodule_dir, path);
571571
if (ret)
572572
goto cleanup;
573573

refs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
21462146
if (!is_nonbare_repository_dir(&submodule_sb))
21472147
goto done;
21482148

2149-
if (submodule_to_gitdir(&submodule_sb, submodule))
2149+
if (submodule_to_gitdir(repo, &submodule_sb, submodule))
21502150
goto done;
21512151

21522152
subrepo = xmalloc(sizeof(*subrepo));

submodule.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ static struct repository *open_submodule(const char *path)
536536
struct strbuf sb = STRBUF_INIT;
537537
struct repository *out = xmalloc(sizeof(*out));
538538

539-
if (submodule_to_gitdir(&sb, path) || repo_init(out, sb.buf, NULL)) {
539+
if (submodule_to_gitdir(the_repository, &sb, path) ||
540+
repo_init(out, sb.buf, NULL)) {
540541
strbuf_release(&sb);
541542
free(out);
542543
return NULL;
@@ -2572,7 +2573,8 @@ int get_superproject_working_tree(struct strbuf *buf)
25722573
* Put the gitdir for a submodule (given relative to the main
25732574
* repository worktree) into `buf`, or return -1 on error.
25742575
*/
2575-
int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
2576+
int submodule_to_gitdir(struct repository *repo,
2577+
struct strbuf *buf, const char *submodule)
25762578
{
25772579
const struct submodule *sub;
25782580
const char *git_dir;
@@ -2592,14 +2594,13 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
25922594
strbuf_addstr(buf, git_dir);
25932595
}
25942596
if (!is_git_directory(buf->buf)) {
2595-
sub = submodule_from_path(the_repository, null_oid(),
2596-
submodule);
2597+
sub = submodule_from_path(repo, null_oid(), submodule);
25972598
if (!sub) {
25982599
ret = -1;
25992600
goto cleanup;
26002601
}
26012602
strbuf_reset(buf);
2602-
submodule_name_to_gitdir(buf, the_repository, sub->name);
2603+
submodule_name_to_gitdir(buf, repo, sub->name);
26032604
}
26042605

26052606
cleanup:

submodule.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ int push_unpushed_submodules(struct repository *r,
136136
* path of that submodule in 'buf'. Return -1 on error or when the
137137
* submodule is not initialized.
138138
*/
139-
int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
139+
int submodule_to_gitdir(struct repository *repo,
140+
struct strbuf *buf, const char *submodule);
140141

141142
/*
142143
* Given a submodule name, create a path to where the submodule's gitdir lives

0 commit comments

Comments
 (0)