get_packed_ref_cache(): take a packed_ref_store * parameter
It only cares about the packed-refs part of the reference store. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
25e0c5faf2
commit
8e821c38f7
@ -404,24 +404,22 @@ static void validate_packed_ref_cache(struct packed_ref_store *refs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the packed_ref_cache for the specified files_ref_store,
|
* Get the packed_ref_cache for the specified packed_ref_store,
|
||||||
* creating and populating it if it hasn't been read before or if the
|
* creating and populating it if it hasn't been read before or if the
|
||||||
* file has been changed (according to its `validity` field) since it
|
* file has been changed (according to its `validity` field) since it
|
||||||
* was last read. On the other hand, if we hold the lock, then assume
|
* was last read. On the other hand, if we hold the lock, then assume
|
||||||
* that the file hasn't been changed out from under us, so skip the
|
* that the file hasn't been changed out from under us, so skip the
|
||||||
* extra `stat()` call in `stat_validity_check()`.
|
* extra `stat()` call in `stat_validity_check()`.
|
||||||
*/
|
*/
|
||||||
static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
|
static struct packed_ref_cache *get_packed_ref_cache(struct packed_ref_store *refs)
|
||||||
{
|
{
|
||||||
const char *packed_refs_file = refs->packed_ref_store->path;
|
if (!is_lock_file_locked(&refs->lock))
|
||||||
|
validate_packed_ref_cache(refs);
|
||||||
|
|
||||||
if (!is_lock_file_locked(&refs->packed_ref_store->lock))
|
if (!refs->cache)
|
||||||
validate_packed_ref_cache(refs->packed_ref_store);
|
refs->cache = read_packed_refs(refs->path);
|
||||||
|
|
||||||
if (!refs->packed_ref_store->cache)
|
return refs->cache;
|
||||||
refs->packed_ref_store->cache = read_packed_refs(packed_refs_file);
|
|
||||||
|
|
||||||
return refs->packed_ref_store->cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_cache)
|
static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_cache)
|
||||||
@ -431,7 +429,7 @@ static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_ca
|
|||||||
|
|
||||||
static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
|
static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
|
||||||
{
|
{
|
||||||
return get_packed_ref_dir(get_packed_ref_cache(refs));
|
return get_packed_ref_dir(get_packed_ref_cache(refs->packed_ref_store));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1151,7 +1149,7 @@ static struct ref_iterator *files_ref_iterator_begin(
|
|||||||
loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
|
loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
|
||||||
prefix, 1);
|
prefix, 1);
|
||||||
|
|
||||||
iter->packed_ref_cache = get_packed_ref_cache(refs);
|
iter->packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
|
||||||
acquire_packed_ref_cache(iter->packed_ref_cache);
|
acquire_packed_ref_cache(iter->packed_ref_cache);
|
||||||
packed_iter = cache_ref_iterator_begin(iter->packed_ref_cache->cache,
|
packed_iter = cache_ref_iterator_begin(iter->packed_ref_cache->cache,
|
||||||
prefix, 0);
|
prefix, 0);
|
||||||
@ -1365,7 +1363,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
|
|||||||
*/
|
*/
|
||||||
validate_packed_ref_cache(refs->packed_ref_store);
|
validate_packed_ref_cache(refs->packed_ref_store);
|
||||||
|
|
||||||
packed_ref_cache = get_packed_ref_cache(refs);
|
packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
|
||||||
/* Increment the reference count to prevent it from being freed: */
|
/* Increment the reference count to prevent it from being freed: */
|
||||||
acquire_packed_ref_cache(packed_ref_cache);
|
acquire_packed_ref_cache(packed_ref_cache);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1380,7 +1378,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
|
|||||||
static int commit_packed_refs(struct files_ref_store *refs)
|
static int commit_packed_refs(struct files_ref_store *refs)
|
||||||
{
|
{
|
||||||
struct packed_ref_cache *packed_ref_cache =
|
struct packed_ref_cache *packed_ref_cache =
|
||||||
get_packed_ref_cache(refs);
|
get_packed_ref_cache(refs->packed_ref_store);
|
||||||
int ok, error = 0;
|
int ok, error = 0;
|
||||||
int save_errno = 0;
|
int save_errno = 0;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
@ -1426,7 +1424,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
|
|||||||
static void rollback_packed_refs(struct files_ref_store *refs)
|
static void rollback_packed_refs(struct files_ref_store *refs)
|
||||||
{
|
{
|
||||||
struct packed_ref_cache *packed_ref_cache =
|
struct packed_ref_cache *packed_ref_cache =
|
||||||
get_packed_ref_cache(refs);
|
get_packed_ref_cache(refs->packed_ref_store);
|
||||||
|
|
||||||
files_assert_main_repository(refs, "rollback_packed_refs");
|
files_assert_main_repository(refs, "rollback_packed_refs");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user