Skip to content

Commit 32c597e

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d4558c commit 32c597e

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

refs.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,17 +1481,6 @@ void base_ref_store_init(struct ref_store *refs,
14811481
const char *submodule)
14821482
{
14831483
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);
14951484
}
14961485

14971486
/* backend functions */

refs/files-backend.c

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,14 @@ struct packed_ref_cache {
912912
*/
913913
struct files_ref_store {
914914
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+
915923
struct ref_entry *loose;
916924
struct packed_ref_cache *packed;
917925
};
@@ -974,9 +982,22 @@ static struct ref_store *files_ref_store_create(const char *submodule)
974982

975983
base_ref_store_init(ref_store, &refs_be_files, submodule);
976984

985+
refs->submodule = submodule ? xstrdup(submodule) : "";
986+
977987
return ref_store;
978988
}
979989

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+
9801001
/*
9811002
* Downcast ref_store to files_ref_store. Die if ref_store is not a
9821003
* files_ref_store. If submodule_allowed is not true, then also die if
@@ -987,14 +1008,18 @@ static struct files_ref_store *files_downcast(
9871008
struct ref_store *ref_store, int submodule_allowed,
9881009
const char *caller)
9891010
{
1011+
struct files_ref_store *refs;
1012+
9901013
if (ref_store->be != &refs_be_files)
9911014
die("BUG: ref_store is type \"%s\" not \"files\" in %s",
9921015
ref_store->be->name, caller);
9931016

1017+
refs = (struct files_ref_store *)ref_store;
1018+
9941019
if (!submodule_allowed)
995-
assert_main_repository(ref_store, caller);
1020+
files_assert_main_repository(refs, caller);
9961021

997-
return (struct files_ref_store *)ref_store;
1022+
return refs;
9981023
}
9991024

10001025
/* 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
11331158
{
11341159
char *packed_refs_file;
11351160

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,
11381163
"packed-refs");
11391164
else
11401165
packed_refs_file = git_pathdup("packed-refs");
@@ -1203,8 +1228,8 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
12031228
size_t path_baselen;
12041229
int err = 0;
12051230

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);
12081233
else
12091234
strbuf_git_path(&path, "%s", dirname);
12101235
path_baselen = path.len;
@@ -1244,10 +1269,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
12441269
} else {
12451270
int read_ok;
12461271

1247-
if (*refs->base.submodule) {
1272+
if (*refs->submodule) {
12481273
hashclr(sha1);
12491274
flag = 0;
1250-
read_ok = !resolve_gitlink_ref(refs->base.submodule,
1275+
read_ok = !resolve_gitlink_ref(refs->submodule,
12511276
refname.buf, sha1);
12521277
} else {
12531278
read_ok = !read_ref_full(refname.buf,
@@ -1358,8 +1383,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
13581383
*type = 0;
13591384
strbuf_reset(&sb_path);
13601385

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);
13631388
else
13641389
strbuf_git_path(&sb_path, "%s", refname);
13651390

@@ -1540,7 +1565,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
15401565
int ret = TRANSACTION_GENERIC_ERROR;
15411566

15421567
assert(err);
1543-
assert_main_repository(&refs->base, "lock_raw_ref");
1568+
files_assert_main_repository(refs, "lock_raw_ref");
15441569

15451570
*type = 0;
15461571

@@ -2006,7 +2031,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
20062031
int attempts_remaining = 3;
20072032
int resolved;
20082033

2009-
assert_main_repository(&refs->base, "lock_ref_sha1_basic");
2034+
files_assert_main_repository(refs, "lock_ref_sha1_basic");
20102035
assert(err);
20112036

20122037
lock = xcalloc(1, sizeof(struct ref_lock));
@@ -2152,7 +2177,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
21522177
static int timeout_value = 1000;
21532178
struct packed_ref_cache *packed_ref_cache;
21542179

2155-
assert_main_repository(&refs->base, "lock_packed_refs");
2180+
files_assert_main_repository(refs, "lock_packed_refs");
21562181

21572182
if (!timeout_configured) {
21582183
git_config_get_int("core.packedrefstimeout", &timeout_value);
@@ -2190,7 +2215,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
21902215
int save_errno = 0;
21912216
FILE *out;
21922217

2193-
assert_main_repository(&refs->base, "commit_packed_refs");
2218+
files_assert_main_repository(refs, "commit_packed_refs");
21942219

21952220
if (!packed_ref_cache->lock)
21962221
die("internal error: packed-refs not locked");
@@ -2223,7 +2248,7 @@ static void rollback_packed_refs(struct files_ref_store *refs)
22232248
struct packed_ref_cache *packed_ref_cache =
22242249
get_packed_ref_cache(refs);
22252250

2226-
assert_main_repository(&refs->base, "rollback_packed_refs");
2251+
files_assert_main_repository(refs, "rollback_packed_refs");
22272252

22282253
if (!packed_ref_cache->lock)
22292254
die("internal error: packed-refs not locked");
@@ -2397,7 +2422,7 @@ static int repack_without_refs(struct files_ref_store *refs,
23972422
struct string_list_item *refname;
23982423
int ret, needs_repacking = 0, removed = 0;
23992424

2400-
assert_main_repository(&refs->base, "repack_without_refs");
2425+
files_assert_main_repository(refs, "repack_without_refs");
24012426
assert(err);
24022427

24032428
/* Look for a packed ref */
@@ -2930,7 +2955,7 @@ static int commit_ref_update(struct files_ref_store *refs,
29302955
const unsigned char *sha1, const char *logmsg,
29312956
struct strbuf *err)
29322957
{
2933-
assert_main_repository(&refs->base, "commit_ref_update");
2958+
files_assert_main_repository(refs, "commit_ref_update");
29342959

29352960
clear_loose_ref_cache(refs);
29362961
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,
35603585
int ret;
35613586
struct ref_lock *lock;
35623587

3563-
assert_main_repository(&refs->base, "lock_ref_for_update");
3588+
files_assert_main_repository(refs, "lock_ref_for_update");
35643589

35653590
if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
35663591
update->flags |= REF_DELETING;

refs/refs-internal.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,6 @@ extern struct ref_storage_be refs_be_files;
629629
struct ref_store {
630630
/* The backend describing this ref_store's storage scheme: */
631631
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;
639632
};
640633

641634
/*
@@ -658,10 +651,4 @@ void base_ref_store_init(struct ref_store *refs,
658651
*/
659652
struct ref_store *get_ref_store(const char *submodule);
660653

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-
667654
#endif /* REFS_REFS_INTERNAL_H */

0 commit comments

Comments
 (0)