update = ref_transaction_add_update(transaction, refname, flags,
new_oid, old_oid, NULL, NULL,
committer_info, msg);
- /*
- * While we do set the old_oid value, we unset the flag to skip
- * old_oid verification which only makes sense for refs.
- */
- update->flags &= ~REF_HAVE_OLD;
update->index = index;
/*
int ref_update_expects_existing_old_ref(struct ref_update *update)
{
+ if (update->flags & REF_LOG_ONLY)
+ return 0;
+
return (update->flags & REF_HAVE_OLD) &&
(!is_null_oid(&update->old_oid) || update->old_target);
}
* done when new_update is processed.
*/
update->flags |= REF_LOG_ONLY | REF_NO_DEREF;
- update->flags &= ~REF_HAVE_OLD;
return 0;
}
struct object_id *oid,
struct strbuf *err)
{
- if (!(update->flags & REF_HAVE_OLD) ||
- oideq(oid, &update->old_oid))
+ if (update->flags & REF_LOG_ONLY ||
+ !(update->flags & REF_HAVE_OLD) ||
+ oideq(oid, &update->old_oid))
return 0;
if (is_null_oid(&update->old_oid)) {
for (i = 0; i < transaction->nr; i++) {
struct ref_update *update = transaction->updates[i];
- if ((update->flags & REF_HAVE_OLD) &&
+ if (!(update->flags & REF_LOG_ONLY) &&
+ (update->flags & REF_HAVE_OLD) &&
!is_null_oid(&update->old_oid))
BUG("initial ref transaction with old_sha1 set");
/*
* Check if the ref must exist, this means that the old_oid or
- * old_target is non NULL.
+ * old_target is non NULL. Log-only updates never require the old state to
+ * match.
*/
int ref_update_expects_existing_old_ref(struct ref_update *update);
if (ret > 0) {
/* The reference does not exist, but we expected it to. */
strbuf_addf(err, _("cannot lock ref '%s': "
-
-
"unable to resolve reference '%s'"),
ref_update_original_update_refname(u), u->refname);
return REF_TRANSACTION_ERROR_NONEXISTENT_REF;
new_update->parent_update = u;
- /*
- * Change the symbolic ref update to log only. Also, it
- * doesn't need to check its old OID value, as that will be
- * done when new_update is processed.
- */
+ /* Change the symbolic ref update to log only. */
u->flags |= REF_LOG_ONLY | REF_NO_DEREF;
- u->flags &= ~REF_HAVE_OLD;
}
}
ret = ref_update_check_old_target(referent->buf, u, err);
if (ret)
return ret;
- } else if ((u->flags & REF_HAVE_OLD) && !oideq(¤t_oid, &u->old_oid)) {
+ } else if ((u->flags & (REF_LOG_ONLY | REF_HAVE_OLD)) == REF_HAVE_OLD &&
+ !oideq(¤t_oid, &u->old_oid)) {
if (is_null_oid(&u->old_oid)) {
strbuf_addf(err, _("cannot lock ref '%s': "
"reference already exists"),