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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 22, 2017 at 16:17 UTC 55c6bc37c90e134e9da39b8cce1f3084318374d3
1 file changed +17 -19
refs/files-backend.c
+17 -19
@@ -43,15 +43,6 @@ struct packed_ref_cache {
43 */
44 unsigned int referrers;
45
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 -
46 /* The metadata from when this packed-refs cache was read */
47 struct stat_validity validity;
48 };
@@ -70,6 +61,13 @@ struct files_ref_store {
61
62 struct ref_cache *loose;
63 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;
71 };
72
73 /* Lock used for the main packed-refs file: */
@@ -104,7 +102,7 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
102 if (refs->packed) {
103 struct packed_ref_cache *packed_refs = refs->packed;
104
107 - if (packed_refs->lock)
105 + if (refs->packed_refs_lock)
106 die("BUG: packed-ref cache cleared while locked");
107 refs->packed = NULL;
108 release_packed_ref_cache(packed_refs);
@@ -396,7 +394,7 @@ static void add_packed_ref(struct files_ref_store *refs,
394 {
395 struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
396
399 - if (!packed_ref_cache->lock)
397 + if (!refs->packed_refs_lock)
398 die("BUG: packed refs not locked");
399 add_ref_entry(get_packed_ref_dir(packed_ref_cache),
400 create_ref_entry(refname, oid, REF_ISPACKED, 1));
@@ -1300,7 +1298,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1298 * the packed-refs file.
1299 */
1300 packed_ref_cache = get_packed_ref_cache(refs);
1303 - packed_ref_cache->lock = &packlock;
1301 + refs->packed_refs_lock = &packlock;
1302 /* Increment the reference count to prevent it from being freed: */
1303 acquire_packed_ref_cache(packed_ref_cache);
1304 return 0;
@@ -1323,10 +1321,10 @@ static int commit_packed_refs(struct files_ref_store *refs)
1321
1322 files_assert_main_repository(refs, "commit_packed_refs");
1323
1326 - if (!packed_ref_cache->lock)
1324 + if (!refs->packed_refs_lock)
1325 die("BUG: packed-refs not locked");
1326
1329 - out = fdopen_lock_file(packed_ref_cache->lock, "w");
1327 + out = fdopen_lock_file(refs->packed_refs_lock, "w");
1328 if (!out)
1329 die_errno("unable to fdopen packed-refs descriptor");
1330
@@ -1344,11 +1342,11 @@ static int commit_packed_refs(struct files_ref_store *refs)
1342 if (ok != ITER_DONE)
1343 die("error while iterating over references");
1344
1347 - if (commit_lock_file(packed_ref_cache->lock)) {
1345 + if (commit_lock_file(refs->packed_refs_lock)) {
1346 save_errno = errno;
1347 error = -1;
1348 }
1351 - packed_ref_cache->lock = NULL;
1349 + refs->packed_refs_lock = NULL;
1350 release_packed_ref_cache(packed_ref_cache);
1351 errno = save_errno;
1352 return error;
@@ -1366,10 +1364,10 @@ static void rollback_packed_refs(struct files_ref_store *refs)
1364
1365 files_assert_main_repository(refs, "rollback_packed_refs");
1366
1369 - if (!packed_ref_cache->lock)
1367 + if (!refs->packed_refs_lock)
1368 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;
1371 release_packed_ref_cache(packed_ref_cache);
1372 clear_packed_ref_cache(refs);
1373 }