Re: [PATCH v27 2/2] status: add status.compareBranches config for multiple branch comparisons
- From
Jeff King <peff@peff.net>
- Date
- Jan 22, 2026, 19:07 UTC
- Message-ID
- <20260122190751.GA2098026@coredump.intra.peff.net>
- In-Reply-To
- <0993420fc1185ec4a907a8c3bb52ca965e720c54.1769096240.git.gitgitgadget@gmail.com>
On Thu, Jan 22, 2026 at 03:37:20PM +0000, Harald Nordgren via GitGitGadget wrote:
Show 5 quoted lines
> + if (string_list_has_string(&processed_refs, full_ref)) {
> + free(full_ref);
> + continue;
> + }
> + string_list_insert(&processed_refs, full_ref);Using a string list like this is quadratic. It probably doesn't matter too much here since we wouldn't expect the list of configured branches to be very long, though. But a strset is probably the better tool, like the diff below (note that its "add" can be used as a single operation to insert and check).
I don't know if it's worth re-rolling for this or not. I doubt anybody would hit it in practice, but I'd be more concerned about people auditing for accidentally-quadratic uses of string_list and stumbling upon it.
-Peff
diff --git a/remote.c b/remote.c index e256cc9b81..1071a23567 100644 --- a/remote.c +++ b/remote.c @@ -2339,7 +2339,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, { char *compare_branches = NULL; struct string_list branches = STRING_LIST_INIT_DUP; - struct string_list processed_refs = STRING_LIST_INIT_DUP; + struct strset processed_refs = STRSET_INIT; int reported = 0; size_t i; const char *upstream_ref; @@ -2370,11 +2370,10 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, if (!full_ref) continue; - if (string_list_has_string(&processed_refs, full_ref)) { + if (!strset_add(&processed_refs, full_ref)) { free(full_ref); continue; } - string_list_insert(&processed_refs, full_ref); short_ref = refs_shorten_unambiguous_ref( get_main_ref_store(the_repository), full_ref, 0); @@ -2421,7 +2420,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, } string_list_clear(&branches, 0); - string_list_clear(&processed_refs, 0); + strset_clear(&processed_refs); free(compare_branches); return reported; }