Skip to content

Commit 276d0e3

Browse files
Martin Ågrengitster
authored andcommitted
refs/files-backend: add refname, not "HEAD", to list
An earlier patch rewrote `split_symref_update()` to add a copy of a string to a string list instead of adding the original string. That was so that the original string could be freed in a later patch, but it is also conceptually cleaner, since now all calls to `string_list_insert()` and `string_list_append()` add `update->refname`. --- Except a literal "HEAD" is added in `split_head_update()`. Restructure `split_head_update()` in the same way as the earlier patch did for `split_symref_update()`. This does not correct any practical problem, but makes things conceptually cleaner. The downside is a call to `string_list_has_string()`, which should be relatively cheap. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3f5ef95 commit 276d0e3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

refs/files-backend.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,11 +2589,10 @@ static int split_head_update(struct ref_update *update,
25892589

25902590
/*
25912591
* First make sure that HEAD is not already in the
2592-
* transaction. This insertion is O(N) in the transaction
2592+
* transaction. This check is O(lg N) in the transaction
25932593
* size, but it happens at most once per transaction.
25942594
*/
2595-
item = string_list_insert(affected_refnames, "HEAD");
2596-
if (item->util) {
2595+
if (string_list_has_string(affected_refnames, "HEAD")) {
25972596
/* An entry already existed */
25982597
strbuf_addf(err,
25992598
"multiple updates for 'HEAD' (including one "
@@ -2608,6 +2607,14 @@ static int split_head_update(struct ref_update *update,
26082607
update->new_oid.hash, update->old_oid.hash,
26092608
update->msg);
26102609

2610+
/*
2611+
* Add "HEAD". This insertion is O(N) in the transaction
2612+
* size, but it happens at most once per transaction.
2613+
* Add new_update->refname instead of a literal "HEAD".
2614+
*/
2615+
if (strcmp(new_update->refname, "HEAD"))
2616+
BUG("%s unexpectedly not 'HEAD'", new_update->refname);
2617+
item = string_list_insert(affected_refnames, new_update->refname);
26112618
item->util = new_update;
26122619

26132620
return 0;

0 commit comments

Comments
 (0)