@@ -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
+ * NULL if it represents the main repository's reference
919
+ * store:
920
+ */
921
+ const char * submodule ;
922
+
915
923
struct ref_entry * loose ;
916
924
struct packed_ref_cache * packed ;
917
925
};
@@ -972,11 +980,24 @@ static struct ref_store *files_ref_store_create(const char *submodule)
972
980
struct files_ref_store * refs = xcalloc (1 , sizeof (* refs ));
973
981
struct ref_store * ref_store = (struct ref_store * )refs ;
974
982
975
- base_ref_store_init (ref_store , & refs_be_files , submodule );
983
+ base_ref_store_init (ref_store , & refs_be_files );
984
+
985
+ refs -> submodule = xstrdup_or_null (submodule );
976
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 ;
@@ -1242,20 +1267,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1242
1267
create_dir_entry (refs , refname .buf ,
1243
1268
refname .len , 1 ));
1244
1269
} else {
1245
- int read_ok ;
1246
-
1247
- if (* refs -> base .submodule ) {
1248
- hashclr (sha1 );
1249
- flag = 0 ;
1250
- read_ok = !resolve_gitlink_ref (refs -> base .submodule ,
1251
- refname .buf , sha1 );
1252
- } else {
1253
- read_ok = !read_ref_full (refname .buf ,
1254
- RESOLVE_REF_READING ,
1255
- sha1 , & flag );
1256
- }
1257
-
1258
- if (!read_ok ) {
1270
+ if (!resolve_ref_recursively (& refs -> base ,
1271
+ refname .buf ,
1272
+ RESOLVE_REF_READING ,
1273
+ sha1 , & flag )) {
1259
1274
hashclr (sha1 );
1260
1275
flag |= REF_ISBROKEN ;
1261
1276
} else if (is_null_sha1 (sha1 )) {
@@ -1358,8 +1373,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
1358
1373
* type = 0 ;
1359
1374
strbuf_reset (& sb_path );
1360
1375
1361
- if (* refs -> base . submodule )
1362
- strbuf_git_path_submodule (& sb_path , refs -> base . submodule , "%s" , refname );
1376
+ if (refs -> submodule )
1377
+ strbuf_git_path_submodule (& sb_path , refs -> submodule , "%s" , refname );
1363
1378
else
1364
1379
strbuf_git_path (& sb_path , "%s" , refname );
1365
1380
@@ -1540,7 +1555,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
1540
1555
int ret = TRANSACTION_GENERIC_ERROR ;
1541
1556
1542
1557
assert (err );
1543
- assert_main_repository ( & refs -> base , "lock_raw_ref" );
1558
+ files_assert_main_repository ( refs , "lock_raw_ref" );
1544
1559
1545
1560
* type = 0 ;
1546
1561
@@ -2011,7 +2026,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
2011
2026
int resolve_flags = RESOLVE_REF_NO_RECURSE ;
2012
2027
int resolved ;
2013
2028
2014
- assert_main_repository ( & refs -> base , "lock_ref_sha1_basic" );
2029
+ files_assert_main_repository ( refs , "lock_ref_sha1_basic" );
2015
2030
assert (err );
2016
2031
2017
2032
lock = xcalloc (1 , sizeof (struct ref_lock ));
@@ -2134,7 +2149,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
2134
2149
static int timeout_value = 1000 ;
2135
2150
struct packed_ref_cache * packed_ref_cache ;
2136
2151
2137
- assert_main_repository ( & refs -> base , "lock_packed_refs" );
2152
+ files_assert_main_repository ( refs , "lock_packed_refs" );
2138
2153
2139
2154
if (!timeout_configured ) {
2140
2155
git_config_get_int ("core.packedrefstimeout" , & timeout_value );
@@ -2172,7 +2187,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
2172
2187
int save_errno = 0 ;
2173
2188
FILE * out ;
2174
2189
2175
- assert_main_repository ( & refs -> base , "commit_packed_refs" );
2190
+ files_assert_main_repository ( refs , "commit_packed_refs" );
2176
2191
2177
2192
if (!packed_ref_cache -> lock )
2178
2193
die ("internal error: packed-refs not locked" );
@@ -2205,7 +2220,7 @@ static void rollback_packed_refs(struct files_ref_store *refs)
2205
2220
struct packed_ref_cache * packed_ref_cache =
2206
2221
get_packed_ref_cache (refs );
2207
2222
2208
- assert_main_repository ( & refs -> base , "rollback_packed_refs" );
2223
+ files_assert_main_repository ( refs , "rollback_packed_refs" );
2209
2224
2210
2225
if (!packed_ref_cache -> lock )
2211
2226
die ("internal error: packed-refs not locked" );
@@ -2392,7 +2407,7 @@ static int repack_without_refs(struct files_ref_store *refs,
2392
2407
struct string_list_item * refname ;
2393
2408
int ret , needs_repacking = 0 , removed = 0 ;
2394
2409
2395
- assert_main_repository ( & refs -> base , "repack_without_refs" );
2410
+ files_assert_main_repository ( refs , "repack_without_refs" );
2396
2411
assert (err );
2397
2412
2398
2413
/* Look for a packed ref */
@@ -2902,7 +2917,7 @@ static int commit_ref_update(struct files_ref_store *refs,
2902
2917
const unsigned char * sha1 , const char * logmsg ,
2903
2918
struct strbuf * err )
2904
2919
{
2905
- assert_main_repository ( & refs -> base , "commit_ref_update" );
2920
+ files_assert_main_repository ( refs , "commit_ref_update" );
2906
2921
2907
2922
clear_loose_ref_cache (refs );
2908
2923
if (files_log_ref_write (lock -> ref_name , lock -> old_oid .hash , sha1 ,
@@ -3534,7 +3549,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
3534
3549
int ret ;
3535
3550
struct ref_lock * lock ;
3536
3551
3537
- assert_main_repository ( & refs -> base , "lock_ref_for_update" );
3552
+ files_assert_main_repository ( refs , "lock_ref_for_update" );
3538
3553
3539
3554
if ((update -> flags & REF_HAVE_NEW ) && is_null_sha1 (update -> new_sha1 ))
3540
3555
update -> flags |= REF_DELETING ;
0 commit comments