summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-05-22 14:17:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-23 05:29:54 (GMT)
commit55c6bc37c90e134e9da39b8cce1f3084318374d3 (patch)
tree6f221976b0cd21bbdd3aedb2140da550bcc13d6e /refs
parent0978f4ba7fe571d96b9f13827bdac6c30eeebfa2 (diff)
downloadgit-55c6bc37c90e134e9da39b8cce1f3084318374d3.zip
git-55c6bc37c90e134e9da39b8cce1f3084318374d3.tar.gz
git-55c6bc37c90e134e9da39b8cce1f3084318374d3.tar.bz2
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>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index fce8265..bfc555a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -43,15 +43,6 @@ struct packed_ref_cache {
*/
unsigned int referrers;
- /*
- * Iff the packed-refs file associated with this instance is
- * currently locked for writing, this points at the associated
- * lock (which is owned by somebody else). The referrer count
- * is also incremented when the file is locked and decremented
- * when it is unlocked.
- */
- struct lock_file *lock;
-
/* The metadata from when this packed-refs cache was read */
struct stat_validity validity;
};
@@ -70,6 +61,13 @@ struct files_ref_store {
struct ref_cache *loose;
struct packed_ref_cache *packed;
+
+ /*
+ * Iff the packed-refs file associated with this instance is
+ * currently locked for writing, this points at the associated
+ * lock (which is owned by somebody else).
+ */
+ struct lock_file *packed_refs_lock;
};
/* Lock used for the main packed-refs file: */
@@ -104,7 +102,7 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
if (refs->packed) {
struct packed_ref_cache *packed_refs = refs->packed;
- if (packed_refs->lock)
+ if (refs->packed_refs_lock)
die("BUG: packed-ref cache cleared while locked");
refs->packed = NULL;
release_packed_ref_cache(packed_refs);
@@ -396,7 +394,7 @@ static void add_packed_ref(struct files_ref_store *refs,
{
struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
- if (!packed_ref_cache->lock)
+ if (!refs->packed_refs_lock)
die("BUG: packed refs not locked");
add_ref_entry(get_packed_ref_dir(packed_ref_cache),
create_ref_entry(refname, oid, REF_ISPACKED, 1));
@@ -1300,7 +1298,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
* the packed-refs file.
*/
packed_ref_cache = get_packed_ref_cache(refs);
- packed_ref_cache->lock = &packlock;
+ refs->packed_refs_lock = &packlock;
/* Increment the reference count to prevent it from being freed: */
acquire_packed_ref_cache(packed_ref_cache);
return 0;
@@ -1323,10 +1321,10 @@ static int commit_packed_refs(struct files_ref_store *refs)
files_assert_main_repository(refs, "commit_packed_refs");
- if (!packed_ref_cache->lock)
+ if (!refs->packed_refs_lock)
die("BUG: packed-refs not locked");
- out = fdopen_lock_file(packed_ref_cache->lock, "w");
+ out = fdopen_lock_file(refs->packed_refs_lock, "w");
if (!out)
die_errno("unable to fdopen packed-refs descriptor");
@@ -1344,11 +1342,11 @@ static int commit_packed_refs(struct files_ref_store *refs)
if (ok != ITER_DONE)
die("error while iterating over references");
- if (commit_lock_file(packed_ref_cache->lock)) {
+ if (commit_lock_file(refs->packed_refs_lock)) {
save_errno = errno;
error = -1;
}
- packed_ref_cache->lock = NULL;
+ refs->packed_refs_lock = NULL;
release_packed_ref_cache(packed_ref_cache);
errno = save_errno;
return error;
@@ -1366,10 +1364,10 @@ static void rollback_packed_refs(struct files_ref_store *refs)
files_assert_main_repository(refs, "rollback_packed_refs");
- if (!packed_ref_cache->lock)
+ if (!refs->packed_refs_lock)
die("BUG: packed-refs not locked");
- rollback_lock_file(packed_ref_cache->lock);
- packed_ref_cache->lock = NULL;
+ rollback_lock_file(refs->packed_refs_lock);
+ refs->packed_refs_lock = NULL;
release_packed_ref_cache(packed_ref_cache);
clear_packed_ref_cache(refs);
}