refs/files: use correct repository

There are several places in the "files" backend where we use `the_repository` instead of the repository associated with the ref store itself. Adapt those to use the correct repository. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed May 17, 2024 at 10:19 UTC c9e9723e1fc6c655420d438c33a4e276d00ff2c9
1 file changed +13 -10
refs/files-backend.c
+13 -10
@@ -1237,7 +1237,8 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_
1237 /*
1238 * Return true if the specified reference should be packed.
1239 */
1240 -static int should_pack_ref(const char *refname,
1240 +static int should_pack_ref(struct files_ref_store *refs,
1241 + const char *refname,
1242 const struct object_id *oid, unsigned int ref_flags,
1243 struct pack_refs_opts *opts)
1244 {
@@ -1253,7 +1254,7 @@ static int should_pack_ref(const char *refname,
1254 return 0;
1255
1256 /* Do not pack broken refs: */
1256 - if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
1257 + if (!ref_resolves_to_object(refname, refs->base.repo, oid, ref_flags))
1258 return 0;
1259
1260 if (ref_excluded(opts->exclusions, refname))
@@ -1285,14 +1286,14 @@ static int files_pack_refs(struct ref_store *ref_store,
1286 packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err);
1287
1288 iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, 0), NULL,
1288 - the_repository, 0);
1289 + refs->base.repo, 0);
1290 while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
1291 /*
1292 * If the loose reference can be packed, add an entry
1293 * in the packed ref cache. If the reference should be
1294 * pruned, also add it to refs_to_prune.
1295 */
1295 - if (!should_pack_ref(iter->refname, iter->oid, iter->flags, opts))
1296 + if (!should_pack_ref(refs, iter->refname, iter->oid, iter->flags, opts))
1297 continue;
1298
1299 /*
@@ -1389,7 +1390,8 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
1390 return ret;
1391 }
1392
1392 -static int write_ref_to_lockfile(struct ref_lock *lock,
1393 +static int write_ref_to_lockfile(struct files_ref_store *refs,
1394 + struct ref_lock *lock,
1395 const struct object_id *oid,
1396 int skip_oid_verification, struct strbuf *err);
1397 static int commit_ref_update(struct files_ref_store *refs,
@@ -1537,7 +1539,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1539 }
1540 oidcpy(&lock->old_oid, &orig_oid);
1541
1540 - if (write_ref_to_lockfile(lock, &orig_oid, 0, &err) ||
1542 + if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) ||
1543 commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) {
1544 error("unable to write current sha1 into %s: %s", newrefname, err.buf);
1545 strbuf_release(&err);
@@ -1557,7 +1559,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1559
1560 flag = log_all_ref_updates;
1561 log_all_ref_updates = LOG_REFS_NONE;
1560 - if (write_ref_to_lockfile(lock, &orig_oid, 0, &err) ||
1562 + if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) ||
1563 commit_ref_update(refs, lock, &orig_oid, NULL, &err)) {
1564 error("unable to write current sha1 into %s: %s", oldrefname, err.buf);
1565 strbuf_release(&err);
@@ -1791,7 +1793,8 @@ static int files_log_ref_write(struct files_ref_store *refs,
1793 * Write oid into the open lockfile, then close the lockfile. On
1794 * errors, rollback the lockfile, fill in *err and return -1.
1795 */
1794 -static int write_ref_to_lockfile(struct ref_lock *lock,
1796 +static int write_ref_to_lockfile(struct files_ref_store *refs,
1797 + struct ref_lock *lock,
1798 const struct object_id *oid,
1799 int skip_oid_verification, struct strbuf *err)
1800 {
@@ -1800,7 +1803,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
1803 int fd;
1804
1805 if (!skip_oid_verification) {
1803 - o = parse_object(the_repository, oid);
1806 + o = parse_object(refs->base.repo, oid);
1807 if (!o) {
1808 strbuf_addf(
1809 err,
@@ -2571,7 +2574,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2574 * value, so we don't need to write it.
2575 */
2576 } else if (write_ref_to_lockfile(
2574 - lock, &update->new_oid,
2577 + refs, lock, &update->new_oid,
2578 update->flags & REF_SKIP_OID_VERIFICATION,
2579 err)) {
2580 char *write_err = strbuf_detach(err, NULL);