Skip to content

Commit 39c8df0

Browse files
mhaggergitster
authored andcommitted
packed-backend: don't adjust the reference count on lock/unlock
The old code incremented the packed ref cache reference count when acquiring the packed-refs lock, and decremented the count when releasing the lock. This is unnecessary because: * Another process cannot change the packed-refs file because it is locked. * When we ourselves change the packed-refs file, we do so by first modifying the packed ref-cache, and then writing the data from the ref-cache to disk. So the packed ref-cache remains fresh because any changes that we plan to make to the file are made in the cache first anyway. So there is no reason for the cache to become stale. Moreover, the extra reference count causes a problem if we intentionally clear the packed refs cache, as we sometimes need to do if we change the cache in anticipation of writing a change to disk, but then the write to disk fails. In that case, `packed_refs_unlock()` would have no easy way to find the cache whose reference count it needs to decrement. This whole issue will soon become moot due to upcoming changes that avoid changing the in-memory cache as part of updating the packed-refs on disk, but this change makes that transition easier. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 238e487 commit 39c8df0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

refs/packed-backend.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
525525
"packed_refs_lock");
526526
static int timeout_configured = 0;
527527
static int timeout_value = 1000;
528-
struct packed_ref_cache *packed_ref_cache;
529528

530529
if (!timeout_configured) {
531530
git_config_get_int("core.packedrefstimeout", &timeout_value);
@@ -560,9 +559,11 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
560559
*/
561560
validate_packed_ref_cache(refs);
562561

563-
packed_ref_cache = get_packed_ref_cache(refs);
564-
/* Increment the reference count to prevent it from being freed: */
565-
acquire_packed_ref_cache(packed_ref_cache);
562+
/*
563+
* Now make sure that the packed-refs file as it exists in the
564+
* locked state is loaded into the cache:
565+
*/
566+
get_packed_ref_cache(refs);
566567
return 0;
567568
}
568569

@@ -576,7 +577,6 @@ void packed_refs_unlock(struct ref_store *ref_store)
576577
if (!is_lock_file_locked(&refs->lock))
577578
die("BUG: packed_refs_unlock() called when not locked");
578579
rollback_lock_file(&refs->lock);
579-
release_packed_ref_cache(refs->cache);
580580
}
581581

582582
int packed_refs_is_locked(struct ref_store *ref_store)

0 commit comments

Comments
 (0)