Skip to content

Commit 34d278c

Browse files
KarthikNayakgitster
authored andcommitted
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. Since `item->util` is only used in this context, remove the assignment and simplify the surrounding code. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb3e8a6 commit 34d278c

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

refs/files-backend.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,6 @@ static int split_head_update(struct ref_update *update,
23822382
struct string_list *affected_refnames,
23832383
struct strbuf *err)
23842384
{
2385-
struct string_list_item *item;
23862385
struct ref_update *new_update;
23872386

23882387
if ((update->flags & REF_LOG_ONLY) ||
@@ -2421,8 +2420,7 @@ static int split_head_update(struct ref_update *update,
24212420
*/
24222421
if (strcmp(new_update->refname, "HEAD"))
24232422
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);
24262424

24272425
return 0;
24282426
}
@@ -2441,7 +2439,6 @@ static int split_symref_update(struct ref_update *update,
24412439
struct string_list *affected_refnames,
24422440
struct strbuf *err)
24432441
{
2444-
struct string_list_item *item;
24452442
struct ref_update *new_update;
24462443
unsigned int new_flags;
24472444

@@ -2496,11 +2493,7 @@ static int split_symref_update(struct ref_update *update,
24962493
* be valid as long as affected_refnames is in use, and NOT
24972494
* referent, which might soon be freed by our caller.
24982495
*/
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);
25042497

25052498
return 0;
25062499
}
@@ -2834,7 +2827,6 @@ static int files_transaction_prepare(struct ref_store *ref_store,
28342827
*/
28352828
for (i = 0; i < transaction->nr; i++) {
28362829
struct ref_update *update = transaction->updates[i];
2837-
struct string_list_item *item;
28382830

28392831
if ((update->flags & REF_IS_PRUNING) &&
28402832
!(update->flags & REF_NO_DEREF))
@@ -2843,13 +2835,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
28432835
if (update->flags & REF_LOG_ONLY)
28442836
continue;
28452837

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);
28532839
}
28542840
string_list_sort(&affected_refnames);
28552841
if (ref_update_reject_duplicates(&affected_refnames, err)) {

0 commit comments

Comments
 (0)