diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2017-03-26 09:42:27 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-03-27 10:23:39 -0700 |
commit | 126c9e05765330d29c973934598876cdea50b5df (patch) | |
tree | c5412d9d141e8e5e681d2bc2b348d878bd7307ad | |
parent | 9476c6ed3dcf89b045d567c153f50de9528dd0ba (diff) | |
download | git-126c9e05765330d29c973934598876cdea50b5df.tar.gz |
refs.c: flatten get_ref_store() a bit
This helps the future changes in this code. And because get_ref_store()
is destined to become get_submodule_ref_store(), the "get main store"
code path will be removed eventually. After this the patch to delete
that code will be cleaner.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | refs.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1462,22 +1462,25 @@ static struct ref_store *get_main_ref_store(void) struct ref_store *get_ref_store(const char *submodule) { + struct strbuf submodule_sb = STRBUF_INIT; struct ref_store *refs; + int ret; if (!submodule || !*submodule) { return get_main_ref_store(); - } else { - refs = lookup_submodule_ref_store(submodule); + } - if (!refs) { - struct strbuf submodule_sb = STRBUF_INIT; + refs = lookup_submodule_ref_store(submodule); + if (refs) + return refs; - strbuf_addstr(&submodule_sb, submodule); - if (is_nonbare_repository_dir(&submodule_sb)) - refs = ref_store_init(submodule); - strbuf_release(&submodule_sb); - } - } + strbuf_addstr(&submodule_sb, submodule); + ret = is_nonbare_repository_dir(&submodule_sb); + strbuf_release(&submodule_sb); + if (!ret) + return NULL; + + refs = ref_store_init(submodule); return refs; } |