A small step towards making files-backend works as a non-main ref store
using the newly added store-aware API.
For the record, `join` and `nm` on refs.o and files-backend.o tell me
that files-backend no longer uses functions that defaults to
get_main_ref_store().
I'm not yet comfortable at the idea of removing
files_assert_main_repository() (or converting REF_STORE_MAIN to
REF_STORE_WRITE). More staring and testing is required before that can
happen. Well, except peel_ref(). I'm pretty sure that function is safe.
Signed-off-by: Nguyễn Thái Ngọc Duy
---
refs/files-backend.c | 84 ++--
1 file changed, 49 insertions(+), 35 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index dec8540a0f..a5b405436f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1830,8 +1830,6 @@ static int files_peel_ref(struct ref_store *ref_store,
int flag;
unsigned char base[20];
- files_assert_main_repository(refs, "peel_ref");
-
if (current_ref_iter && current_ref_iter->refname == refname) {
struct object_id peeled;
@@ -1841,7 +1839,8 @@ static int files_peel_ref(struct ref_store *ref_store,
return 0;
}
- if (read_ref_full(refname, RESOLVE_REF_READING, base, ))
+ if (refs_read_ref_full(ref_store, refname,
+ RESOLVE_REF_READING, base, ))
return -1;
/*
@@ -2009,15 +2008,15 @@ static struct ref_iterator *files_ref_iterator_begin(
* on success. On error, write an error message to err, set errno, and
* return a negative value.
*/
-static int verify_lock(struct ref_lock *lock,
+static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
const unsigned char *old_sha1, int mustexist,
struct strbuf *err)
{
assert(err);
- if (read_ref_full(lock->ref_name,
- mustexist ? RESOLVE_REF_READING : 0,
- lock->old_oid.hash, NULL)) {
+ if (refs_read_ref_full(ref_store, lock->ref_name,
+ mustexist ? RESOLVE_REF_READING : 0,
+ lock->old_oid.hash, NULL)) {
if (old_sha1) {
int save_errno = errno;
strbuf_addf(err, "can't verify ref '%s'",
lock->ref_name);
@@ -2086,8 +2085,9 @@ static struct ref_lock *lock_ref_sha1_basic(struct
files_ref_store *refs,
resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
files_ref_path(refs, _file, refname);
- resolved = !!resolve_ref_unsafe(refname, resolve_flags,
- lock->old_oid.hash, type);
+ resolved = !!refs_resolve_ref_unsafe(>base,
+refname, resolve_flags,
+lock->old_oid.hash, type);
if (!resolved && errno == EISDIR) {
/*
* we are trying to lock foo but we used to
@@ -2104,8 +2104,9 @@ static struct ref_lock *lock_ref_sha1_basic(struct
files_ref_store *refs,
refname);
goto error_return;
}
- resolved = !!resolve_ref_unsafe(refname, resolve_flags,
- lock->old_oid.hash, type);
+ resolved = !!refs_resolve_ref_unsafe(>base,
+refname, resolve_flags,
+lock->old_oid.hash, type);
}
if (!resolved) {
last_errno = errno;
@@ -2143,7 +2144,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct
files_ref_store *refs,
goto error_return;
}
- if (verify_lock(lock, old_sha1, mustexist, err)) {
+ if (verify_lock(>base, lock, old_sha1, mustexist, err)) {
last_errno = errno;
goto error_return;
}
@@ -2398,7 +2399,7 @@ static void try_remove_empty_parents(struct
files_ref_store *refs,
}
/* make sure nobody touched the ref, and unlink */
-static void prune_ref(struct ref_to_prune *r)
+static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
{
struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT;
@@ -2406,7 +2407,7 @@ static void prune_ref(struct ref_to_prune *r)
if (check_refname_format(r->name, 0))
return;
- transaction = ref_transaction_begin();
+ transaction = ref_store_transaction_begin(>base, );
if (!transaction ||
ref_transaction_delete(transaction, r->name, r->sha1,
REF_ISPRUNING | REF_NODEREF, NULL, ) ||
@@ -2420,10 +2421,10 @@ static void prune_ref(struct ref_to_prune *r)
strbuf_release();
}
-static void