files-backend: avoid ref api targeting main ref store
A small step towards making files-backend work 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 default 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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c0fe4e8ba3
commit
2f40e95472
@ -1829,8 +1829,6 @@ static int files_peel_ref(struct ref_store *ref_store,
|
|||||||
int flag;
|
int flag;
|
||||||
unsigned char base[20];
|
unsigned char base[20];
|
||||||
|
|
||||||
files_assert_main_repository(refs, "peel_ref");
|
|
||||||
|
|
||||||
if (current_ref_iter && current_ref_iter->refname == refname) {
|
if (current_ref_iter && current_ref_iter->refname == refname) {
|
||||||
struct object_id peeled;
|
struct object_id peeled;
|
||||||
|
|
||||||
@ -1840,7 +1838,8 @@ static int files_peel_ref(struct ref_store *ref_store,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_ref_full(refname, RESOLVE_REF_READING, base, &flag))
|
if (refs_read_ref_full(ref_store, refname,
|
||||||
|
RESOLVE_REF_READING, base, &flag))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2008,13 +2007,13 @@ static struct ref_iterator *files_ref_iterator_begin(
|
|||||||
* on success. On error, write an error message to err, set errno, and
|
* on success. On error, write an error message to err, set errno, and
|
||||||
* return a negative value.
|
* 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,
|
const unsigned char *old_sha1, int mustexist,
|
||||||
struct strbuf *err)
|
struct strbuf *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
assert(err);
|
||||||
|
|
||||||
if (read_ref_full(lock->ref_name,
|
if (refs_read_ref_full(ref_store, lock->ref_name,
|
||||||
mustexist ? RESOLVE_REF_READING : 0,
|
mustexist ? RESOLVE_REF_READING : 0,
|
||||||
lock->old_oid.hash, NULL)) {
|
lock->old_oid.hash, NULL)) {
|
||||||
if (old_sha1) {
|
if (old_sha1) {
|
||||||
@ -2085,7 +2084,8 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
|
|||||||
resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
|
resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
|
||||||
|
|
||||||
files_ref_path(refs, &ref_file, refname);
|
files_ref_path(refs, &ref_file, refname);
|
||||||
resolved = !!resolve_ref_unsafe(refname, resolve_flags,
|
resolved = !!refs_resolve_ref_unsafe(&refs->base,
|
||||||
|
refname, resolve_flags,
|
||||||
lock->old_oid.hash, type);
|
lock->old_oid.hash, type);
|
||||||
if (!resolved && errno == EISDIR) {
|
if (!resolved && errno == EISDIR) {
|
||||||
/*
|
/*
|
||||||
@ -2103,7 +2103,8 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
|
|||||||
refname);
|
refname);
|
||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
resolved = !!resolve_ref_unsafe(refname, resolve_flags,
|
resolved = !!refs_resolve_ref_unsafe(&refs->base,
|
||||||
|
refname, resolve_flags,
|
||||||
lock->old_oid.hash, type);
|
lock->old_oid.hash, type);
|
||||||
}
|
}
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
@ -2142,7 +2143,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
|
|||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verify_lock(lock, old_sha1, mustexist, err)) {
|
if (verify_lock(&refs->base, lock, old_sha1, mustexist, err)) {
|
||||||
last_errno = errno;
|
last_errno = errno;
|
||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
@ -2397,7 +2398,7 @@ static void try_remove_empty_parents(struct files_ref_store *refs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* make sure nobody touched the ref, and unlink */
|
/* 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 ref_transaction *transaction;
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
@ -2405,7 +2406,7 @@ static void prune_ref(struct ref_to_prune *r)
|
|||||||
if (check_refname_format(r->name, 0))
|
if (check_refname_format(r->name, 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
transaction = ref_transaction_begin(&err);
|
transaction = ref_store_transaction_begin(&refs->base, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_delete(transaction, r->name, r->sha1,
|
ref_transaction_delete(transaction, r->name, r->sha1,
|
||||||
REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
|
REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
|
||||||
@ -2419,10 +2420,10 @@ static void prune_ref(struct ref_to_prune *r)
|
|||||||
strbuf_release(&err);
|
strbuf_release(&err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prune_refs(struct ref_to_prune *r)
|
static void prune_refs(struct files_ref_store *refs, struct ref_to_prune *r)
|
||||||
{
|
{
|
||||||
while (r) {
|
while (r) {
|
||||||
prune_ref(r);
|
prune_ref(refs, r);
|
||||||
r = r->next;
|
r = r->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2446,7 +2447,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
|
|||||||
if (commit_packed_refs(refs))
|
if (commit_packed_refs(refs))
|
||||||
die_errno("unable to overwrite old ref-pack file");
|
die_errno("unable to overwrite old ref-pack file");
|
||||||
|
|
||||||
prune_refs(cbdata.ref_to_prune);
|
prune_refs(refs, cbdata.ref_to_prune);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2538,7 +2539,7 @@ static int files_delete_refs(struct ref_store *ref_store,
|
|||||||
for (i = 0; i < refnames->nr; i++) {
|
for (i = 0; i < refnames->nr; i++) {
|
||||||
const char *refname = refnames->items[i].string;
|
const char *refname = refnames->items[i].string;
|
||||||
|
|
||||||
if (delete_ref(NULL, refname, NULL, flags))
|
if (refs_delete_ref(&refs->base, NULL, refname, NULL, flags))
|
||||||
result |= error(_("could not remove reference %s"), refname);
|
result |= error(_("could not remove reference %s"), refname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2660,7 +2661,8 @@ static int files_rename_ref(struct ref_store *ref_store,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resolve_ref_unsafe(oldrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
|
||||||
|
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
||||||
orig_sha1, &flag)) {
|
orig_sha1, &flag)) {
|
||||||
ret = error("refname %s not found", oldrefname);
|
ret = error("refname %s not found", oldrefname);
|
||||||
goto out;
|
goto out;
|
||||||
@ -2682,7 +2684,8 @@ static int files_rename_ref(struct ref_store *ref_store,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delete_ref(logmsg, oldrefname, orig_sha1, REF_NODEREF)) {
|
if (refs_delete_ref(&refs->base, logmsg, oldrefname,
|
||||||
|
orig_sha1, REF_NODEREF)) {
|
||||||
error("unable to delete old %s", oldrefname);
|
error("unable to delete old %s", oldrefname);
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
}
|
||||||
@ -2694,9 +2697,11 @@ static int files_rename_ref(struct ref_store *ref_store,
|
|||||||
* the safety anyway; we want to delete the reference whatever
|
* the safety anyway; we want to delete the reference whatever
|
||||||
* its current value.
|
* its current value.
|
||||||
*/
|
*/
|
||||||
if (!read_ref_full(newrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
if (!refs_read_ref_full(&refs->base, newrefname,
|
||||||
|
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
||||||
sha1, NULL) &&
|
sha1, NULL) &&
|
||||||
delete_ref(NULL, newrefname, NULL, REF_NODEREF)) {
|
refs_delete_ref(&refs->base, NULL, newrefname,
|
||||||
|
NULL, REF_NODEREF)) {
|
||||||
if (errno == EISDIR) {
|
if (errno == EISDIR) {
|
||||||
struct strbuf path = STRBUF_INIT;
|
struct strbuf path = STRBUF_INIT;
|
||||||
int result;
|
int result;
|
||||||
@ -3052,7 +3057,8 @@ static int commit_ref_update(struct files_ref_store *refs,
|
|||||||
int head_flag;
|
int head_flag;
|
||||||
const char *head_ref;
|
const char *head_ref;
|
||||||
|
|
||||||
head_ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
|
head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD",
|
||||||
|
RESOLVE_REF_READING,
|
||||||
head_sha1, &head_flag);
|
head_sha1, &head_flag);
|
||||||
if (head_ref && (head_flag & REF_ISSYMREF) &&
|
if (head_ref && (head_flag & REF_ISSYMREF) &&
|
||||||
!strcmp(head_ref, lock->ref_name)) {
|
!strcmp(head_ref, lock->ref_name)) {
|
||||||
@ -3097,7 +3103,9 @@ static void update_symref_reflog(struct files_ref_store *refs,
|
|||||||
{
|
{
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
unsigned char new_sha1[20];
|
unsigned char new_sha1[20];
|
||||||
if (logmsg && !read_ref(target, new_sha1) &&
|
if (logmsg &&
|
||||||
|
!refs_read_ref_full(&refs->base, target,
|
||||||
|
RESOLVE_REF_READING, new_sha1, NULL) &&
|
||||||
files_log_ref_write(refs, refname, lock->old_oid.hash,
|
files_log_ref_write(refs, refname, lock->old_oid.hash,
|
||||||
new_sha1, logmsg, 0, &err)) {
|
new_sha1, logmsg, 0, &err)) {
|
||||||
error("%s", err.buf);
|
error("%s", err.buf);
|
||||||
@ -3402,6 +3410,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
|
|||||||
struct files_reflog_iterator {
|
struct files_reflog_iterator {
|
||||||
struct ref_iterator base;
|
struct ref_iterator base;
|
||||||
|
|
||||||
|
struct ref_store *ref_store;
|
||||||
struct dir_iterator *dir_iterator;
|
struct dir_iterator *dir_iterator;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
};
|
};
|
||||||
@ -3423,7 +3432,8 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
|
|||||||
if (ends_with(diter->basename, ".lock"))
|
if (ends_with(diter->basename, ".lock"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (read_ref_full(diter->relative_path, 0,
|
if (refs_read_ref_full(iter->ref_store,
|
||||||
|
diter->relative_path, 0,
|
||||||
iter->oid.hash, &flags)) {
|
iter->oid.hash, &flags)) {
|
||||||
error("bad ref for %s", diter->path.buf);
|
error("bad ref for %s", diter->path.buf);
|
||||||
continue;
|
continue;
|
||||||
@ -3478,6 +3488,7 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
|
|||||||
base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable);
|
base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable);
|
||||||
files_reflog_path(refs, &sb, NULL);
|
files_reflog_path(refs, &sb, NULL);
|
||||||
iter->dir_iterator = dir_iterator_begin(sb.buf);
|
iter->dir_iterator = dir_iterator_begin(sb.buf);
|
||||||
|
iter->ref_store = ref_store;
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
return ref_iterator;
|
return ref_iterator;
|
||||||
}
|
}
|
||||||
@ -3717,7 +3728,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
* the transaction, so we have to read it here
|
* the transaction, so we have to read it here
|
||||||
* to record and possibly check old_sha1:
|
* to record and possibly check old_sha1:
|
||||||
*/
|
*/
|
||||||
if (read_ref_full(referent.buf, 0,
|
if (refs_read_ref_full(&refs->base,
|
||||||
|
referent.buf, 0,
|
||||||
lock->old_oid.hash, NULL)) {
|
lock->old_oid.hash, NULL)) {
|
||||||
if (update->flags & REF_HAVE_OLD) {
|
if (update->flags & REF_HAVE_OLD) {
|
||||||
strbuf_addf(err, "cannot lock ref '%s': "
|
strbuf_addf(err, "cannot lock ref '%s': "
|
||||||
@ -3872,7 +3884,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
* head_ref within the transaction, then split_head_update()
|
* head_ref within the transaction, then split_head_update()
|
||||||
* arranges for the reflog of HEAD to be updated, too.
|
* arranges for the reflog of HEAD to be updated, too.
|
||||||
*/
|
*/
|
||||||
head_ref = resolve_refdup("HEAD", RESOLVE_REF_NO_RECURSE,
|
head_ref = refs_resolve_refdup(ref_store, "HEAD",
|
||||||
|
RESOLVE_REF_NO_RECURSE,
|
||||||
head_oid.hash, &head_type);
|
head_oid.hash, &head_type);
|
||||||
|
|
||||||
if (head_ref && !(head_type & REF_ISSYMREF)) {
|
if (head_ref && !(head_type & REF_ISSYMREF)) {
|
||||||
@ -4046,7 +4059,8 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
|
|||||||
* so here we really only check that none of the references
|
* so here we really only check that none of the references
|
||||||
* that we are creating already exists.
|
* that we are creating already exists.
|
||||||
*/
|
*/
|
||||||
if (for_each_rawref(ref_present, &affected_refnames))
|
if (refs_for_each_rawref(&refs->base, ref_present,
|
||||||
|
&affected_refnames))
|
||||||
die("BUG: initial ref transaction called with existing refs");
|
die("BUG: initial ref transaction called with existing refs");
|
||||||
|
|
||||||
for (i = 0; i < transaction->nr; i++) {
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
@ -4165,7 +4179,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
|
|||||||
strbuf_release(&err);
|
strbuf_release(&err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!reflog_exists(refname)) {
|
if (!refs_reflog_exists(ref_store, refname)) {
|
||||||
unlock_ref(lock);
|
unlock_ref(lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -4196,7 +4210,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
|
|||||||
}
|
}
|
||||||
|
|
||||||
(*prepare_fn)(refname, sha1, cb.policy_cb);
|
(*prepare_fn)(refname, sha1, cb.policy_cb);
|
||||||
for_each_reflog_ent(refname, expire_reflog_ent, &cb);
|
refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb);
|
||||||
(*cleanup_fn)(cb.policy_cb);
|
(*cleanup_fn)(cb.policy_cb);
|
||||||
|
|
||||||
if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) {
|
if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user