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>

Martin Ågren committed Sep 9, 2017 at 08:57 UTC 276d0e35c0c9cadaf38247f7a9ff716e293b2acb
1 file changed +10 -3
refs/files-backend.c
+10 -3
@@ -2589,11 +2589,10 @@ static int split_head_update(struct ref_update *update,
2589
2590 /*
2591 * 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
2593 * size, but it happens at most once per transaction.
2594 */
2595 - item = string_list_insert(affected_refnames, "HEAD");
2596 - if (item->util) {
2595 + if (string_list_has_string(affected_refnames, "HEAD")) {
2596 /* An entry already existed */
2597 strbuf_addf(err,
2598 "multiple updates for 'HEAD' (including one "
@@ -2608,6 +2607,14 @@ static int split_head_update(struct ref_update *update,
2607 update->new_oid.hash, update->old_oid.hash,
2608 update->msg);
2609
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);
2618 item->util = new_update;
2619
2620 return 0;