diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-04-20 04:37:19 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-20 04:37:19 (GMT) |
commit | 5ab8f2261fa2b595abe433dd50be0f2aaec14aa0 (patch) | |
tree | a81428eb12d15f62e206a6414bda6cd78ae0a69a /submodule.c | |
parent | 52d77af463ce7be79f777ec7c8bf8adc632a0be2 (diff) | |
parent | adac8115a6e7f9841c48e4fe48b74e0ce652ef58 (diff) | |
download | git-5ab8f2261fa2b595abe433dd50be0f2aaec14aa0.zip git-5ab8f2261fa2b595abe433dd50be0f2aaec14aa0.tar.gz git-5ab8f2261fa2b595abe433dd50be0f2aaec14aa0.tar.bz2 |
Merge branch 'nd/files-backend-git-dir'
The "submodule" specific field in the ref_store structure is
replaced with a more generic "gitdir" that can later be used also
when dealing with ref_store that represents the set of refs visible
from the other worktrees.
* nd/files-backend-git-dir: (28 commits)
refs.h: add a note about sorting order of for_each_ref_*
t1406: new tests for submodule ref store
t1405: some basic tests on main ref store
t/helper: add test-ref-store to test ref-store functions
refs: delete pack_refs() in favor of refs_pack_refs()
files-backend: avoid ref api targeting main ref store
refs: new transaction related ref-store api
refs: add new ref-store api
refs: rename get_ref_store() to get_submodule_ref_store() and make it public
files-backend: replace submodule_allowed check in files_downcast()
refs: move submodule code out of files-backend.c
path.c: move some code out of strbuf_git_path_submodule()
refs.c: make get_main_ref_store() public and use it
refs.c: kill register_ref_store(), add register_submodule_ref_store()
refs.c: flatten get_ref_store() a bit
refs: rename lookup_ref_store() to lookup_submodule_ref_store()
refs.c: introduce get_main_ref_store()
files-backend: remove the use of git_path()
files-backend: add and use files_ref_path()
files-backend: add and use files_reflog_path()
...
Diffstat (limited to 'submodule.c')
-rw-r--r-- | submodule.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/submodule.c b/submodule.c index 620504d..5615d73 100644 --- a/submodule.c +++ b/submodule.c @@ -1866,3 +1866,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; +} |