{lock,commit,rollback}_packed_refs(): add files_ref_store arguments

These functions currently only work in the main repository, so add an assert_main_repository() check to each function. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Sep 4, 2016 at 18:08 UTC 49c0df6a68c6c02a75e306c34e4e9d2bfa645892
1 file changed +16 -16
refs/files-backend.c
+16 -16
@@ -2215,14 +2215,14 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
2215 * hold_lock_file_for_update(). Return 0 on success. On errors, set
2216 * errno appropriately and return a nonzero value.
2217 */
2218 -static int lock_packed_refs(int flags)
2218 +static int lock_packed_refs(struct files_ref_store *refs, int flags)
2219 {
2220 - struct files_ref_store *refs =
2221 - get_files_ref_store(NULL, "lock_packed_refs");
2220 static int timeout_configured = 0;
2221 static int timeout_value = 1000;
2222 struct packed_ref_cache *packed_ref_cache;
2223
2224 + assert_main_repository(&refs->base, "lock_packed_refs");
2225 +
2226 if (!timeout_configured) {
2227 git_config_get_int("core.packedrefstimeout", &timeout_value);
2228 timeout_configured = 1;
@@ -2251,16 +2251,16 @@ static int lock_packed_refs(int flags)
2251 * lock_packed_refs()). Return zero on success. On errors, set errno
2252 * and return a nonzero value
2253 */
2254 -static int commit_packed_refs(void)
2254 +static int commit_packed_refs(struct files_ref_store *refs)
2255 {
2256 - struct files_ref_store *refs =
2257 - get_files_ref_store(NULL, "commit_packed_refs");
2256 struct packed_ref_cache *packed_ref_cache =
2257 get_packed_ref_cache(refs);
2258 int error = 0;
2259 int save_errno = 0;
2260 FILE *out;
2261
2262 + assert_main_repository(&refs->base, "commit_packed_refs");
2263 +
2264 if (!packed_ref_cache->lock)
2265 die("internal error: packed-refs not locked");
2266
@@ -2287,13 +2287,13 @@ static int commit_packed_refs(void)
2287 * in-memory packed reference cache. (The packed-refs file will be
2288 * read anew if it is needed again after this function is called.)
2289 */
2290 -static void rollback_packed_refs(void)
2290 +static void rollback_packed_refs(struct files_ref_store *refs)
2291 {
2292 - struct files_ref_store *refs =
2293 - get_files_ref_store(NULL, "rollback_packed_refs");
2292 struct packed_ref_cache *packed_ref_cache =
2293 get_packed_ref_cache(refs);
2294
2295 + assert_main_repository(&refs->base, "rollback_packed_refs");
2296 +
2297 if (!packed_ref_cache->lock)
2298 die("internal error: packed-refs not locked");
2299 rollback_lock_file(packed_ref_cache->lock);
@@ -2439,13 +2439,13 @@ int pack_refs(unsigned int flags)
2439 memset(&cbdata, 0, sizeof(cbdata));
2440 cbdata.flags = flags;
2441
2442 - lock_packed_refs(LOCK_DIE_ON_ERROR);
2442 + lock_packed_refs(refs, LOCK_DIE_ON_ERROR);
2443 cbdata.packed_refs = get_packed_refs(refs);
2444
2445 do_for_each_entry_in_dir(get_loose_refs(refs), 0,
2446 pack_if_possible_fn, &cbdata);
2447
2448 - if (commit_packed_refs())
2448 + if (commit_packed_refs(refs))
2449 die_errno("unable to overwrite old ref-pack file");
2450
2451 prune_refs(cbdata.ref_to_prune);
@@ -2481,7 +2481,7 @@ static int repack_without_refs(struct string_list *refnames, struct strbuf *err)
2481 if (!needs_repacking)
2482 return 0; /* no refname exists in packed refs */
2483
2484 - if (lock_packed_refs(0)) {
2484 + if (lock_packed_refs(refs, 0)) {
2485 unable_to_lock_message(git_path("packed-refs"), errno, err);
2486 return -1;
2487 }
@@ -2496,12 +2496,12 @@ static int repack_without_refs(struct string_list *refnames, struct strbuf *err)
2496 * All packed entries disappeared while we were
2497 * acquiring the lock.
2498 */
2499 - rollback_packed_refs();
2499 + rollback_packed_refs(refs);
2500 return 0;
2501 }
2502
2503 /* Write what remains */
2504 - ret = commit_packed_refs();
2504 + ret = commit_packed_refs(refs);
2505 if (ret)
2506 strbuf_addf(err, "unable to overwrite old ref-pack file: %s",
2507 strerror(errno));
@@ -3919,7 +3919,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
3919 }
3920 }
3921
3922 - if (lock_packed_refs(0)) {
3922 + if (lock_packed_refs(refs, 0)) {
3923 strbuf_addf(err, "unable to lock packed-refs file: %s",
3924 strerror(errno));
3925 ret = TRANSACTION_GENERIC_ERROR;
@@ -3934,7 +3934,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
3934 add_packed_ref(refs, update->refname, update->new_sha1);
3935 }
3936
3937 - if (commit_packed_refs()) {
3937 + if (commit_packed_refs(refs)) {
3938 strbuf_addf(err, "unable to commit packed-refs file: %s",
3939 strerror(errno));
3940 ret = TRANSACTION_GENERIC_ERROR;