@ -630,16 +630,20 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
@@ -630,16 +630,20 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
return 0;
}
int delete_ref(const char *msg, const char *refname,
const unsigned char *old_sha1, unsigned int flags)
int refs_delete_ref(struct ref_store *refs, const char *msg,
const char *refname,
const unsigned char *old_sha1,
unsigned int flags)
{
struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT;
if (ref_type(refname) == REF_TYPE_PSEUDOREF)
if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
assert(refs == get_main_ref_store());
return delete_pseudoref(refname, old_sha1);
}
transaction = ref_transaction_begin(&err);
transaction = ref_store_transaction_begin(refs, &err);
if (!transaction ||
ref_transaction_delete(transaction, refname, old_sha1,
flags, msg, &err) ||
@ -654,6 +658,13 @@ int delete_ref(const char *msg, const char *refname,
@@ -654,6 +658,13 @@ int delete_ref(const char *msg, const char *refname,
return 0;
}
int delete_ref(const char *msg, const char *refname,
const unsigned char *old_sha1, unsigned int flags)
{
return refs_delete_ref(get_main_ref_store(), msg, refname,
old_sha1, flags);
}
int copy_reflog_msg(char *buf, const char *msg)
{
char *cp = buf;
@ -813,11 +824,20 @@ int read_ref_at(const char *refname, unsigned int flags, unsigned long at_time,
@@ -813,11 +824,20 @@ int read_ref_at(const char *refname, unsigned int flags, unsigned long at_time,
return 1;
}
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
struct strbuf *err)
{
struct ref_transaction *tr;
assert(err);
return xcalloc(1, sizeof(struct ref_transaction));
tr = xcalloc(1, sizeof(struct ref_transaction));
tr->ref_store = refs;
return tr;
}
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
{
return ref_store_transaction_begin(get_main_ref_store(), err);
}
void ref_transaction_free(struct ref_transaction *transaction)
@ -934,18 +954,20 @@ int update_ref_oid(const char *msg, const char *refname,
@@ -934,18 +954,20 @@ int update_ref_oid(const char *msg, const char *refname,
old_oid ? old_oid->hash : NULL, flags, onerr);
}
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1, const unsigned char *old_sha1,
unsigned int flags, enum action_on_err onerr)
int refs_update_ref(struct ref_store *refs, const char *msg,
const char *refname, const unsigned char *new_sha1,
const unsigned char *old_sha1, unsigned int flags,
enum action_on_err onerr)
{
struct ref_transaction *t = NULL;
struct strbuf err = STRBUF_INIT;
int ret = 0;
if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
assert(refs == get_main_ref_store());
ret = write_pseudoref(refname, new_sha1, old_sha1, &err);
} else {
t = ref_transaction_begin(&err);
t = ref_store_transaction_begin(refs, &err);
if (!t ||
ref_transaction_update(t, refname, new_sha1, old_sha1,
flags, msg, &err) ||
@ -976,6 +998,15 @@ int update_ref(const char *msg, const char *refname,
@@ -976,6 +998,15 @@ int update_ref(const char *msg, const char *refname,
return 0;
}
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1,
const unsigned char *old_sha1,
unsigned int flags, enum action_on_err onerr)
{
return refs_update_ref(get_main_ref_store(), msg, refname, new_sha1,
old_sha1, flags, onerr);
}
char *shorten_unambiguous_ref(const char *refname, int strict)
{
int i;
@ -1607,7 +1638,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
@@ -1607,7 +1638,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
int ref_transaction_commit(struct ref_transaction *transaction,
struct strbuf *err)
{
struct ref_store *refs = get_main_ref_store();
struct ref_store *refs = transaction->ref_store;
return refs->be->transaction_commit(refs, transaction, err);
}
@ -1726,7 +1757,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
@@ -1726,7 +1757,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
int initial_ref_transaction_commit(struct ref_transaction *transaction,
struct strbuf *err)
{
struct ref_store *refs = get_main_ref_store();
struct ref_store *refs = transaction->ref_store;
return refs->be->initial_transaction_commit(refs, transaction, err);
}