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>
maint
Nguyễn Thái Ngọc Duy 2017-03-26 09:42:27 +07:00 committed by Junio C Hamano
parent 9476c6ed3d
commit 126c9e0576
1 changed files with 14 additions and 11 deletions

19
refs.c
View File

@ -1462,22 +1462,25 @@ static struct ref_store *get_main_ref_store(void)


struct ref_store *get_ref_store(const char *submodule) struct ref_store *get_ref_store(const char *submodule)
{ {
struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs; struct ref_store *refs;
int ret;


if (!submodule || !*submodule) { if (!submodule || !*submodule) {
return get_main_ref_store(); return get_main_ref_store();
} else { }
refs = lookup_submodule_ref_store(submodule);


if (!refs) { refs = lookup_submodule_ref_store(submodule);
struct strbuf submodule_sb = STRBUF_INIT; if (refs)
return refs;


strbuf_addstr(&submodule_sb, submodule); strbuf_addstr(&submodule_sb, submodule);
if (is_nonbare_repository_dir(&submodule_sb)) ret = is_nonbare_repository_dir(&submodule_sb);
refs = ref_store_init(submodule);
strbuf_release(&submodule_sb); strbuf_release(&submodule_sb);
} if (!ret)
} return NULL;

refs = ref_store_init(submodule);
return refs; return refs;
} }