]> git.ipfire.org Git - thirdparty/git.git/commitdiff
promisor-remote: keep accepted promisor_info structs alive
authorChristian Couder <christian.couder@gmail.com>
Tue, 7 Apr 2026 11:52:41 +0000 (13:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Apr 2026 15:45:44 +0000 (08:45 -0700)
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>
promisor-remote.c

index 8d80ef6040534c0c2b9bf32774518f456d3d1be2..74e65e9dd0de4808fceb51a533f54365d1574eaa 100644 (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);
-               if (r) {
-                       free(r->advertised_filter);
-                       r->advertised_filter = item->util;
-                       item->util = NULL;
-               }
-       }
+       /* 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);
 
-       string_list_clear(&accepted_filters, 1);
+               strvec_push(accepted, info->name);
 
-       /* 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)
+               if (r) {
                        r->accepted = 1;
+                       if (info->filter) {
+                               free(r->advertised_filter);
+                               r->advertised_filter = xstrdup(info->filter);
+                       }
+               }
        }
+
+       promisor_info_list_clear(&accepted_remotes);
 }
 
 void promisor_remote_reply(const char *info, char **accepted_out)