diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2021-09-09 11:47:28 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-09-09 14:09:30 -0700 |
commit | 8eb8dcf94643ca6e7c3f040f3e0bf96e11c7ae47 (patch) | |
tree | f7e2ee9926bed0f5382f492687ca830a599c993c /repository.c | |
parent | submodule: remove unnecessary unabsorbed fallback (diff) | |
download | tgif-8eb8dcf94643ca6e7c3f040f3e0bf96e11c7ae47.tar.xz |
repository: support unabsorbed in repo_submodule_init
In preparation for a subsequent commit that migrates code using
add_submodule_odb() to repo_submodule_init(), teach
repo_submodule_init() to support submodules with unabsorbed gitdirs.
(See the documentation for "git submodule absorbgitdirs" for more
information about absorbed and unabsorbed gitdirs.)
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'repository.c')
-rw-r--r-- | repository.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/repository.c b/repository.c index b2bf44c6fa..e4a1afb0ac 100644 --- a/repository.c +++ b/repository.c @@ -190,19 +190,15 @@ error: int repo_submodule_init(struct repository *subrepo, struct repository *superproject, - const struct submodule *sub) + const char *path, + const struct object_id *treeish_name) { struct strbuf gitdir = STRBUF_INIT; struct strbuf worktree = STRBUF_INIT; int ret = 0; - if (!sub) { - ret = -1; - goto out; - } - - strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", sub->path); - strbuf_repo_worktree_path(&worktree, superproject, "%s", sub->path); + strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path); + strbuf_repo_worktree_path(&worktree, superproject, "%s", path); if (repo_init(subrepo, gitdir.buf, worktree.buf)) { /* @@ -212,6 +208,13 @@ int repo_submodule_init(struct repository *subrepo, * in the superproject's 'modules' directory. In this case the * submodule would not have a worktree. */ + const struct submodule *sub = + submodule_from_path(superproject, treeish_name, path); + if (!sub) { + ret = -1; + goto out; + } + strbuf_reset(&gitdir); strbuf_repo_git_path(&gitdir, superproject, "modules/%s", sub->name); @@ -225,7 +228,7 @@ int repo_submodule_init(struct repository *subrepo, subrepo->submodule_prefix = xstrfmt("%s%s/", superproject->submodule_prefix ? superproject->submodule_prefix : - "", sub->path); + "", path); out: strbuf_release(&gitdir); |