aboutsummaryrefslogtreecommitdiffstats
path: root/submodule.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-02-07 12:03:29 +0100
committerJunio C Hamano <gitster@pobox.com>2025-02-07 09:59:21 -0800
commitf9467895d884908d5588fc920997b2e53dfb3302 (patch)
tree2326fe2a0b5fb00b447be12c777947c6f3839988 /submodule.c
parentpath: refactor `repo_worktree_path()` family of functions (diff)
downloadgit-f9467895d884908d5588fc920997b2e53dfb3302.tar.gz
git-f9467895d884908d5588fc920997b2e53dfb3302.zip
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/submodule.c b/submodule.c
index 211ead54a0..0530e8cf24 100644
--- a/submodule.c
+++ b/submodule.c
@@ -536,7 +536,8 @@ static struct repository *open_submodule(const char *path)
struct strbuf sb = STRBUF_INIT;
struct repository *out = xmalloc(sizeof(*out));
- if (submodule_to_gitdir(&sb, path) || repo_init(out, sb.buf, NULL)) {
+ if (submodule_to_gitdir(the_repository, &sb, path) ||
+ repo_init(out, sb.buf, NULL)) {
strbuf_release(&sb);
free(out);
return NULL;
@@ -2572,7 +2573,8 @@ int get_superproject_working_tree(struct strbuf *buf)
* Put the gitdir for a submodule (given relative to the main
* repository worktree) into `buf`, or return -1 on error.
*/
-int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
+int submodule_to_gitdir(struct repository *repo,
+ struct strbuf *buf, const char *submodule)
{
const struct submodule *sub;
const char *git_dir;
@@ -2592,14 +2594,13 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
strbuf_addstr(buf, git_dir);
}
if (!is_git_directory(buf->buf)) {
- sub = submodule_from_path(the_repository, null_oid(),
- submodule);
+ sub = submodule_from_path(repo, null_oid(), submodule);
if (!sub) {
ret = -1;
goto cleanup;
}
strbuf_reset(buf);
- submodule_name_to_gitdir(buf, the_repository, sub->name);
+ submodule_name_to_gitdir(buf, repo, sub->name);
}
cleanup: