refs: push the submodule attribute down
Push the submodule attribute down from ref_store to files_ref_store. This is another step towards loosening the 1:1 connection between ref_stores and submodules. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Feb 10, 2017 at 12:16 UTC
32c597e7b2d85c1ae313e369b21398638cafe45d
3 files changed
+43
-42
refs.c
-11
@@ -1481,17 +1481,6 @@ void base_ref_store_init(struct ref_store *refs,
1481
const char *submodule)
1482
{
1483
refs->be = be;
1484
-
1485
- if (!submodule)
1486
- refs->submodule = "";
1487
- else
1488
- refs->submodule = xstrdup(submodule);
1489
-}
1490
-
1491
-void assert_main_repository(struct ref_store *refs, const char *caller)
1492
-{
1493
- if (*refs->submodule)
1494
- die("BUG: %s called for a submodule", caller);
1484
}
1485
1486
/* backend functions */
refs/files-backend.c
+43
-18
@@ -912,6 +912,14 @@ struct packed_ref_cache {
912
*/
913
struct files_ref_store {
914
struct ref_store base;
915
+
916
+ /*
917
+ * The name of the submodule represented by this object, or
918
+ * the empty string if it represents the main repository's
919
+ * reference store:
920
+ */
921
+ const char *submodule;
922
+
923
struct ref_entry *loose;
924
struct packed_ref_cache *packed;
925
};
@@ -974,9 +982,22 @@ static struct ref_store *files_ref_store_create(const char *submodule)
982
983
base_ref_store_init(ref_store, &refs_be_files, submodule);
984
985
+ refs->submodule = submodule ? xstrdup(submodule) : "";
986
+
987
return ref_store;
988
}
989
990
+/*
991
+ * Die if refs is for a submodule (i.e., not for the main repository).
992
+ * caller is used in any necessary error messages.
993
+ */
994
+static void files_assert_main_repository(struct files_ref_store *refs,
995
+ const char *caller)
996
+{
997
+ if (*refs->submodule)
998
+ die("BUG: %s called for a submodule", caller);
999
+}
1000
+
1001
/*
1002
* Downcast ref_store to files_ref_store. Die if ref_store is not a
1003
* files_ref_store. If submodule_allowed is not true, then also die if
@@ -987,14 +1008,18 @@ static struct files_ref_store *files_downcast(
1008
struct ref_store *ref_store, int submodule_allowed,
1009
const char *caller)
1010
{
1011
+ struct files_ref_store *refs;
1012
+
1013
if (ref_store->be != &refs_be_files)
1014
die("BUG: ref_store is type \"%s\" not \"files\" in %s",
1015
ref_store->be->name, caller);
1016
1017
+ refs = (struct files_ref_store *)ref_store;
1018
+
1019
if (!submodule_allowed)
995
- assert_main_repository(ref_store, caller);
1020
+ files_assert_main_repository(refs, caller);
1021
997
- return (struct files_ref_store *)ref_store;
1022
+ return refs;
1023
}
1024
1025
/* The length of a peeled reference line in packed-refs, including EOL: */
@@ -1133,8 +1158,8 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
1158
{
1159
char *packed_refs_file;
1160
1136
- if (*refs->base.submodule)
1137
- packed_refs_file = git_pathdup_submodule(refs->base.submodule,
1161
+ if (*refs->submodule)
1162
+ packed_refs_file = git_pathdup_submodule(refs->submodule,
1163
"packed-refs");
1164
else
1165
packed_refs_file = git_pathdup("packed-refs");
@@ -1203,8 +1228,8 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1228
size_t path_baselen;
1229
int err = 0;
1230
1206
- if (*refs->base.submodule)
1207
- err = strbuf_git_path_submodule(&path, refs->base.submodule, "%s", dirname);
1231
+ if (*refs->submodule)
1232
+ err = strbuf_git_path_submodule(&path, refs->submodule, "%s", dirname);
1233
else
1234
strbuf_git_path(&path, "%s", dirname);
1235
path_baselen = path.len;
@@ -1244,10 +1269,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1269
} else {
1270
int read_ok;
1271
1247
- if (*refs->base.submodule) {
1272
+ if (*refs->submodule) {
1273
hashclr(sha1);
1274
flag = 0;
1250
- read_ok = !resolve_gitlink_ref(refs->base.submodule,
1275
+ read_ok = !resolve_gitlink_ref(refs->submodule,
1276
refname.buf, sha1);
1277
} else {
1278
read_ok = !read_ref_full(refname.buf,
@@ -1358,8 +1383,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
1383
*type = 0;
1384
strbuf_reset(&sb_path);
1385
1361
- if (*refs->base.submodule)
1362
- strbuf_git_path_submodule(&sb_path, refs->base.submodule, "%s", refname);
1386
+ if (*refs->submodule)
1387
+ strbuf_git_path_submodule(&sb_path, refs->submodule, "%s", refname);
1388
else
1389
strbuf_git_path(&sb_path, "%s", refname);
1390
@@ -1540,7 +1565,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
1565
int ret = TRANSACTION_GENERIC_ERROR;
1566
1567
assert(err);
1543
- assert_main_repository(&refs->base, "lock_raw_ref");
1568
+ files_assert_main_repository(refs, "lock_raw_ref");
1569
1570
*type = 0;
1571
@@ -2006,7 +2031,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
2031
int attempts_remaining = 3;
2032
int resolved;
2033
2009
- assert_main_repository(&refs->base, "lock_ref_sha1_basic");
2034
+ files_assert_main_repository(refs, "lock_ref_sha1_basic");
2035
assert(err);
2036
2037
lock = xcalloc(1, sizeof(struct ref_lock));
@@ -2152,7 +2177,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
2177
static int timeout_value = 1000;
2178
struct packed_ref_cache *packed_ref_cache;
2179
2155
- assert_main_repository(&refs->base, "lock_packed_refs");
2180
+ files_assert_main_repository(refs, "lock_packed_refs");
2181
2182
if (!timeout_configured) {
2183
git_config_get_int("core.packedrefstimeout", &timeout_value);
@@ -2190,7 +2215,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
2215
int save_errno = 0;
2216
FILE *out;
2217
2193
- assert_main_repository(&refs->base, "commit_packed_refs");
2218
+ files_assert_main_repository(refs, "commit_packed_refs");
2219
2220
if (!packed_ref_cache->lock)
2221
die("internal error: packed-refs not locked");
@@ -2223,7 +2248,7 @@ static void rollback_packed_refs(struct files_ref_store *refs)
2248
struct packed_ref_cache *packed_ref_cache =
2249
get_packed_ref_cache(refs);
2250
2226
- assert_main_repository(&refs->base, "rollback_packed_refs");
2251
+ files_assert_main_repository(refs, "rollback_packed_refs");
2252
2253
if (!packed_ref_cache->lock)
2254
die("internal error: packed-refs not locked");
@@ -2397,7 +2422,7 @@ static int repack_without_refs(struct files_ref_store *refs,
2422
struct string_list_item *refname;
2423
int ret, needs_repacking = 0, removed = 0;
2424
2400
- assert_main_repository(&refs->base, "repack_without_refs");
2425
+ files_assert_main_repository(refs, "repack_without_refs");
2426
assert(err);
2427
2428
/* Look for a packed ref */
@@ -2930,7 +2955,7 @@ static int commit_ref_update(struct files_ref_store *refs,
2955
const unsigned char *sha1, const char *logmsg,
2956
struct strbuf *err)
2957
{
2933
- assert_main_repository(&refs->base, "commit_ref_update");
2958
+ files_assert_main_repository(refs, "commit_ref_update");
2959
2960
clear_loose_ref_cache(refs);
2961
if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, 0, err)) {
@@ -3560,7 +3585,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
3585
int ret;
3586
struct ref_lock *lock;
3587
3563
- assert_main_repository(&refs->base, "lock_ref_for_update");
3588
+ files_assert_main_repository(refs, "lock_ref_for_update");
3589
3590
if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
3591
update->flags |= REF_DELETING;
refs/refs-internal.h
-13
@@ -629,13 +629,6 @@ extern struct ref_storage_be refs_be_files;
629
struct ref_store {
630
/* The backend describing this ref_store's storage scheme: */
631
const struct ref_storage_be *be;
632
-
633
- /*
634
- * The name of the submodule represented by this object, or
635
- * the empty string if it represents the main repository's
636
- * reference store:
637
- */
638
- const char *submodule;
632
};
633
634
/*
@@ -658,10 +651,4 @@ void base_ref_store_init(struct ref_store *refs,
651
*/
652
struct ref_store *get_ref_store(const char *submodule);
653
661
-/*
662
- * Die if refs is for a submodule (i.e., not for the main repository).
663
- * caller is used in any necessary error messages.
664
- */
665
-void assert_main_repository(struct ref_store *refs, const char *caller);
666
-
654
#endif /* REFS_REFS_INTERNAL_H */