]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files: remove duplicate duplicates check
authorKarthik Nayak <karthik.188@gmail.com>
Tue, 8 Apr 2025 08:51:07 +0000 (10:51 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2025 14:57:19 +0000 (07:57 -0700)
Within the files reference backend's transaction's 'finish' phase, a
verification step is currently performed wherein the refnames list is
sorted and examined for multiple updates targeting the same refname.

It has been observed that this verification is redundant, as an
identical check is already executed during the transaction's 'prepare'
stage. Since the refnames list remains unmodified following the
'prepare' stage, this secondary verification can be safely eliminated.

The duplicate check has been removed accordingly, and the
`ref_update_reject_duplicates()` function has been marked as static, as
its usage is now confined to 'refs.c'.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs/files-backend.c
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index 22000798c75553d84bf94e2d5f6a367ffdc9b60a..b34969c7923369a1f741f1b6c9cb1d04ce33c86e 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2303,8 +2303,13 @@ cleanup:
        return ret;
 }
 
-int ref_update_reject_duplicates(struct string_list *refnames,
-                                struct strbuf *err)
+/*
+ * Write an error to `err` and return a nonzero value iff the same
+ * refname appears multiple times in `refnames`. `refnames` must be
+ * sorted on entry to this function.
+ */
+static int ref_update_reject_duplicates(struct string_list *refnames,
+                                       struct strbuf *err)
 {
        size_t i, n = refnames->nr;
 
index ecf2df556d3b7993c7b88738b392cd93ffcf5bdf..73da0d70e8366104dbdf41bf66123d38f367d5a6 100644 (file)
@@ -3016,12 +3016,6 @@ static int files_transaction_finish_initial(struct files_ref_store *refs,
        if (transaction->state != REF_TRANSACTION_PREPARED)
                BUG("commit called for transaction that is not prepared");
 
-       string_list_sort(&transaction->refnames);
-       if (ref_update_reject_duplicates(&transaction->refnames, err)) {
-               ret = TRANSACTION_GENERIC_ERROR;
-               goto cleanup;
-       }
-
        /*
         * It's really undefined to call this function in an active
         * repository or when there are existing references: we are
index 92db7930260d070b3fdf84a2931abbd975227882..6d3770d0ccfe41717a90c13ccdd3a34c9d5e63b1 100644 (file)
@@ -142,14 +142,6 @@ int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
                      struct object_id *oid, struct strbuf *referent,
                      unsigned int *type, int *failure_errno);
 
-/*
- * Write an error to `err` and return a nonzero value iff the same
- * refname appears multiple times in `refnames`. `refnames` must be
- * sorted on entry to this function.
- */
-int ref_update_reject_duplicates(struct string_list *refnames,
-                                struct strbuf *err);
-
 /*
  * Add a ref_update with the specified properties to transaction, and
  * return a pointer to the new object. This function does not verify