mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
93a8cfaf3c
commit
f9467895d8
11
submodule.c
11
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:
|
||||
|
||||
Reference in New Issue
Block a user