refs: create a base class "ref_store" for files_ref_store

We want ref_stores to be polymorphic, so invent a base class of which files_ref_store is a derived class. For now there is exactly one ref_store for the main repository and one for any submodules whose references have been accessed. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Sep 4, 2016 at 18:08 UTC 00eebe351c4b4626a7b8e0b2dc4b7a172f3fd8d9
3 files changed +270 -78
refs.c
+93
@@ -1151,8 +1151,12 @@ int head_ref(each_ref_fn fn, void *cb_data)
1151 static int do_for_each_ref(const char *submodule, const char *prefix,
1152 each_ref_fn fn, int trim, int flags, void *cb_data)
1153 {
1154 + struct ref_store *refs = get_ref_store(submodule);
1155 struct ref_iterator *iter;
1156
1157 + if (!refs)
1158 + return 0;
1159 +
1160 iter = files_ref_iterator_begin(submodule, prefix, flags);
1161 iter = prefix_ref_iterator_begin(iter, prefix, trim);
1162
@@ -1284,3 +1288,92 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
1288 errno = ELOOP;
1289 return NULL;
1290 }
1291 +
1292 +/* A pointer to the ref_store for the main repository: */
1293 +static struct ref_store *main_ref_store;
1294 +
1295 +/* A linked list of ref_stores for submodules: */
1296 +static struct ref_store *submodule_ref_stores;
1297 +
1298 +void base_ref_store_init(struct ref_store *refs,
1299 + const struct ref_storage_be *be,
1300 + const char *submodule)
1301 +{
1302 + refs->be = be;
1303 + if (!submodule) {
1304 + if (main_ref_store)
1305 + die("BUG: main_ref_store initialized twice");
1306 +
1307 + refs->submodule = "";
1308 + refs->next = NULL;
1309 + main_ref_store = refs;
1310 + } else {
1311 + if (lookup_ref_store(submodule))
1312 + die("BUG: ref_store for submodule '%s' initialized twice",
1313 + submodule);
1314 +
1315 + refs->submodule = xstrdup(submodule);
1316 + refs->next = submodule_ref_stores;
1317 + submodule_ref_stores = refs;
1318 + }
1319 +}
1320 +
1321 +struct ref_store *ref_store_init(const char *submodule)
1322 +{
1323 + const char *be_name = "files";
1324 + struct ref_storage_be *be = find_ref_storage_backend(be_name);
1325 +
1326 + if (!be)
1327 + die("BUG: reference backend %s is unknown", be_name);
1328 +
1329 + if (!submodule || !*submodule)
1330 + return be->init(NULL);
1331 + else
1332 + return be->init(submodule);
1333 +}
1334 +
1335 +struct ref_store *lookup_ref_store(const char *submodule)
1336 +{
1337 + struct ref_store *refs;
1338 +
1339 + if (!submodule || !*submodule)
1340 + return main_ref_store;
1341 +
1342 + for (refs = submodule_ref_stores; refs; refs = refs->next) {
1343 + if (!strcmp(submodule, refs->submodule))
1344 + return refs;
1345 + }
1346 +
1347 + return NULL;
1348 +}
1349 +
1350 +struct ref_store *get_ref_store(const char *submodule)
1351 +{
1352 + struct ref_store *refs;
1353 +
1354 + if (!submodule || !*submodule) {
1355 + refs = lookup_ref_store(NULL);
1356 +
1357 + if (!refs)
1358 + refs = ref_store_init(NULL);
1359 + } else {
1360 + refs = lookup_ref_store(submodule);
1361 +
1362 + if (!refs) {
1363 + struct strbuf submodule_sb = STRBUF_INIT;
1364 +
1365 + strbuf_addstr(&submodule_sb, submodule);
1366 + if (is_nonbare_repository_dir(&submodule_sb))
1367 + refs = ref_store_init(submodule);
1368 + strbuf_release(&submodule_sb);
1369 + }
1370 + }
1371 +
1372 + return refs;
1373 +}
1374 +
1375 +void assert_main_repository(struct ref_store *refs, const char *caller)
1376 +{
1377 + if (*refs->submodule)
1378 + die("BUG: %s called for a submodule", caller);
1379 +}
refs/files-backend.c
+99 -78
@@ -910,17 +910,11 @@ struct packed_ref_cache {
910 * Future: need to be in "struct repository"
911 * when doing a full libification.
912 */
913 -static struct files_ref_store {
914 - struct files_ref_store *next;
913 +struct files_ref_store {
914 + struct ref_store base;
915 struct ref_entry *loose;
916 struct packed_ref_cache *packed;
917 - /*
918 - * The submodule name, or "" for the main repo. We allocate
919 - * length 1 rather than FLEX_ARRAY so that the main
920 - * files_ref_store is initialized correctly.
921 - */
922 - char name[1];
923 -} ref_store, *submodule_ref_stores;
917 +};
918
919 /* Lock used for the main packed-refs file: */
920 static struct lock_file packlock;
@@ -973,53 +967,50 @@ static void clear_loose_ref_cache(struct files_ref_store *refs)
967 * Create a new submodule ref cache and add it to the internal
968 * set of caches.
969 */
976 -static struct files_ref_store *create_ref_store(const char *submodule)
970 +static struct ref_store *files_ref_store_create(const char *submodule)
971 {
978 - struct files_ref_store *refs;
979 - if (!submodule)
980 - submodule = "";
981 - FLEX_ALLOC_STR(refs, name, submodule);
982 - refs->next = submodule_ref_stores;
983 - submodule_ref_stores = refs;
984 - return refs;
972 + struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
973 + struct ref_store *ref_store = (struct ref_store *)refs;
974 +
975 + base_ref_store_init(ref_store, &refs_be_files, submodule);
976 +
977 + return ref_store;
978 }
979
987 -static struct files_ref_store *lookup_ref_store(const char *submodule)
980 +/*
981 + * Downcast ref_store to files_ref_store. Die if ref_store is not a
982 + * files_ref_store. If submodule_allowed is not true, then also die if
983 + * files_ref_store is for a submodule (i.e., not for the main
984 + * repository). caller is used in any necessary error messages.
985 + */
986 +static struct files_ref_store *files_downcast(
987 + struct ref_store *ref_store, int submodule_allowed,
988 + const char *caller)
989 {
989 - struct files_ref_store *refs;
990 + if (ref_store->be != &refs_be_files)
991 + die("BUG: ref_store is type \"%s\" not \"files\" in %s",
992 + ref_store->be->name, caller);
993
991 - if (!submodule || !*submodule)
992 - return &ref_store;
994 + if (!submodule_allowed)
995 + assert_main_repository(ref_store, caller);
996
994 - for (refs = submodule_ref_stores; refs; refs = refs->next)
995 - if (!strcmp(submodule, refs->name))
996 - return refs;
997 - return NULL;
997 + return (struct files_ref_store *)ref_store;
998 }
999
1000 /*
1001 - * Return a pointer to a files_ref_store for the specified submodule. For
1002 - * the main repository, use submodule==NULL; such a call cannot fail.
1003 - * For a submodule, the submodule must exist and be a nonbare
1004 - * repository, otherwise return NULL.
1005 - *
1006 - * The returned structure will be allocated and initialized but not
1007 - * necessarily populated; it should not be freed.
1001 + * Return a pointer to the reference store for the specified
1002 + * submodule. For the main repository, use submodule==NULL; such a
1003 + * call cannot fail. For a submodule, the submodule must exist and be
1004 + * a nonbare repository, otherwise return NULL. Verify that the
1005 + * reference store is a files_ref_store, and cast it to that type
1006 + * before returning it.
1007 */
1009 -static struct files_ref_store *get_ref_store(const char *submodule)
1008 +static struct files_ref_store *get_files_ref_store(const char *submodule,
1009 + const char *caller)
1010 {
1011 - struct files_ref_store *refs = lookup_ref_store(submodule);
1011 + struct ref_store *refs = get_ref_store(submodule);
1012
1013 - if (!refs) {
1014 - struct strbuf submodule_sb = STRBUF_INIT;
1015 -
1016 - strbuf_addstr(&submodule_sb, submodule);
1017 - if (is_nonbare_repository_dir(&submodule_sb))
1018 - refs = create_ref_store(submodule);
1019 - strbuf_release(&submodule_sb);
1020 - }
1021 -
1022 - return refs;
1013 + return refs ? files_downcast(refs, 1, caller) : NULL;
1014 }
1015
1016 /* The length of a peeled reference line in packed-refs, including EOL: */
@@ -1158,8 +1149,9 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
1149 {
1150 char *packed_refs_file;
1151
1161 - if (*refs->name)
1162 - packed_refs_file = git_pathdup_submodule(refs->name, "packed-refs");
1152 + if (*refs->base.submodule)
1153 + packed_refs_file = git_pathdup_submodule(refs->base.submodule,
1154 + "packed-refs");
1155 else
1156 packed_refs_file = git_pathdup("packed-refs");
1157
@@ -1202,8 +1194,9 @@ static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
1194 */
1195 static void add_packed_ref(const char *refname, const unsigned char *sha1)
1196 {
1205 - struct packed_ref_cache *packed_ref_cache =
1206 - get_packed_ref_cache(&ref_store);
1197 + struct files_ref_store *refs =
1198 + get_files_ref_store(NULL, "add_packed_ref");
1199 + struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
1200
1201 if (!packed_ref_cache->lock)
1202 die("internal error: packed refs not locked");
@@ -1226,8 +1219,8 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1219 struct strbuf path = STRBUF_INIT;
1220 size_t path_baselen;
1221
1229 - if (*refs->name)
1230 - strbuf_git_path_submodule(&path, refs->name, "%s", dirname);
1222 + if (*refs->base.submodule)
1223 + strbuf_git_path_submodule(&path, refs->base.submodule, "%s", dirname);
1224 else
1225 strbuf_git_path(&path, "%s", dirname);
1226 path_baselen = path.len;
@@ -1262,10 +1255,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1255 } else {
1256 int read_ok;
1257
1265 - if (*refs->name) {
1258 + if (*refs->base.submodule) {
1259 hashclr(sha1);
1260 flag = 0;
1268 - read_ok = !resolve_gitlink_ref(refs->name,
1261 + read_ok = !resolve_gitlink_ref(refs->base.submodule,
1262 refname.buf, sha1);
1263 } else {
1264 read_ok = !read_ref_full(refname.buf,
@@ -1355,8 +1348,8 @@ static int resolve_gitlink_ref_recursive(struct files_ref_store *refs,
1348
1349 if (recursion > SYMREF_MAXDEPTH || strlen(refname) > MAXREFLEN)
1350 return -1;
1358 - path = *refs->name
1359 - ? git_pathdup_submodule(refs->name, "%s", refname)
1351 + path = *refs->base.submodule
1352 + ? git_pathdup_submodule(refs->base.submodule, "%s", refname)
1353 : git_pathdup("%s", refname);
1354 fd = open(path, O_RDONLY);
1355 free(path);
@@ -1397,7 +1390,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh
1390 return -1;
1391
1392 strbuf_add(&submodule, path, len);
1400 - refs = get_ref_store(submodule.buf);
1393 + refs = get_files_ref_store(submodule.buf, "resolve_gitlink_ref");
1394 if (!refs) {
1395 strbuf_release(&submodule);
1396 return -1;
@@ -1413,7 +1406,10 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh
1406 */
1407 static struct ref_entry *get_packed_ref(const char *refname)
1408 {
1416 - return find_ref(get_packed_refs(&ref_store), refname);
1409 + struct files_ref_store *refs =
1410 + get_files_ref_store(NULL, "get_packed_ref");
1411 +
1412 + return find_ref(get_packed_refs(refs), refname);
1413 }
1414
1415 /*
@@ -1613,6 +1609,8 @@ static int lock_raw_ref(const char *refname, int mustexist,
1609 unsigned int *type,
1610 struct strbuf *err)
1611 {
1612 + struct files_ref_store *refs =
1613 + get_files_ref_store(NULL, "lock_raw_ref");
1614 struct ref_lock *lock;
1615 struct strbuf ref_file = STRBUF_INIT;
1616 int attempts_remaining = 3;
@@ -1745,7 +1743,7 @@ retry:
1743 REMOVE_DIR_EMPTY_ONLY)) {
1744 if (verify_refname_available_dir(
1745 refname, extras, skip,
1748 - get_loose_refs(&ref_store),
1746 + get_loose_refs(refs),
1747 err)) {
1748 /*
1749 * The error message set by
@@ -1784,7 +1782,7 @@ retry:
1782 */
1783 if (verify_refname_available_dir(
1784 refname, extras, skip,
1787 - get_packed_refs(&ref_store),
1785 + get_packed_refs(refs),
1786 err)) {
1787 goto error_return;
1788 }
@@ -1942,7 +1940,8 @@ struct ref_iterator *files_ref_iterator_begin(
1940 const char *submodule,
1941 const char *prefix, unsigned int flags)
1942 {
1945 - struct files_ref_store *refs = get_ref_store(submodule);
1943 + struct files_ref_store *refs =
1944 + get_files_ref_store(submodule, "ref_iterator_begin");
1945 struct ref_dir *loose_dir, *packed_dir;
1946 struct ref_iterator *loose_iter, *packed_iter;
1947 struct files_ref_iterator *iter;
@@ -2065,6 +2064,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2064 unsigned int flags, int *type,
2065 struct strbuf *err)
2066 {
2067 + struct files_ref_store *refs =
2068 + get_files_ref_store(NULL, "lock_ref_sha1_basic");
2069 struct strbuf ref_file = STRBUF_INIT;
2070 struct ref_lock *lock;
2071 int last_errno = 0;
@@ -2095,8 +2096,9 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2096 */
2097 if (remove_empty_directories(&ref_file)) {
2098 last_errno = errno;
2098 - if (!verify_refname_available_dir(refname, extras, skip,
2099 - get_loose_refs(&ref_store), err))
2099 + if (!verify_refname_available_dir(
2100 + refname, extras, skip,
2101 + get_loose_refs(refs), err))
2102 strbuf_addf(err, "there are still refs under '%s'",
2103 refname);
2104 goto error_return;
@@ -2107,8 +2109,9 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2109 if (!resolved) {
2110 last_errno = errno;
2111 if (last_errno != ENOTDIR ||
2110 - !verify_refname_available_dir(refname, extras, skip,
2111 - get_loose_refs(&ref_store), err))
2112 + !verify_refname_available_dir(
2113 + refname, extras, skip,
2114 + get_loose_refs(refs), err))
2115 strbuf_addf(err, "unable to resolve reference '%s': %s",
2116 refname, strerror(last_errno));
2117
@@ -2123,7 +2126,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2126 */
2127 if (is_null_oid(&lock->old_oid) &&
2128 verify_refname_available_dir(refname, extras, skip,
2126 - get_packed_refs(&ref_store), err)) {
2129 + get_packed_refs(refs),
2130 + err)) {
2131 last_errno = ENOTDIR;
2132 goto error_return;
2133 }
@@ -2212,9 +2216,10 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
2216 */
2217 static int lock_packed_refs(int flags)
2218 {
2219 + struct files_ref_store *refs =
2220 + get_files_ref_store(NULL, "lock_packed_refs");
2221 static int timeout_configured = 0;
2222 static int timeout_value = 1000;
2217 -
2223 struct packed_ref_cache *packed_ref_cache;
2224
2225 if (!timeout_configured) {
@@ -2232,7 +2237,7 @@ static int lock_packed_refs(int flags)
2237 * this will automatically invalidate the cache and re-read
2238 * the packed-refs file.
2239 */
2235 - packed_ref_cache = get_packed_ref_cache(&ref_store);
2240 + packed_ref_cache = get_packed_ref_cache(refs);
2241 packed_ref_cache->lock = &packlock;
2242 /* Increment the reference count to prevent it from being freed: */
2243 acquire_packed_ref_cache(packed_ref_cache);
@@ -2247,8 +2252,10 @@ static int lock_packed_refs(int flags)
2252 */
2253 static int commit_packed_refs(void)
2254 {
2255 + struct files_ref_store *refs =
2256 + get_files_ref_store(NULL, "commit_packed_refs");
2257 struct packed_ref_cache *packed_ref_cache =
2251 - get_packed_ref_cache(&ref_store);
2258 + get_packed_ref_cache(refs);
2259 int error = 0;
2260 int save_errno = 0;
2261 FILE *out;
@@ -2281,15 +2288,17 @@ static int commit_packed_refs(void)
2288 */
2289 static void rollback_packed_refs(void)
2290 {
2291 + struct files_ref_store *refs =
2292 + get_files_ref_store(NULL, "rollback_packed_refs");
2293 struct packed_ref_cache *packed_ref_cache =
2285 - get_packed_ref_cache(&ref_store);
2294 + get_packed_ref_cache(refs);
2295
2296 if (!packed_ref_cache->lock)
2297 die("internal error: packed-refs not locked");
2298 rollback_lock_file(packed_ref_cache->lock);
2299 packed_ref_cache->lock = NULL;
2300 release_packed_ref_cache(packed_ref_cache);
2292 - clear_packed_ref_cache(&ref_store);
2301 + clear_packed_ref_cache(refs);
2302 }
2303
2304 struct ref_to_prune {
@@ -2422,15 +2431,17 @@ static void prune_refs(struct ref_to_prune *r)
2431
2432 int pack_refs(unsigned int flags)
2433 {
2434 + struct files_ref_store *refs =
2435 + get_files_ref_store(NULL, "pack_refs");
2436 struct pack_refs_cb_data cbdata;
2437
2438 memset(&cbdata, 0, sizeof(cbdata));
2439 cbdata.flags = flags;
2440
2441 lock_packed_refs(LOCK_DIE_ON_ERROR);
2431 - cbdata.packed_refs = get_packed_refs(&ref_store);
2442 + cbdata.packed_refs = get_packed_refs(refs);
2443
2433 - do_for_each_entry_in_dir(get_loose_refs(&ref_store), 0,
2444 + do_for_each_entry_in_dir(get_loose_refs(refs), 0,
2445 pack_if_possible_fn, &cbdata);
2446
2447 if (commit_packed_refs())
@@ -2449,6 +2460,8 @@ int pack_refs(unsigned int flags)
2460 */
2461 static int repack_without_refs(struct string_list *refnames, struct strbuf *err)
2462 {
2463 + struct files_ref_store *refs =
2464 + get_files_ref_store(NULL, "repack_without_refs");
2465 struct ref_dir *packed;
2466 struct string_list_item *refname;
2467 int ret, needs_repacking = 0, removed = 0;
@@ -2471,7 +2484,7 @@ static int repack_without_refs(struct string_list *refnames, struct strbuf *err)
2484 unable_to_lock_message(git_path("packed-refs"), errno, err);
2485 return -1;
2486 }
2474 - packed = get_packed_refs(&ref_store);
2487 + packed = get_packed_refs(refs);
2488
2489 /* Remove refnames from the cache */
2490 for_each_string_list_item(refname, refnames)
@@ -2616,8 +2629,10 @@ int verify_refname_available(const char *newname,
2629 const struct string_list *skip,
2630 struct strbuf *err)
2631 {
2619 - struct ref_dir *packed_refs = get_packed_refs(&ref_store);
2620 - struct ref_dir *loose_refs = get_loose_refs(&ref_store);
2632 + struct files_ref_store *refs =
2633 + get_files_ref_store(NULL, "verify_refname_available");
2634 + struct ref_dir *packed_refs = get_packed_refs(refs);
2635 + struct ref_dir *loose_refs = get_loose_refs(refs);
2636
2637 if (verify_refname_available_dir(newname, extras, skip,
2638 packed_refs, err) ||
@@ -2968,7 +2983,10 @@ static int commit_ref_update(struct ref_lock *lock,
2983 const unsigned char *sha1, const char *logmsg,
2984 struct strbuf *err)
2985 {
2971 - clear_loose_ref_cache(&ref_store);
2986 + struct files_ref_store *refs =
2987 + get_files_ref_store(NULL, "commit_ref_update");
2988 +
2989 + clear_loose_ref_cache(refs);
2990 if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, 0, err)) {
2991 char *old_msg = strbuf_detach(err, NULL);
2992 strbuf_addf(err, "cannot update the ref '%s': %s",
@@ -3684,6 +3702,8 @@ static int lock_ref_for_update(struct ref_update *update,
3702 int ref_transaction_commit(struct ref_transaction *transaction,
3703 struct strbuf *err)
3704 {
3705 + struct files_ref_store *refs =
3706 + get_files_ref_store(NULL, "ref_transaction_commit");
3707 int ret = 0, i;
3708 struct string_list refs_to_delete = STRING_LIST_INIT_NODUP;
3709 struct string_list_item *ref_to_delete;
@@ -3790,7 +3810,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3810 }
3811 }
3812 if (update->flags & REF_NEEDS_COMMIT) {
3793 - clear_loose_ref_cache(&ref_store);
3813 + clear_loose_ref_cache(refs);
3814 if (commit_ref(lock)) {
3815 strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
3816 unlock_ref(lock);
@@ -3823,7 +3843,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3843 }
3844 for_each_string_list_item(ref_to_delete, &refs_to_delete)
3845 unlink_or_warn(git_path("logs/%s", ref_to_delete->string));
3826 - clear_loose_ref_cache(&ref_store);
3846 + clear_loose_ref_cache(refs);
3847
3848 cleanup:
3849 transaction->state = REF_TRANSACTION_CLOSED;
@@ -4069,5 +4089,6 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
4089
4090 struct ref_storage_be refs_be_files = {
4091 NULL,
4072 - "files"
4092 + "files",
4093 + files_ref_store_create
4094 };
refs/refs-internal.h
+78
@@ -526,11 +526,89 @@ int read_raw_ref(const char *refname, unsigned char *sha1,
526 struct strbuf *referent, unsigned int *type);
527
528 /* refs backends */
529 +
530 +/*
531 + * Initialize the ref_store for the specified submodule, or for the
532 + * main repository if submodule == NULL. These functions should call
533 + * base_ref_store_init() to initialize the shared part of the
534 + * ref_store and to record the ref_store for later lookup.
535 + */
536 +typedef struct ref_store *ref_store_init_fn(const char *submodule);
537 +
538 struct ref_storage_be {
539 struct ref_storage_be *next;
540 const char *name;
541 + ref_store_init_fn *init;
542 };
543
544 extern struct ref_storage_be refs_be_files;
545
546 +/*
547 + * A representation of the reference store for the main repository or
548 + * a submodule. The ref_store instances for submodules are kept in a
549 + * linked list.
550 + */
551 +struct ref_store {
552 + /* The backend describing this ref_store's storage scheme: */
553 + const struct ref_storage_be *be;
554 +
555 + /*
556 + * The name of the submodule represented by this object, or
557 + * the empty string if it represents the main repository's
558 + * reference store:
559 + */
560 + const char *submodule;
561 +
562 + /*
563 + * Submodule reference store instances are stored in a linked
564 + * list using this pointer.
565 + */
566 + struct ref_store *next;
567 +};
568 +
569 +/*
570 + * Fill in the generic part of refs for the specified submodule and
571 + * add it to our collection of reference stores.
572 + */
573 +void base_ref_store_init(struct ref_store *refs,
574 + const struct ref_storage_be *be,
575 + const char *submodule);
576 +
577 +/*
578 + * Create, record, and return a ref_store instance for the specified
579 + * submodule (or the main repository if submodule is NULL).
580 + *
581 + * For backwards compatibility, submodule=="" is treated the same as
582 + * submodule==NULL.
583 + */
584 +struct ref_store *ref_store_init(const char *submodule);
585 +
586 +/*
587 + * Return the ref_store instance for the specified submodule (or the
588 + * main repository if submodule is NULL). If that ref_store hasn't
589 + * been initialized yet, return NULL.
590 + *
591 + * For backwards compatibility, submodule=="" is treated the same as
592 + * submodule==NULL.
593 + */
594 +struct ref_store *lookup_ref_store(const char *submodule);
595 +
596 +/*
597 + * Return the ref_store instance for the specified submodule. For the
598 + * main repository, use submodule==NULL; such a call cannot fail. For
599 + * a submodule, the submodule must exist and be a nonbare repository,
600 + * otherwise return NULL. If the requested reference store has not yet
601 + * been initialized, initialize it first.
602 + *
603 + * For backwards compatibility, submodule=="" is treated the same as
604 + * submodule==NULL.
605 + */
606 +struct ref_store *get_ref_store(const char *submodule);
607 +
608 +/*
609 + * Die if refs is for a submodule (i.e., not for the main repository).
610 + * caller is used in any necessary error messages.
611 + */
612 +void assert_main_repository(struct ref_store *refs, const char *caller);
613 +
614 #endif /* REFS_REFS_INTERNAL_H */