promisor-remote: keep accepted promisor_info structs alive

In filter_promisor_remote(), the instances of `struct promisor_info`
for accepted remotes are dismantled into separate parallel data
structures (the 'accepted' strvec for server names, and
'accepted_filters' for filter strings) and then immediately freed.

Instead, let's keep these instances on an 'accepted_remotes' list.

This way the post-loop phase can iterate a single list to build the
protocol reply, apply advertised filters, and mark remotes as
accepted, rather than iterating three separate structures.

This refactoring also prepares for a future commit that will add a
'local_name' member to 'struct promisor_info'. Since struct instances
stay alive, downstream code will be able to simply read both names
from them rather than needing yet another parallel strvec.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
Christian Couder 2026-04-07 13:52:41 +02:00 committed by Junio C Hamano
parent 7557a56243
commit e0f80d8876
1 changed files with 17 additions and 25 deletions

View File

@ -890,10 +890,10 @@ static void filter_promisor_remote(struct repository *repo,
{
struct string_list config_info = STRING_LIST_INIT_NODUP;
struct string_list remote_info = STRING_LIST_INIT_DUP;
struct string_list accepted_remotes = STRING_LIST_INIT_NODUP;
struct store_info *store_info = NULL;
struct string_list_item *item;
bool reload_config = false;
struct string_list accepted_filters = STRING_LIST_INIT_DUP;
enum accept_promisor accept = accept_from_server(repo);

if (accept == ACCEPT_NONE)
@ -922,17 +922,10 @@ static void filter_promisor_remote(struct repository *repo,
if (promisor_store_advertised_fields(advertised, store_info))
reload_config = true;

strvec_push(accepted, advertised->name);

/* Capture advertised filters for accepted remotes */
if (advertised->filter) {
struct string_list_item *i;
i = string_list_append(&accepted_filters, advertised->name);
i->util = xstrdup(advertised->filter);
}
string_list_append(&accepted_remotes, advertised->name)->util = advertised;
} else {
promisor_info_free(advertised);
}

promisor_info_free(advertised);
}

promisor_info_list_clear(&config_info);
@ -942,24 +935,23 @@ static void filter_promisor_remote(struct repository *repo,
if (reload_config)
repo_promisor_remote_reinit(repo);

/* Apply accepted remote filters to the stable repo state */
for_each_string_list_item(item, &accepted_filters) {
struct promisor_remote *r = repo_promisor_remote_find(repo, item->string);
/* Apply accepted remotes to the stable repo state */
for_each_string_list_item(item, &accepted_remotes) {
struct promisor_info *info = item->util;
struct promisor_remote *r = repo_promisor_remote_find(repo, info->name);

strvec_push(accepted, info->name);

if (r) {
free(r->advertised_filter);
r->advertised_filter = item->util;
item->util = NULL;
r->accepted = 1;
if (info->filter) {
free(r->advertised_filter);
r->advertised_filter = xstrdup(info->filter);
}
}
}

string_list_clear(&accepted_filters, 1);

/* Mark the remotes as accepted in the repository state */
for (size_t i = 0; i < accepted->nr; i++) {
struct promisor_remote *r = repo_promisor_remote_find(repo, accepted->v[i]);
if (r)
r->accepted = 1;
}
promisor_info_list_clear(&accepted_remotes);
}

void promisor_remote_reply(const char *info, char **accepted_out)