@@ -912,6 +912,14 @@ struct packed_ref_cache {
912
912
*/
913
913
struct files_ref_store {
914
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
+
915
923
struct ref_entry * loose ;
916
924
struct packed_ref_cache * packed ;
917
925
};
@@ -974,9 +982,22 @@ static struct ref_store *files_ref_store_create(const char *submodule)
974
982
975
983
base_ref_store_init (ref_store , & refs_be_files , submodule );
976
984
985
+ refs -> submodule = submodule ? xstrdup (submodule ) : "" ;
986
+
977
987
return ref_store ;
978
988
}
979
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
+
980
1001
/*
981
1002
* Downcast ref_store to files_ref_store. Die if ref_store is not a
982
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(
987
1008
struct ref_store * ref_store , int submodule_allowed ,
988
1009
const char * caller )
989
1010
{
1011
+ struct files_ref_store * refs ;
1012
+
990
1013
if (ref_store -> be != & refs_be_files )
991
1014
die ("BUG: ref_store is type \"%s\" not \"files\" in %s" ,
992
1015
ref_store -> be -> name , caller );
993
1016
1017
+ refs = (struct files_ref_store * )ref_store ;
1018
+
994
1019
if (!submodule_allowed )
995
- assert_main_repository ( ref_store , caller );
1020
+ files_assert_main_repository ( refs , caller );
996
1021
997
- return ( struct files_ref_store * ) ref_store ;
1022
+ return refs ;
998
1023
}
999
1024
1000
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
1133
1158
{
1134
1159
char * packed_refs_file ;
1135
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 ,
1138
1163
"packed-refs" );
1139
1164
else
1140
1165
packed_refs_file = git_pathdup ("packed-refs" );
@@ -1203,8 +1228,8 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1203
1228
size_t path_baselen ;
1204
1229
int err = 0 ;
1205
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 );
1208
1233
else
1209
1234
strbuf_git_path (& path , "%s" , dirname );
1210
1235
path_baselen = path .len ;
@@ -1244,10 +1269,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1244
1269
} else {
1245
1270
int read_ok ;
1246
1271
1247
- if (* refs -> base . submodule ) {
1272
+ if (* refs -> submodule ) {
1248
1273
hashclr (sha1 );
1249
1274
flag = 0 ;
1250
- read_ok = !resolve_gitlink_ref (refs -> base . submodule ,
1275
+ read_ok = !resolve_gitlink_ref (refs -> submodule ,
1251
1276
refname .buf , sha1 );
1252
1277
} else {
1253
1278
read_ok = !read_ref_full (refname .buf ,
@@ -1358,8 +1383,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
1358
1383
* type = 0 ;
1359
1384
strbuf_reset (& sb_path );
1360
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 );
1363
1388
else
1364
1389
strbuf_git_path (& sb_path , "%s" , refname );
1365
1390
@@ -1540,7 +1565,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
1540
1565
int ret = TRANSACTION_GENERIC_ERROR ;
1541
1566
1542
1567
assert (err );
1543
- assert_main_repository ( & refs -> base , "lock_raw_ref" );
1568
+ files_assert_main_repository ( refs , "lock_raw_ref" );
1544
1569
1545
1570
* type = 0 ;
1546
1571
@@ -2006,7 +2031,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
2006
2031
int attempts_remaining = 3 ;
2007
2032
int resolved ;
2008
2033
2009
- assert_main_repository ( & refs -> base , "lock_ref_sha1_basic" );
2034
+ files_assert_main_repository ( refs , "lock_ref_sha1_basic" );
2010
2035
assert (err );
2011
2036
2012
2037
lock = xcalloc (1 , sizeof (struct ref_lock ));
@@ -2152,7 +2177,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
2152
2177
static int timeout_value = 1000 ;
2153
2178
struct packed_ref_cache * packed_ref_cache ;
2154
2179
2155
- assert_main_repository ( & refs -> base , "lock_packed_refs" );
2180
+ files_assert_main_repository ( refs , "lock_packed_refs" );
2156
2181
2157
2182
if (!timeout_configured ) {
2158
2183
git_config_get_int ("core.packedrefstimeout" , & timeout_value );
@@ -2190,7 +2215,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
2190
2215
int save_errno = 0 ;
2191
2216
FILE * out ;
2192
2217
2193
- assert_main_repository ( & refs -> base , "commit_packed_refs" );
2218
+ files_assert_main_repository ( refs , "commit_packed_refs" );
2194
2219
2195
2220
if (!packed_ref_cache -> lock )
2196
2221
die ("internal error: packed-refs not locked" );
@@ -2223,7 +2248,7 @@ static void rollback_packed_refs(struct files_ref_store *refs)
2223
2248
struct packed_ref_cache * packed_ref_cache =
2224
2249
get_packed_ref_cache (refs );
2225
2250
2226
- assert_main_repository ( & refs -> base , "rollback_packed_refs" );
2251
+ files_assert_main_repository ( refs , "rollback_packed_refs" );
2227
2252
2228
2253
if (!packed_ref_cache -> lock )
2229
2254
die ("internal error: packed-refs not locked" );
@@ -2397,7 +2422,7 @@ static int repack_without_refs(struct files_ref_store *refs,
2397
2422
struct string_list_item * refname ;
2398
2423
int ret , needs_repacking = 0 , removed = 0 ;
2399
2424
2400
- assert_main_repository ( & refs -> base , "repack_without_refs" );
2425
+ files_assert_main_repository ( refs , "repack_without_refs" );
2401
2426
assert (err );
2402
2427
2403
2428
/* Look for a packed ref */
@@ -2930,7 +2955,7 @@ static int commit_ref_update(struct files_ref_store *refs,
2930
2955
const unsigned char * sha1 , const char * logmsg ,
2931
2956
struct strbuf * err )
2932
2957
{
2933
- assert_main_repository ( & refs -> base , "commit_ref_update" );
2958
+ files_assert_main_repository ( refs , "commit_ref_update" );
2934
2959
2935
2960
clear_loose_ref_cache (refs );
2936
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,
3560
3585
int ret ;
3561
3586
struct ref_lock * lock ;
3562
3587
3563
- assert_main_repository ( & refs -> base , "lock_ref_for_update" );
3588
+ files_assert_main_repository ( refs , "lock_ref_for_update" );
3564
3589
3565
3590
if ((update -> flags & REF_HAVE_NEW ) && is_null_sha1 (update -> new_sha1 ))
3566
3591
update -> flags |= REF_DELETING ;
0 commit comments