@@ -80,6 +80,19 @@ static struct packed_ref_store *packed_ref_store_create(
8080 return refs ;
8181}
8282
83+ /*
84+ * Die if refs is not the main ref store. caller is used in any
85+ * necessary error messages.
86+ */
87+ static void packed_assert_main_repository (struct packed_ref_store * refs ,
88+ const char * caller )
89+ {
90+ if (refs -> store_flags & REF_STORE_MAIN )
91+ return ;
92+
93+ die ("BUG: operation %s only allowed for main ref store" , caller );
94+ }
95+
8396/*
8497 * Future: need to be in "struct repository"
8598 * when doing a full libification.
@@ -1334,22 +1347,22 @@ static void write_packed_entry(FILE *fh, const char *refname,
13341347 * hold_lock_file_for_update(). Return 0 on success. On errors, set
13351348 * errno appropriately and return a nonzero value.
13361349 */
1337- static int lock_packed_refs (struct files_ref_store * refs , int flags )
1350+ static int lock_packed_refs (struct packed_ref_store * refs , int flags )
13381351{
13391352 static int timeout_configured = 0 ;
13401353 static int timeout_value = 1000 ;
13411354 struct packed_ref_cache * packed_ref_cache ;
13421355
1343- files_assert_main_repository (refs , "lock_packed_refs" );
1356+ packed_assert_main_repository (refs , "lock_packed_refs" );
13441357
13451358 if (!timeout_configured ) {
13461359 git_config_get_int ("core.packedrefstimeout" , & timeout_value );
13471360 timeout_configured = 1 ;
13481361 }
13491362
13501363 if (hold_lock_file_for_update_timeout (
1351- & refs -> packed_ref_store -> lock ,
1352- refs -> packed_ref_store -> path ,
1364+ & refs -> lock ,
1365+ refs -> path ,
13531366 flags , timeout_value ) < 0 )
13541367 return -1 ;
13551368
@@ -1361,9 +1374,9 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
13611374 * cache is still valid. We've just locked the file, but it
13621375 * might have changed the moment *before* we locked it.
13631376 */
1364- validate_packed_ref_cache (refs -> packed_ref_store );
1377+ validate_packed_ref_cache (refs );
13651378
1366- packed_ref_cache = get_packed_ref_cache (refs -> packed_ref_store );
1379+ packed_ref_cache = get_packed_ref_cache (refs );
13671380 /* Increment the reference count to prevent it from being freed: */
13681381 acquire_packed_ref_cache (packed_ref_cache );
13691382 return 0 ;
@@ -1560,7 +1573,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
15601573 int ok ;
15611574 struct ref_to_prune * refs_to_prune = NULL ;
15621575
1563- lock_packed_refs (refs , LOCK_DIE_ON_ERROR );
1576+ lock_packed_refs (refs -> packed_ref_store , LOCK_DIE_ON_ERROR );
15641577
15651578 iter = cache_ref_iterator_begin (get_loose_ref_cache (refs ), NULL , 0 );
15661579 while ((ok = ref_iterator_advance (iter )) == ITER_OK ) {
@@ -1629,7 +1642,7 @@ static int repack_without_refs(struct files_ref_store *refs,
16291642 if (!needs_repacking )
16301643 return 0 ; /* no refname exists in packed refs */
16311644
1632- if (lock_packed_refs (refs , 0 )) {
1645+ if (lock_packed_refs (refs -> packed_ref_store , 0 )) {
16331646 unable_to_lock_message (refs -> packed_ref_store -> path , errno , err );
16341647 return -1 ;
16351648 }
@@ -3198,7 +3211,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
31983211 }
31993212 }
32003213
3201- if (lock_packed_refs (refs , 0 )) {
3214+ if (lock_packed_refs (refs -> packed_ref_store , 0 )) {
32023215 strbuf_addf (err , "unable to lock packed-refs file: %s" ,
32033216 strerror (errno ));
32043217 ret = TRANSACTION_GENERIC_ERROR ;
0 commit comments