refs: accept symref values in ref_transaction_update()
The function `ref_transaction_update()` obtains ref information and flags to create a `ref_update` and add them to the transaction at hand. To extend symref support in transactions, we need to also accept the old and new ref targets and process it. This commit adds the required parameters to the function and modifies all call sites. The two parameters added are `new_target` and `old_target`. The `new_target` is used to denote what the reference should point to when the transaction is applied. Some functions allow this parameter to be NULL, meaning that the reference is not changed. The `old_target` denotes the value the reference must have before the update. Some functions allow this parameter to be NULL, meaning that the old value of the reference is not checked. We also update the internal function `ref_transaction_add_update()` similarly to take the two new parameters. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
436d4e5b14
commit
1bc4cc3fc4
22
refs.c
22
refs.c
@ -1228,6 +1228,7 @@ struct ref_update *ref_transaction_add_update(
|
||||
const char *refname, unsigned int flags,
|
||||
const struct object_id *new_oid,
|
||||
const struct object_id *old_oid,
|
||||
const char *new_target, const char *old_target,
|
||||
const char *msg)
|
||||
{
|
||||
struct ref_update *update;
|
||||
@ -1235,6 +1236,11 @@ struct ref_update *ref_transaction_add_update(
|
||||
if (transaction->state != REF_TRANSACTION_OPEN)
|
||||
BUG("update called for transaction that is not open");
|
||||
|
||||
if (old_oid && old_target)
|
||||
BUG("only one of old_oid and old_target should be non NULL");
|
||||
if (new_oid && new_target)
|
||||
BUG("only one of new_oid and new_target should be non NULL");
|
||||
|
||||
FLEX_ALLOC_STR(update, refname, refname);
|
||||
ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
|
||||
transaction->updates[transaction->nr++] = update;
|
||||
@ -1253,6 +1259,8 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const struct object_id *new_oid,
|
||||
const struct object_id *old_oid,
|
||||
const char *new_target,
|
||||
const char *old_target,
|
||||
unsigned int flags, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
@ -1280,7 +1288,8 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
||||
flags |= (new_oid ? REF_HAVE_NEW : 0) | (old_oid ? REF_HAVE_OLD : 0);
|
||||
|
||||
ref_transaction_add_update(transaction, refname, flags,
|
||||
new_oid, old_oid, msg);
|
||||
new_oid, old_oid, new_target,
|
||||
old_target, msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1295,7 +1304,8 @@ int ref_transaction_create(struct ref_transaction *transaction,
|
||||
return 1;
|
||||
}
|
||||
return ref_transaction_update(transaction, refname, new_oid,
|
||||
null_oid(), flags, msg, err);
|
||||
null_oid(), NULL, NULL, flags,
|
||||
msg, err);
|
||||
}
|
||||
|
||||
int ref_transaction_delete(struct ref_transaction *transaction,
|
||||
@ -1308,7 +1318,8 @@ int ref_transaction_delete(struct ref_transaction *transaction,
|
||||
BUG("delete called with old_oid set to zeros");
|
||||
return ref_transaction_update(transaction, refname,
|
||||
null_oid(), old_oid,
|
||||
flags, msg, err);
|
||||
NULL, NULL, flags,
|
||||
msg, err);
|
||||
}
|
||||
|
||||
int ref_transaction_verify(struct ref_transaction *transaction,
|
||||
@ -1321,6 +1332,7 @@ int ref_transaction_verify(struct ref_transaction *transaction,
|
||||
BUG("verify called with old_oid set to NULL");
|
||||
return ref_transaction_update(transaction, refname,
|
||||
NULL, old_oid,
|
||||
NULL, NULL,
|
||||
flags, NULL, err);
|
||||
}
|
||||
|
||||
@ -1335,8 +1347,8 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
|
||||
|
||||
t = ref_store_transaction_begin(refs, &err);
|
||||
if (!t ||
|
||||
ref_transaction_update(t, refname, new_oid, old_oid, flags, msg,
|
||||
&err) ||
|
||||
ref_transaction_update(t, refname, new_oid, old_oid, NULL, NULL,
|
||||
flags, msg, &err) ||
|
||||
ref_transaction_commit(t, &err)) {
|
||||
ret = 1;
|
||||
ref_transaction_free(t);
|
||||
|
Reference in New Issue
Block a user