Minor cleanup of _ostree_repo_remote_new_fetcher()
authorAlexander Larsson <alexl@redhat.com>
Thu, 10 Sep 2020 09:34:31 +0000 (11:34 +0200)
committerAlexander Larsson <alexl@redhat.com>
Fri, 11 Sep 2020 10:03:28 +0000 (12:03 +0200)
Instead of open coding the extra_headers and append_user_agent
setting everywhere we do this in the constructor.

src/libostree/ostree-repo-pull.c

index 61700e47e7d93df1f485434c6c0b0c78da126933..21092cd7002d2cf0ee3af1e55cb332ebb6bb17e7 100644 (file)
@@ -2824,6 +2824,8 @@ static OstreeFetcher *
 _ostree_repo_remote_new_fetcher (OstreeRepo  *self,
                                  const char  *remote_name,
                                  gboolean     gzip,
+                                 GVariant    *extra_headers,
+                                 const char  *append_user_agent,
                                  OstreeFetcherSecurityState *out_state,
                                  GError     **error)
 {
@@ -2937,6 +2939,12 @@ _ostree_repo_remote_new_fetcher (OstreeRepo  *self,
         _ostree_fetcher_set_cookie_jar (fetcher, jar_path);
     }
 
+  if (extra_headers)
+    _ostree_fetcher_set_extra_headers (fetcher, extra_headers);
+
+  if (append_user_agent)
+    _ostree_fetcher_set_extra_user_agent (fetcher, append_user_agent);
+
   success = TRUE;
 
 out:
@@ -3092,17 +3100,13 @@ reinitialize_fetcher (OtPullData *pull_data, const char *remote_name,
 {
   g_clear_object (&pull_data->fetcher);
   pull_data->fetcher = _ostree_repo_remote_new_fetcher (pull_data->repo, remote_name, FALSE,
+                                                        pull_data->extra_headers,
+                                                        pull_data->append_user_agent,
                                                         &pull_data->fetcher_security_state,
                                                         error);
   if (pull_data->fetcher == NULL)
     return FALSE;
 
-  if (pull_data->extra_headers)
-    _ostree_fetcher_set_extra_headers (pull_data->fetcher, pull_data->extra_headers);
-
-  if (pull_data->append_user_agent)
-    _ostree_fetcher_set_extra_user_agent (pull_data->fetcher, pull_data->append_user_agent);
-
   return TRUE;
 }
 
@@ -5454,7 +5458,7 @@ find_remotes_cb (GObject      *obj,
                 goto error;
 
               fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name,
-                                                         TRUE, NULL, &error);
+                                                         TRUE, NULL, NULL, NULL, &error);
               if (fetcher == NULL)
                 goto error;
 
@@ -6110,16 +6114,10 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo    *self,
 
   mainctx = _ostree_main_context_new_default ();
 
-  fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, NULL, error);
+  fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, NULL, error);
   if (fetcher == NULL)
     return FALSE;
 
-  if (extra_headers)
-    _ostree_fetcher_set_extra_headers (fetcher, extra_headers);
-
-  if (append_user_agent)
-    _ostree_fetcher_set_extra_user_agent (fetcher, append_user_agent);
-
   {
     g_autofree char *url_string = NULL;
     if (metalink_url_string)