]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files: remove redundant check in split_symref_update()
authorKarthik Nayak <karthik.188@gmail.com>
Tue, 8 Apr 2025 08:51:05 +0000 (10:51 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2025 14:57:18 +0000 (07:57 -0700)
In `split_symref_update()`, there were two checks for duplicate
refnames:

  - At the start, `string_list_has_string()` ensures the refname is not
    already in `affected_refnames`, preventing duplicates from being
    added.

  - After adding the refname, another check verifies whether the newly
    inserted item has a `util` value.

The second check is unnecessary because the first one guarantees that
`string_list_insert()` will never encounter a preexisting entry.

The `item->util` field is assigned to validate that a rename doesn't
already exist in the list. The validation is done after the first check.
As this check is removed, clean up the validation and the assignment of
this field in `split_head_update()` and `files_transaction_prepare()`.

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/files-backend.c

index 5f921e85eb4ff378fae2c8f5080f14f66c62807f..dab3951ccf9d46cb136eb8556c39e7750625b61f 100644 (file)
@@ -2382,7 +2382,6 @@ static int split_head_update(struct ref_update *update,
                             struct string_list *affected_refnames,
                             struct strbuf *err)
 {
-       struct string_list_item *item;
        struct ref_update *new_update;
 
        if ((update->flags & REF_LOG_ONLY) ||
@@ -2421,8 +2420,7 @@ static int split_head_update(struct ref_update *update,
         */
        if (strcmp(new_update->refname, "HEAD"))
                BUG("%s unexpectedly not 'HEAD'", new_update->refname);
-       item = string_list_insert(affected_refnames, new_update->refname);
-       item->util = new_update;
+       string_list_insert(affected_refnames, new_update->refname);
 
        return 0;
 }
@@ -2441,7 +2439,6 @@ static int split_symref_update(struct ref_update *update,
                               struct string_list *affected_refnames,
                               struct strbuf *err)
 {
-       struct string_list_item *item;
        struct ref_update *new_update;
        unsigned int new_flags;
 
@@ -2496,11 +2493,7 @@ static int split_symref_update(struct ref_update *update,
         * be valid as long as affected_refnames is in use, and NOT
         * referent, which might soon be freed by our caller.
         */
-       item = string_list_insert(affected_refnames, new_update->refname);
-       if (item->util)
-               BUG("%s unexpectedly found in affected_refnames",
-                   new_update->refname);
-       item->util = new_update;
+       string_list_insert(affected_refnames, new_update->refname);
 
        return 0;
 }
@@ -2834,7 +2827,6 @@ static int files_transaction_prepare(struct ref_store *ref_store,
         */
        for (i = 0; i < transaction->nr; i++) {
                struct ref_update *update = transaction->updates[i];
-               struct string_list_item *item;
 
                if ((update->flags & REF_IS_PRUNING) &&
                    !(update->flags & REF_NO_DEREF))
@@ -2843,13 +2835,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
                if (update->flags & REF_LOG_ONLY)
                        continue;
 
-               item = string_list_append(&affected_refnames, update->refname);
-               /*
-                * We store a pointer to update in item->util, but at
-                * the moment we never use the value of this field
-                * except to check whether it is non-NULL.
-                */
-               item->util = update;
+               string_list_append(&affected_refnames, update->refname);
        }
        string_list_sort(&affected_refnames);
        if (ref_update_reject_duplicates(&affected_refnames, err)) {