packed_ref_store: move `packed_refs_lock` member here

Move the `packed_refs_lock` member from `files_ref_store` to `packed_ref_store`, and rename it to `lock` since it's now more obvious what it is locking. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jun 23, 2017 at 09:01 UTC 139c4596ad6fc1585574f27fde6dea28ab1d3a54
1 file changed +16 -15
refs/files-backend.c
+16 -15
@@ -62,6 +62,12 @@ struct packed_ref_store {
62 * it might still be current; otherwise, NULL.
63 */
64 struct packed_ref_cache *cache;
65 +
66 + /*
67 + * Lock used for the "packed-refs" file. Note that this (and
68 + * thus the enclosing `packed_ref_store`) must not be freed.
69 + */
70 + struct lock_file lock;
71 };
72
73 static struct packed_ref_store *packed_ref_store_create(
@@ -87,12 +93,6 @@ struct files_ref_store {
93
94 struct ref_cache *loose;
95
90 - /*
91 - * Lock used for the "packed-refs" file. Note that this (and
92 - * thus the enclosing `files_ref_store`) must not be freed.
93 - */
94 - struct lock_file packed_refs_lock;
95 -
96 struct packed_ref_store *packed_ref_store;
97 };
98
@@ -125,7 +125,7 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
125 if (refs->packed_ref_store->cache) {
126 struct packed_ref_cache *packed_refs = refs->packed_ref_store->cache;
127
128 - if (is_lock_file_locked(&refs->packed_refs_lock))
128 + if (is_lock_file_locked(&refs->packed_ref_store->lock))
129 die("BUG: packed-ref cache cleared while locked");
130 refs->packed_ref_store->cache = NULL;
131 release_packed_ref_cache(packed_refs);
@@ -416,7 +416,7 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
416 {
417 const char *packed_refs_file = refs->packed_ref_store->path;
418
419 - if (!is_lock_file_locked(&refs->packed_refs_lock))
419 + if (!is_lock_file_locked(&refs->packed_ref_store->lock))
420 validate_packed_ref_cache(refs);
421
422 if (!refs->packed_ref_store->cache)
@@ -447,7 +447,7 @@ static void add_packed_ref(struct files_ref_store *refs,
447 struct ref_dir *packed_refs;
448 struct ref_entry *packed_entry;
449
450 - if (!is_lock_file_locked(&refs->packed_refs_lock))
450 + if (!is_lock_file_locked(&refs->packed_ref_store->lock))
451 die("BUG: packed refs not locked");
452
453 if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
@@ -1351,7 +1351,8 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1351 }
1352
1353 if (hold_lock_file_for_update_timeout(
1354 - &refs->packed_refs_lock, refs->packed_ref_store->path,
1354 + &refs->packed_ref_store->lock,
1355 + refs->packed_ref_store->path,
1356 flags, timeout_value) < 0)
1357 return -1;
1358
@@ -1388,10 +1389,10 @@ static int commit_packed_refs(struct files_ref_store *refs)
1389
1390 files_assert_main_repository(refs, "commit_packed_refs");
1391
1391 - if (!is_lock_file_locked(&refs->packed_refs_lock))
1392 + if (!is_lock_file_locked(&refs->packed_ref_store->lock))
1393 die("BUG: packed-refs not locked");
1394
1394 - out = fdopen_lock_file(&refs->packed_refs_lock, "w");
1395 + out = fdopen_lock_file(&refs->packed_ref_store->lock, "w");
1396 if (!out)
1397 die_errno("unable to fdopen packed-refs descriptor");
1398
@@ -1409,7 +1410,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
1410 if (ok != ITER_DONE)
1411 die("error while iterating over references");
1412
1412 - if (commit_lock_file(&refs->packed_refs_lock)) {
1413 + if (commit_lock_file(&refs->packed_ref_store->lock)) {
1414 save_errno = errno;
1415 error = -1;
1416 }
@@ -1430,9 +1431,9 @@ static void rollback_packed_refs(struct files_ref_store *refs)
1431
1432 files_assert_main_repository(refs, "rollback_packed_refs");
1433
1433 - if (!is_lock_file_locked(&refs->packed_refs_lock))
1434 + if (!is_lock_file_locked(&refs->packed_ref_store->lock))
1435 die("BUG: packed-refs not locked");
1435 - rollback_lock_file(&refs->packed_refs_lock);
1436 + rollback_lock_file(&refs->packed_ref_store->lock);
1437 release_packed_ref_cache(packed_ref_cache);
1438 clear_packed_ref_cache(refs);
1439 }