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>

Michael Haggerty committed Jun 23, 2017 at 09:01 UTC 8e821c38f76c49e0e679c8d79c0b150d18aba155
1 file changed +12 -14
refs/files-backend.c
+12 -14
@@ -404,24 +404,22 @@ static void validate_packed_ref_cache(struct packed_ref_store *refs)
404 }
405
406 /*
407 - * Get the packed_ref_cache for the specified files_ref_store,
407 + * Get the packed_ref_cache for the specified packed_ref_store,
408 * creating and populating it if it hasn't been read before or if the
409 * file has been changed (according to its `validity` field) since it
410 * was last read. On the other hand, if we hold the lock, then assume
411 * that the file hasn't been changed out from under us, so skip the
412 * extra `stat()` call in `stat_validity_check()`.
413 */
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)
415 {
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);
418
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);
421
424 - return refs->packed_ref_store->cache;
422 + return refs->cache;
423 }
424
425 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
429
430 static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
431 {
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));
433 }
434
435 /*
@@ -1151,7 +1149,7 @@ static struct ref_iterator *files_ref_iterator_begin(
1149 loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
1150 prefix, 1);
1151
1154 - iter->packed_ref_cache = get_packed_ref_cache(refs);
1152 + iter->packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
1153 acquire_packed_ref_cache(iter->packed_ref_cache);
1154 packed_iter = cache_ref_iterator_begin(iter->packed_ref_cache->cache,
1155 prefix, 0);
@@ -1365,7 +1363,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1363 */
1364 validate_packed_ref_cache(refs->packed_ref_store);
1365
1368 - packed_ref_cache = get_packed_ref_cache(refs);
1366 + packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
1367 /* Increment the reference count to prevent it from being freed: */
1368 acquire_packed_ref_cache(packed_ref_cache);
1369 return 0;
@@ -1380,7 +1378,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1378 static int commit_packed_refs(struct files_ref_store *refs)
1379 {
1380 struct packed_ref_cache *packed_ref_cache =
1383 - get_packed_ref_cache(refs);
1381 + get_packed_ref_cache(refs->packed_ref_store);
1382 int ok, error = 0;
1383 int save_errno = 0;
1384 FILE *out;
@@ -1426,7 +1424,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
1424 static void rollback_packed_refs(struct files_ref_store *refs)
1425 {
1426 struct packed_ref_cache *packed_ref_cache =
1429 - get_packed_ref_cache(refs);
1427 + get_packed_ref_cache(refs->packed_ref_store);
1428
1429 files_assert_main_repository(refs, "rollback_packed_refs");
1430