]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: return `ref_transaction_error` from `ref_transaction_update()`
authorKarthik Nayak <karthik.188@gmail.com>
Mon, 27 Apr 2026 10:42:05 +0000 (12:42 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Apr 2026 12:35:12 +0000 (21:35 +0900)
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>
refs.c
refs.h

diff --git a/refs.c b/refs.c
index 6b506aeea30bae9dad537f1f7f85507c7292495b..efa16b739d153b24b53ff8639cdf4e75516c9207 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1383,25 +1383,25 @@ static int transaction_refname_valid(const char *refname,
        return 1;
 }
 
-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)
+enum ref_transaction_error 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)
 {
        assert(err);
 
        if ((flags & REF_FORCE_CREATE_REFLOG) &&
            (flags & REF_SKIP_CREATE_REFLOG)) {
                strbuf_addstr(err, _("refusing to force and skip creation of reflog"));
-               return -1;
+               return REF_TRANSACTION_ERROR_GENERIC;
        }
 
        if (!transaction_refname_valid(refname, new_oid, flags, err))
-               return -1;
+               return REF_TRANSACTION_ERROR_GENERIC;
 
        if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS)
                BUG("illegal flags 0x%x passed to ref_transaction_update()", flags);
diff --git a/refs.h b/refs.h
index d65de6ab5fe11b5043f04e5152c2b3265fa1b255..71d5c186d044bbd278dbfe8685287196d780243e 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -905,14 +905,14 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
  * See the above comment "Reference transaction updates" for more
  * information.
  */
-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);
+enum ref_transaction_error 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);
 
 /*
  * Similar to `ref_transaction_update`, but this function is only for adding