/*
* 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).
+ * 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;
};
/* Read the current packed-refs while holding the lock: */
packed_ref_cache = get_packed_ref_cache(&ref_cache);
packed_ref_cache->lock = &packlock;
+ /* Increment the reference count to prevent it from being freed: */
+ acquire_packed_ref_cache(packed_ref_cache);
return 0;
}
if (commit_lock_file(packed_ref_cache->lock))
error = -1;
packed_ref_cache->lock = NULL;
+ release_packed_ref_cache(packed_ref_cache);
return error;
}
die("internal error: packed-refs not locked");
rollback_lock_file(packed_ref_cache->lock);
packed_ref_cache->lock = NULL;
+ release_packed_ref_cache(packed_ref_cache);
clear_packed_ref_cache(&ref_cache);
}