refs.c: kill register_ref_store(), add register_submodule_ref_store()

This is the last function in this code (besides public API) that takes submodule argument and handles both main/submodule cases. Break it down, move main store registration in get_main_ref_store() and keep the rest in register_submodule_ref_store(). 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 378dc9103a6b36ecac5f63eb0d5a87f573081094
1 file changed +20 -25
refs.c
+20 -25
@@ -1411,29 +1411,6 @@ static struct ref_store *lookup_submodule_ref_store(const char *submodule)
1411 return entry ? entry->refs : NULL;
1412 }
1413
1414 -/*
1415 - * Register the specified ref_store to be the one that should be used
1416 - * for submodule (or the main repository if submodule is NULL). It is
1417 - * a fatal error to call this function twice for the same submodule.
1418 - */
1419 -static void register_ref_store(struct ref_store *refs, const char *submodule)
1420 -{
1421 - if (!submodule) {
1422 - if (main_ref_store)
1423 - die("BUG: main_ref_store initialized twice");
1424 -
1425 - main_ref_store = refs;
1426 - } else {
1427 - if (!submodule_ref_stores.tablesize)
1428 - hashmap_init(&submodule_ref_stores, submodule_hash_cmp, 0);
1429 -
1430 - if (hashmap_put(&submodule_ref_stores,
1431 - alloc_submodule_hash_entry(submodule, refs)))
1432 - die("BUG: ref_store for submodule '%s' initialized twice",
1433 - submodule);
1434 - }
1435 -}
1436 -
1414 /*
1415 * Create, record, and return a ref_store instance for the specified
1416 * submodule (or the main repository if submodule is NULL).
@@ -1448,7 +1425,6 @@ static struct ref_store *ref_store_init(const char *submodule)
1425 die("BUG: reference backend %s is unknown", be_name);
1426
1427 refs = be->init(submodule);
1451 - register_ref_store(refs, submodule);
1428 return refs;
1429 }
1430
@@ -1457,7 +1433,25 @@ static struct ref_store *get_main_ref_store(void)
1433 if (main_ref_store)
1434 return main_ref_store;
1435
1460 - return ref_store_init(NULL);
1436 + main_ref_store = ref_store_init(NULL);
1437 + return main_ref_store;
1438 +}
1439 +
1440 +/*
1441 + * Register the specified ref_store to be the one that should be used
1442 + * for submodule. It is a fatal error to call this function twice for
1443 + * the same submodule.
1444 + */
1445 +static void register_submodule_ref_store(struct ref_store *refs,
1446 + const char *submodule)
1447 +{
1448 + if (!submodule_ref_stores.tablesize)
1449 + hashmap_init(&submodule_ref_stores, submodule_hash_cmp, 0);
1450 +
1451 + if (hashmap_put(&submodule_ref_stores,
1452 + alloc_submodule_hash_entry(submodule, refs)))
1453 + die("BUG: ref_store for submodule '%s' initialized twice",
1454 + submodule);
1455 }
1456
1457 struct ref_store *get_ref_store(const char *submodule)
@@ -1481,6 +1475,7 @@ struct ref_store *get_ref_store(const char *submodule)
1475 return NULL;
1476
1477 refs = ref_store_init(submodule);
1478 + register_submodule_ref_store(refs, submodule);
1479 return refs;
1480 }
1481