From: Toon Claes Date: Fri, 24 Apr 2026 12:06:24 GMT Subject: Re: [PATCH v2 7/9] refs: move object parsing to the generic layer Message-ID: <87zf2sd0lb.fsf@toon--20250203-5JQV3.mail-host-address-is-not-set> In-Reply-To: <20260423-refs-move-to-generic-layer-v2-7-ae5a4f146d7d@gmail.com> Karthik Nayak writes: > Regular reference updates made via reference transactions validate that > the provided object ID exists in the object database, which is done by > calling 'parse_object()'. This check is done independently by the > backends which leads to duplicated logic. > > Let's move this to the generic layer, ensuring the backends only have to > care about reference storage and not about validation of the object IDs. > With this also remove the 'REF_TRANSACTION_ERROR_INVALID_NEW_VALUE' > error type as its no longer used. > > Since we don't iterate over individual references in > `ref_transaction_prepare()`, we add this check to > `ref_transaction_update()`. This means that the validation is done as > soon as an update is queued, without needing to prepare the > transaction. It can be argued that this is more ideal, since this > validation has no dependency on the reference transaction being > prepared. > > It must be noted that the change in behavior means that this error > cannot be ignored even with usage of batched updates, since this happens > when the update is being added to the transaction. But since the caller > gets specific error codes, they can either abort the transaction or > continue adding other updates to the transaction. > > Modify 'builtin/receive-pack.c' to now capture the error type so that > the error propagated to the client stays the same. Also remove two of > the tests which validates batch-updates with invalid new_oid. > > Signed-off-by: Karthik Nayak > --- > builtin/receive-pack.c | 22 +++++++++++++--------- > refs.c | 18 ++++++++++++++++++ > refs/files-backend.c | 28 ++-------------------------- > refs/reftable-backend.c | 19 ------------------- > 4 files changed, 33 insertions(+), 54 deletions(-) > > diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c > index 878aa7f0ed..0fb3d57de8 100644 > --- a/builtin/receive-pack.c > +++ b/builtin/receive-pack.c > @@ -1641,8 +1641,8 @@ static const char *update(struct command *cmd, struct shallow_info *si) > ret = NULL; /* good */ > } > strbuf_release(&err); > - } > - else { > + } else { > + enum ref_transaction_error err_type; Shall we also use `tx_err` like in builtin/update-ref.c? > diff --git a/refs.c b/refs.c > index efa16b739d..662a9e6f9e 100644 > --- a/refs.c > +++ b/refs.c > @@ -1416,6 +1416,24 @@ enum ref_transaction_error ref_transaction_update(struct ref_transaction *transa > flags |= (new_oid ? REF_HAVE_NEW : 0) | (old_oid ? REF_HAVE_OLD : 0); > flags |= (new_target ? REF_HAVE_NEW : 0) | (old_target ? REF_HAVE_OLD : 0); > > + if ((flags & REF_HAVE_NEW) && !new_target && !is_null_oid(new_oid) && > + !(flags & REF_SKIP_OID_VERIFICATION) && !(flags & REF_LOG_ONLY)) { Compared to the version we used to have in refs/reftable-backend.c, you've added `!new_target`. Why is that? If I understand correctly, that only happens when `new_oid` is set. Wouldn't `!is_null_oid(new_oid)` guard for that? -- Cheers, Toon