@@ -63,16 +63,12 @@ struct files_ref_store {
63
63
struct packed_ref_cache * packed ;
64
64
65
65
/*
66
- * Iff the packed-refs file associated with this instance is
67
- * currently locked for writing, this points at the associated
68
- * lock (which is owned by somebody else).
66
+ * Lock used for the "packed-refs" file. Note that this (and
67
+ * thus the enclosing `files_ref_store`) must not be freed.
69
68
*/
70
- struct lock_file * packed_refs_lock ;
69
+ struct lock_file packed_refs_lock ;
71
70
};
72
71
73
- /* Lock used for the main packed-refs file: */
74
- static struct lock_file packlock ;
75
-
76
72
/*
77
73
* Increment the reference count of *packed_refs.
78
74
*/
@@ -102,7 +98,7 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
102
98
if (refs -> packed ) {
103
99
struct packed_ref_cache * packed_refs = refs -> packed ;
104
100
105
- if (refs -> packed_refs_lock )
101
+ if (is_lock_file_locked ( & refs -> packed_refs_lock ) )
106
102
die ("BUG: packed-ref cache cleared while locked" );
107
103
refs -> packed = NULL ;
108
104
release_packed_ref_cache (packed_refs );
@@ -394,7 +390,7 @@ static void add_packed_ref(struct files_ref_store *refs,
394
390
{
395
391
struct packed_ref_cache * packed_ref_cache = get_packed_ref_cache (refs );
396
392
397
- if (!refs -> packed_refs_lock )
393
+ if (!is_lock_file_locked ( & refs -> packed_refs_lock ) )
398
394
die ("BUG: packed refs not locked" );
399
395
add_ref_entry (get_packed_ref_dir (packed_ref_cache ),
400
396
create_ref_entry (refname , oid , REF_ISPACKED , 1 ));
@@ -1288,7 +1284,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1288
1284
}
1289
1285
1290
1286
if (hold_lock_file_for_update_timeout (
1291
- & packlock , files_packed_refs_path (refs ),
1287
+ & refs -> packed_refs_lock , files_packed_refs_path (refs ),
1292
1288
flags , timeout_value ) < 0 )
1293
1289
return -1 ;
1294
1290
/*
@@ -1298,7 +1294,6 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1298
1294
* the packed-refs file.
1299
1295
*/
1300
1296
packed_ref_cache = get_packed_ref_cache (refs );
1301
- refs -> packed_refs_lock = & packlock ;
1302
1297
/* Increment the reference count to prevent it from being freed: */
1303
1298
acquire_packed_ref_cache (packed_ref_cache );
1304
1299
return 0 ;
@@ -1321,10 +1316,10 @@ static int commit_packed_refs(struct files_ref_store *refs)
1321
1316
1322
1317
files_assert_main_repository (refs , "commit_packed_refs" );
1323
1318
1324
- if (!refs -> packed_refs_lock )
1319
+ if (!is_lock_file_locked ( & refs -> packed_refs_lock ) )
1325
1320
die ("BUG: packed-refs not locked" );
1326
1321
1327
- out = fdopen_lock_file (refs -> packed_refs_lock , "w" );
1322
+ out = fdopen_lock_file (& refs -> packed_refs_lock , "w" );
1328
1323
if (!out )
1329
1324
die_errno ("unable to fdopen packed-refs descriptor" );
1330
1325
@@ -1342,11 +1337,10 @@ static int commit_packed_refs(struct files_ref_store *refs)
1342
1337
if (ok != ITER_DONE )
1343
1338
die ("error while iterating over references" );
1344
1339
1345
- if (commit_lock_file (refs -> packed_refs_lock )) {
1340
+ if (commit_lock_file (& refs -> packed_refs_lock )) {
1346
1341
save_errno = errno ;
1347
1342
error = -1 ;
1348
1343
}
1349
- refs -> packed_refs_lock = NULL ;
1350
1344
release_packed_ref_cache (packed_ref_cache );
1351
1345
errno = save_errno ;
1352
1346
return error ;
@@ -1364,10 +1358,9 @@ static void rollback_packed_refs(struct files_ref_store *refs)
1364
1358
1365
1359
files_assert_main_repository (refs , "rollback_packed_refs" );
1366
1360
1367
- if (!refs -> packed_refs_lock )
1361
+ if (!is_lock_file_locked ( & refs -> packed_refs_lock ) )
1368
1362
die ("BUG: packed-refs not locked" );
1369
- rollback_lock_file (refs -> packed_refs_lock );
1370
- refs -> packed_refs_lock = NULL ;
1363
+ rollback_lock_file (& refs -> packed_refs_lock );
1371
1364
release_packed_ref_cache (packed_ref_cache );
1372
1365
clear_packed_ref_cache (refs );
1373
1366
}
0 commit comments