refs: return `ref_transaction_error` from `ref_transaction_update()`
The `ref_transaction_update()` function is used to add updates to a given reference transactions. In the following commit, we'll add more validation to this function. As such, it would be beneficial if the function returns specific error types, so callers can differentiate between different errors. To facilitate this, return `enum ref_transaction_error` from the function and covert the existing '-1' returns to 'REF_TRANSACTION_ERROR_GENERIC'. Since this retains the existing behavior, no changes are made to any of the callers but this sets the necessary infrastructure for introduction of other errors. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
May 4, 2026 at 19:44 UTC
e99e98e600181ddf431b267c2887358b3556e45c
2 files changed
+18
-18
refs.c
+10
-10
@@ -1383,25 +1383,25 @@ static int transaction_refname_valid(const char *refname,
1383
return 1;
1384
}
1385
1386
-int ref_transaction_update(struct ref_transaction *transaction,
1387
- const char *refname,
1388
- const struct object_id *new_oid,
1389
- const struct object_id *old_oid,
1390
- const char *new_target,
1391
- const char *old_target,
1392
- unsigned int flags, const char *msg,
1393
- struct strbuf *err)
1386
+enum ref_transaction_error ref_transaction_update(struct ref_transaction *transaction,
1387
+ const char *refname,
1388
+ const struct object_id *new_oid,
1389
+ const struct object_id *old_oid,
1390
+ const char *new_target,
1391
+ const char *old_target,
1392
+ unsigned int flags, const char *msg,
1393
+ struct strbuf *err)
1394
{
1395
assert(err);
1396
1397
if ((flags & REF_FORCE_CREATE_REFLOG) &&
1398
(flags & REF_SKIP_CREATE_REFLOG)) {
1399
strbuf_addstr(err, _("refusing to force and skip creation of reflog"));
1400
- return -1;
1400
+ return REF_TRANSACTION_ERROR_GENERIC;
1401
}
1402
1403
if (!transaction_refname_valid(refname, new_oid, flags, err))
1404
- return -1;
1404
+ return REF_TRANSACTION_ERROR_GENERIC;
1405
1406
if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS)
1407
BUG("illegal flags 0x%x passed to ref_transaction_update()", flags);
refs.h
+8
-8
@@ -905,14 +905,14 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
905
* See the above comment "Reference transaction updates" for more
906
* information.
907
*/
908
-int ref_transaction_update(struct ref_transaction *transaction,
909
- const char *refname,
910
- const struct object_id *new_oid,
911
- const struct object_id *old_oid,
912
- const char *new_target,
913
- const char *old_target,
914
- unsigned int flags, const char *msg,
915
- struct strbuf *err);
908
+enum ref_transaction_error ref_transaction_update(struct ref_transaction *transaction,
909
+ const char *refname,
910
+ const struct object_id *new_oid,
911
+ const struct object_id *old_oid,
912
+ const char *new_target,
913
+ const char *old_target,
914
+ unsigned int flags, const char *msg,
915
+ struct strbuf *err);
916
917
/*
918
* Similar to `ref_transaction_update`, but this function is only for adding