refs: rename get_ref_store() to get_submodule_ref_store() and make it public

This function is intended to replace *_submodule() refs API. It provides a ref store for a specific submodule, which can be operated on by a new set of refs API. 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 18d0002d6ddc191454b6b4a99cdac65fc7ff9ece
3 files changed +19 -16
refs.c
+8 -4
@@ -1171,7 +1171,7 @@ int head_ref(each_ref_fn fn, void *cb_data)
1171 static int do_for_each_ref(const char *submodule, const char *prefix,
1172 each_ref_fn fn, int trim, int flags, void *cb_data)
1173 {
1174 - struct ref_store *refs = get_ref_store(submodule);
1174 + struct ref_store *refs = get_submodule_ref_store(submodule);
1175 struct ref_iterator *iter;
1176
1177 if (!refs)
@@ -1344,10 +1344,10 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
1344 /* We need to strip off one or more trailing slashes */
1345 char *stripped = xmemdupz(submodule, len);
1346
1347 - refs = get_ref_store(stripped);
1347 + refs = get_submodule_ref_store(stripped);
1348 free(stripped);
1349 } else {
1350 - refs = get_ref_store(submodule);
1350 + refs = get_submodule_ref_store(submodule);
1351 }
1352
1353 if (!refs)
@@ -1460,13 +1460,17 @@ static void register_submodule_ref_store(struct ref_store *refs,
1460 submodule);
1461 }
1462
1463 -struct ref_store *get_ref_store(const char *submodule)
1463 +struct ref_store *get_submodule_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 + /*
1471 + * FIXME: This case is ideally not allowed. But that
1472 + * can't happen until we clean up all the callers.
1473 + */
1474 return get_main_ref_store();
1475 }
1476
refs.h
+11
@@ -562,5 +562,16 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
562 int ref_storage_backend_exists(const char *name);
563
564 struct ref_store *get_main_ref_store(void);
565 +/*
566 + * Return the ref_store instance for the specified submodule. For the
567 + * main repository, use submodule==NULL; such a call cannot fail. For
568 + * a submodule, the submodule must exist and be a nonbare repository,
569 + * otherwise return NULL. If the requested reference store has not yet
570 + * been initialized, initialize it first.
571 + *
572 + * For backwards compatibility, submodule=="" is treated the same as
573 + * submodule==NULL.
574 + */
575 +struct ref_store *get_submodule_ref_store(const char *submodule);
576
577 #endif /* REFS_H */
refs/refs-internal.h
-12
@@ -646,18 +646,6 @@ struct ref_store {
646 void base_ref_store_init(struct ref_store *refs,
647 const struct ref_storage_be *be);
648
649 -/*
650 - * Return the ref_store instance for the specified submodule. For the
651 - * main repository, use submodule==NULL; such a call cannot fail. For
652 - * a submodule, the submodule must exist and be a nonbare repository,
653 - * otherwise return NULL. If the requested reference store has not yet
654 - * been initialized, initialize it first.
655 - *
656 - * For backwards compatibility, submodule=="" is treated the same as
657 - * submodule==NULL.
658 - */
659 -struct ref_store *get_ref_store(const char *submodule);
660 -
649 const char *resolve_ref_recursively(struct ref_store *refs,
650 const char *refname,
651 int resolve_flags,