Skip to content

Commit 8e821c3

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 25e0c5f commit 8e821c3

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

refs/files-backend.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,22 @@ static void validate_packed_ref_cache(struct packed_ref_store *refs)
404404
}
405405

406406
/*
407-
* Get the packed_ref_cache for the specified files_ref_store,
407+
* Get the packed_ref_cache for the specified packed_ref_store,
408408
* creating and populating it if it hasn't been read before or if the
409409
* file has been changed (according to its `validity` field) since it
410410
* was last read. On the other hand, if we hold the lock, then assume
411411
* that the file hasn't been changed out from under us, so skip the
412412
* extra `stat()` call in `stat_validity_check()`.
413413
*/
414-
static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
414+
static struct packed_ref_cache *get_packed_ref_cache(struct packed_ref_store *refs)
415415
{
416-
const char *packed_refs_file = refs->packed_ref_store->path;
416+
if (!is_lock_file_locked(&refs->lock))
417+
validate_packed_ref_cache(refs);
417418

418-
if (!is_lock_file_locked(&refs->packed_ref_store->lock))
419-
validate_packed_ref_cache(refs->packed_ref_store);
420-
421-
if (!refs->packed_ref_store->cache)
422-
refs->packed_ref_store->cache = read_packed_refs(packed_refs_file);
419+
if (!refs->cache)
420+
refs->cache = read_packed_refs(refs->path);
423421

424-
return refs->packed_ref_store->cache;
422+
return refs->cache;
425423
}
426424

427425
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
431429

432430
static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
433431
{
434-
return get_packed_ref_dir(get_packed_ref_cache(refs));
432+
return get_packed_ref_dir(get_packed_ref_cache(refs->packed_ref_store));
435433
}
436434

437435
/*
@@ -1151,7 +1149,7 @@ static struct ref_iterator *files_ref_iterator_begin(
11511149
loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
11521150
prefix, 1);
11531151

1154-
iter->packed_ref_cache = get_packed_ref_cache(refs);
1152+
iter->packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
11551153
acquire_packed_ref_cache(iter->packed_ref_cache);
11561154
packed_iter = cache_ref_iterator_begin(iter->packed_ref_cache->cache,
11571155
prefix, 0);
@@ -1365,7 +1363,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
13651363
*/
13661364
validate_packed_ref_cache(refs->packed_ref_store);
13671365

1368-
packed_ref_cache = get_packed_ref_cache(refs);
1366+
packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
13691367
/* Increment the reference count to prevent it from being freed: */
13701368
acquire_packed_ref_cache(packed_ref_cache);
13711369
return 0;
@@ -1380,7 +1378,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
13801378
static int commit_packed_refs(struct files_ref_store *refs)
13811379
{
13821380
struct packed_ref_cache *packed_ref_cache =
1383-
get_packed_ref_cache(refs);
1381+
get_packed_ref_cache(refs->packed_ref_store);
13841382
int ok, error = 0;
13851383
int save_errno = 0;
13861384
FILE *out;
@@ -1426,7 +1424,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
14261424
static void rollback_packed_refs(struct files_ref_store *refs)
14271425
{
14281426
struct packed_ref_cache *packed_ref_cache =
1429-
get_packed_ref_cache(refs);
1427+
get_packed_ref_cache(refs->packed_ref_store);
14301428

14311429
files_assert_main_repository(refs, "rollback_packed_refs");
14321430

0 commit comments

Comments
 (0)