path.c: move some code out of strbuf_git_path_submodule()
refs is learning to avoid path rewriting that is done by strbuf_git_path_submodule(). Factor out this code so it could be reused by refs_* functions. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
077be78d7f
commit
bbbb7de7ac
31
submodule.c
31
submodule.c
@ -1596,3 +1596,34 @@ const char *get_superproject_working_tree(void)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
|
||||
{
|
||||
const struct submodule *sub;
|
||||
const char *git_dir;
|
||||
int ret = 0;
|
||||
|
||||
strbuf_reset(buf);
|
||||
strbuf_addstr(buf, submodule);
|
||||
strbuf_complete(buf, '/');
|
||||
strbuf_addstr(buf, ".git");
|
||||
|
||||
git_dir = read_gitfile(buf->buf);
|
||||
if (git_dir) {
|
||||
strbuf_reset(buf);
|
||||
strbuf_addstr(buf, git_dir);
|
||||
}
|
||||
if (!is_git_directory(buf->buf)) {
|
||||
gitmodules_config();
|
||||
sub = submodule_from_path(null_sha1, submodule);
|
||||
if (!sub) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
strbuf_reset(buf);
|
||||
strbuf_git_path(buf, "%s/%s", "modules", sub->name);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user