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>

Nguyễn Thái Ngọc Duy committed Mar 26, 2017 at 09:42 UTC 126c9e05765330d29c973934598876cdea50b5df
1 file changed +13 -10
refs.c
+13 -10
@@ -1462,22 +1462,25 @@ static struct ref_store *get_main_ref_store(void)
1462
1463 struct ref_store *get_ref_store(const char *submodule)
1464 {
1465 + struct strbuf submodule_sb = STRBUF_INIT;
1466 struct ref_store *refs;
1467 + int ret;
1468
1469 if (!submodule || !*submodule) {
1470 return get_main_ref_store();
1469 - } else {
1470 - refs = lookup_submodule_ref_store(submodule);
1471 + }
1472
1472 - if (!refs) {
1473 - struct strbuf submodule_sb = STRBUF_INIT;
1473 + refs = lookup_submodule_ref_store(submodule);
1474 + if (refs)
1475 + return refs;
1476
1475 - strbuf_addstr(&submodule_sb, submodule);
1476 - if (is_nonbare_repository_dir(&submodule_sb))
1477 - refs = ref_store_init(submodule);
1478 - strbuf_release(&submodule_sb);
1479 - }
1480 - }
1477 + strbuf_addstr(&submodule_sb, submodule);
1478 + ret = is_nonbare_repository_dir(&submodule_sb);
1479 + strbuf_release(&submodule_sb);
1480 + if (!ret)
1481 + return NULL;
1482 +
1483 + refs = ref_store_init(submodule);
1484 return refs;
1485 }
1486