git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 1/8] refs/files: remove redundant check in split_symref_update()

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 20, 2025, 11:43 UTC
Message-ID
<20250320-245-partially-atomic-ref-updates-v4-1-3dcc1b311dc9@gmail.com>
In-Reply-To
<20250320-245-partially-atomic-ref-updates-v4-0-3dcc1b311dc9@gmail.com>

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>
---
 refs/files-backend.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index ff54a4bb7e..15559a09c5 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -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)) {
-- 
2.48.1
Previous: Karthik NayakNext: Karthik Nayak
Message 2 of 19 in “refs: introduce support for batched reference updates”
  1. 0/8 refs: introduce support for batched reference updatesKarthik Nayak, Mar 20, 2025
  2. 1/8 refs/files: remove redundant check in split_symref_update()Karthik Nayak, Mar 20, 2025
  3. 2/8 refs: move duplicate refname update check to generic layerKarthik Nayak, Mar 20, 2025
  4. 3/8 refs/files: remove duplicate duplicates checkKarthik Nayak, Mar 20, 2025
  5. 4/8 refs/reftable: extract code from the transaction preparationKarthik Nayak, Mar 20, 2025
  6. 6/8 refs: implement batch reference update supportKarthik Nayak, Mar 20, 2025
  7. Patrick SteinhardtMar 20, 2025
  8. Karthik NayakMar 24, 2025
  9. 5/8 refs: introduce enum-based transaction error typesKarthik Nayak, Mar 20, 2025
  10. Patrick SteinhardtMar 20, 2025
  11. Karthik NayakMar 24, 2025
  12. Patrick SteinhardtMar 25, 2025
  13. 7/8 refs: support rejection in batch updates during F/D checksKarthik Nayak, Mar 20, 2025
  14. Patrick SteinhardtMar 24, 2025
  15. Karthik NayakMar 24, 2025
  16. Patrick SteinhardtMar 25, 2025
  17. 8/8 update-ref: add --batch-updates flag for stdin modeKarthik Nayak, Mar 20, 2025
  18. Patrick SteinhardtMar 24, 2025
  19. Karthik NayakMar 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.