Skip to content

Commit 55c6bc3

Browse files
mhaggergitster
authored andcommitted
files-backend: move lock member to files_ref_store
Move the `lock` member from `packed_ref_cache` to `files_ref_store`, since at most one cache can have a locked "packed-refs" file associated with it. Rename it to `packed_refs_lock` to make its purpose clearer in its new home. More changes are coming here shortly. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0978f4b commit 55c6bc3

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

refs/files-backend.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ struct packed_ref_cache {
4343
*/
4444
unsigned int referrers;
4545

46-
/*
47-
* Iff the packed-refs file associated with this instance is
48-
* currently locked for writing, this points at the associated
49-
* lock (which is owned by somebody else). The referrer count
50-
* is also incremented when the file is locked and decremented
51-
* when it is unlocked.
52-
*/
53-
struct lock_file *lock;
54-
5546
/* The metadata from when this packed-refs cache was read */
5647
struct stat_validity validity;
5748
};
@@ -70,6 +61,13 @@ struct files_ref_store {
7061

7162
struct ref_cache *loose;
7263
struct packed_ref_cache *packed;
64+
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).
69+
*/
70+
struct lock_file *packed_refs_lock;
7371
};
7472

7573
/* Lock used for the main packed-refs file: */
@@ -104,7 +102,7 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
104102
if (refs->packed) {
105103
struct packed_ref_cache *packed_refs = refs->packed;
106104

107-
if (packed_refs->lock)
105+
if (refs->packed_refs_lock)
108106
die("BUG: packed-ref cache cleared while locked");
109107
refs->packed = NULL;
110108
release_packed_ref_cache(packed_refs);
@@ -396,7 +394,7 @@ static void add_packed_ref(struct files_ref_store *refs,
396394
{
397395
struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
398396

399-
if (!packed_ref_cache->lock)
397+
if (!refs->packed_refs_lock)
400398
die("BUG: packed refs not locked");
401399
add_ref_entry(get_packed_ref_dir(packed_ref_cache),
402400
create_ref_entry(refname, oid, REF_ISPACKED, 1));
@@ -1300,7 +1298,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
13001298
* the packed-refs file.
13011299
*/
13021300
packed_ref_cache = get_packed_ref_cache(refs);
1303-
packed_ref_cache->lock = &packlock;
1301+
refs->packed_refs_lock = &packlock;
13041302
/* Increment the reference count to prevent it from being freed: */
13051303
acquire_packed_ref_cache(packed_ref_cache);
13061304
return 0;
@@ -1323,10 +1321,10 @@ static int commit_packed_refs(struct files_ref_store *refs)
13231321

13241322
files_assert_main_repository(refs, "commit_packed_refs");
13251323

1326-
if (!packed_ref_cache->lock)
1324+
if (!refs->packed_refs_lock)
13271325
die("BUG: packed-refs not locked");
13281326

1329-
out = fdopen_lock_file(packed_ref_cache->lock, "w");
1327+
out = fdopen_lock_file(refs->packed_refs_lock, "w");
13301328
if (!out)
13311329
die_errno("unable to fdopen packed-refs descriptor");
13321330

@@ -1344,11 +1342,11 @@ static int commit_packed_refs(struct files_ref_store *refs)
13441342
if (ok != ITER_DONE)
13451343
die("error while iterating over references");
13461344

1347-
if (commit_lock_file(packed_ref_cache->lock)) {
1345+
if (commit_lock_file(refs->packed_refs_lock)) {
13481346
save_errno = errno;
13491347
error = -1;
13501348
}
1351-
packed_ref_cache->lock = NULL;
1349+
refs->packed_refs_lock = NULL;
13521350
release_packed_ref_cache(packed_ref_cache);
13531351
errno = save_errno;
13541352
return error;
@@ -1366,10 +1364,10 @@ static void rollback_packed_refs(struct files_ref_store *refs)
13661364

13671365
files_assert_main_repository(refs, "rollback_packed_refs");
13681366

1369-
if (!packed_ref_cache->lock)
1367+
if (!refs->packed_refs_lock)
13701368
die("BUG: packed-refs not locked");
1371-
rollback_lock_file(packed_ref_cache->lock);
1372-
packed_ref_cache->lock = NULL;
1369+
rollback_lock_file(refs->packed_refs_lock);
1370+
refs->packed_refs_lock = NULL;
13731371
release_packed_ref_cache(packed_ref_cache);
13741372
clear_packed_ref_cache(refs);
13751373
}

0 commit comments

Comments
 (0)