lock_packed_refs(): 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 f512f0f32ced4832776ff78f5026ae87bf65f454
1 file changed +22 -9
refs/files-backend.c
+22 -9
@@ -80,6 +80,19 @@ static struct packed_ref_store *packed_ref_store_create(
80 return refs;
81 }
82
83 +/*
84 + * Die if refs is not the main ref store. caller is used in any
85 + * necessary error messages.
86 + */
87 +static void packed_assert_main_repository(struct packed_ref_store *refs,
88 + const char *caller)
89 +{
90 + if (refs->store_flags & REF_STORE_MAIN)
91 + return;
92 +
93 + die("BUG: operation %s only allowed for main ref store", caller);
94 +}
95 +
96 /*
97 * Future: need to be in "struct repository"
98 * when doing a full libification.
@@ -1334,13 +1347,13 @@ static void write_packed_entry(FILE *fh, const char *refname,
1347 * hold_lock_file_for_update(). Return 0 on success. On errors, set
1348 * errno appropriately and return a nonzero value.
1349 */
1337 -static int lock_packed_refs(struct files_ref_store *refs, int flags)
1350 +static int lock_packed_refs(struct packed_ref_store *refs, int flags)
1351 {
1352 static int timeout_configured = 0;
1353 static int timeout_value = 1000;
1354 struct packed_ref_cache *packed_ref_cache;
1355
1343 - files_assert_main_repository(refs, "lock_packed_refs");
1356 + packed_assert_main_repository(refs, "lock_packed_refs");
1357
1358 if (!timeout_configured) {
1359 git_config_get_int("core.packedrefstimeout", &timeout_value);
@@ -1348,8 +1361,8 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1361 }
1362
1363 if (hold_lock_file_for_update_timeout(
1351 - &refs->packed_ref_store->lock,
1352 - refs->packed_ref_store->path,
1364 + &refs->lock,
1365 + refs->path,
1366 flags, timeout_value) < 0)
1367 return -1;
1368
@@ -1361,9 +1374,9 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1374 * cache is still valid. We've just locked the file, but it
1375 * might have changed the moment *before* we locked it.
1376 */
1364 - validate_packed_ref_cache(refs->packed_ref_store);
1377 + validate_packed_ref_cache(refs);
1378
1366 - packed_ref_cache = get_packed_ref_cache(refs->packed_ref_store);
1379 + packed_ref_cache = get_packed_ref_cache(refs);
1380 /* Increment the reference count to prevent it from being freed: */
1381 acquire_packed_ref_cache(packed_ref_cache);
1382 return 0;
@@ -1560,7 +1573,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
1573 int ok;
1574 struct ref_to_prune *refs_to_prune = NULL;
1575
1563 - lock_packed_refs(refs, LOCK_DIE_ON_ERROR);
1576 + lock_packed_refs(refs->packed_ref_store, LOCK_DIE_ON_ERROR);
1577
1578 iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, 0);
1579 while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
@@ -1629,7 +1642,7 @@ static int repack_without_refs(struct files_ref_store *refs,
1642 if (!needs_repacking)
1643 return 0; /* no refname exists in packed refs */
1644
1632 - if (lock_packed_refs(refs, 0)) {
1645 + if (lock_packed_refs(refs->packed_ref_store, 0)) {
1646 unable_to_lock_message(refs->packed_ref_store->path, errno, err);
1647 return -1;
1648 }
@@ -3198,7 +3211,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
3211 }
3212 }
3213
3201 - if (lock_packed_refs(refs, 0)) {
3214 + if (lock_packed_refs(refs->packed_ref_store, 0)) {
3215 strbuf_addf(err, "unable to lock packed-refs file: %s",
3216 strerror(errno));
3217 ret = TRANSACTION_GENERIC_ERROR;