Skip to content

Commit e0f80d8

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent 7557a56 commit e0f80d8

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

promisor-remote.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,10 @@ static void filter_promisor_remote(struct repository *repo,
890890
{
891891
struct string_list config_info = STRING_LIST_INIT_NODUP;
892892
struct string_list remote_info = STRING_LIST_INIT_DUP;
893+
struct string_list accepted_remotes = STRING_LIST_INIT_NODUP;
893894
struct store_info *store_info = NULL;
894895
struct string_list_item *item;
895896
bool reload_config = false;
896-
struct string_list accepted_filters = STRING_LIST_INIT_DUP;
897897
enum accept_promisor accept = accept_from_server(repo);
898898

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

925-
strvec_push(accepted, advertised->name);
926-
927-
/* Capture advertised filters for accepted remotes */
928-
if (advertised->filter) {
929-
struct string_list_item *i;
930-
i = string_list_append(&accepted_filters, advertised->name);
931-
i->util = xstrdup(advertised->filter);
932-
}
925+
string_list_append(&accepted_remotes, advertised->name)->util = advertised;
926+
} else {
927+
promisor_info_free(advertised);
933928
}
934-
935-
promisor_info_free(advertised);
936929
}
937930

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

945-
/* Apply accepted remote filters to the stable repo state */
946-
for_each_string_list_item(item, &accepted_filters) {
947-
struct promisor_remote *r = repo_promisor_remote_find(repo, item->string);
948-
if (r) {
949-
free(r->advertised_filter);
950-
r->advertised_filter = item->util;
951-
item->util = NULL;
952-
}
953-
}
938+
/* Apply accepted remotes to the stable repo state */
939+
for_each_string_list_item(item, &accepted_remotes) {
940+
struct promisor_info *info = item->util;
941+
struct promisor_remote *r = repo_promisor_remote_find(repo, info->name);
954942

955-
string_list_clear(&accepted_filters, 1);
943+
strvec_push(accepted, info->name);
956944

957-
/* Mark the remotes as accepted in the repository state */
958-
for (size_t i = 0; i < accepted->nr; i++) {
959-
struct promisor_remote *r = repo_promisor_remote_find(repo, accepted->v[i]);
960-
if (r)
945+
if (r) {
961946
r->accepted = 1;
947+
if (info->filter) {
948+
free(r->advertised_filter);
949+
r->advertised_filter = xstrdup(info->filter);
950+
}
951+
}
962952
}
953+
954+
promisor_info_list_clear(&accepted_remotes);
963955
}
964956

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

0 commit comments

Comments
 (0)