refs/files: remove redundant check in split_symref_update()

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>

Karthik Nayak committed Apr 8, 2025 at 10:51 UTC 05a1834e429c619602a8507d8a2c9b81d467c24d
1 file changed +3 -17
refs/files-backend.c
+3 -17
@@ -2382,7 +2382,6 @@ static int split_head_update(struct ref_update *update,
2382 struct string_list *affected_refnames,
2383 struct strbuf *err)
2384 {
2385 - struct string_list_item *item;
2385 struct ref_update *new_update;
2386
2387 if ((update->flags & REF_LOG_ONLY) ||
@@ -2421,8 +2420,7 @@ static int split_head_update(struct ref_update *update,
2420 */
2421 if (strcmp(new_update->refname, "HEAD"))
2422 BUG("%s unexpectedly not 'HEAD'", new_update->refname);
2424 - item = string_list_insert(affected_refnames, new_update->refname);
2425 - item->util = new_update;
2423 + string_list_insert(affected_refnames, new_update->refname);
2424
2425 return 0;
2426 }
@@ -2441,7 +2439,6 @@ static int split_symref_update(struct ref_update *update,
2439 struct string_list *affected_refnames,
2440 struct strbuf *err)
2441 {
2444 - struct string_list_item *item;
2442 struct ref_update *new_update;
2443 unsigned int new_flags;
2444
@@ -2496,11 +2493,7 @@ static int split_symref_update(struct ref_update *update,
2493 * be valid as long as affected_refnames is in use, and NOT
2494 * referent, which might soon be freed by our caller.
2495 */
2499 - item = string_list_insert(affected_refnames, new_update->refname);
2500 - if (item->util)
2501 - BUG("%s unexpectedly found in affected_refnames",
2502 - new_update->refname);
2503 - item->util = new_update;
2496 + string_list_insert(affected_refnames, new_update->refname);
2497
2498 return 0;
2499 }
@@ -2834,7 +2827,6 @@ static int files_transaction_prepare(struct ref_store *ref_store,
2827 */
2828 for (i = 0; i < transaction->nr; i++) {
2829 struct ref_update *update = transaction->updates[i];
2837 - struct string_list_item *item;
2830
2831 if ((update->flags & REF_IS_PRUNING) &&
2832 !(update->flags & REF_NO_DEREF))
@@ -2843,13 +2835,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
2835 if (update->flags & REF_LOG_ONLY)
2836 continue;
2837
2846 - item = string_list_append(&affected_refnames, update->refname);
2847 - /*
2848 - * We store a pointer to update in item->util, but at
2849 - * the moment we never use the value of this field
2850 - * except to check whether it is non-NULL.
2851 - */
2852 - item->util = update;
2838 + string_list_append(&affected_refnames, update->refname);
2839 }
2840 string_list_sort(&affected_refnames);
2841 if (ref_update_reject_duplicates(&affected_refnames, err)) {