diff options
author | Colin Walters <walters@verbum.org> | 2023-05-03 08:24:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 08:24:21 -0400 |
commit | 8a2993a9d01cc358e4c2d936ca132174aabdc714 (patch) | |
tree | 5402001ab710dadfd51ba3e9071b044016030e3e /src/ostree/ot-builtin-find-remotes.c | |
parent | dd70c9b78cc34ccc7e638eda4c2df1ddd8ee3add (diff) | |
parent | c1044a02b28982ef6dd58af98b23a40482d26487 (diff) | |
download | ostree-8a2993a9d01cc358e4c2d936ca132174aabdc714.tar.gz |
Merge pull request #2565 from cgwalters/clang-format
Add .clang-format file + tree-wide: Run `clang-format`
Diffstat (limited to 'src/ostree/ot-builtin-find-remotes.c')
-rw-r--r-- | src/ostree/ot-builtin-find-remotes.c | 164 |
1 files changed, 81 insertions, 83 deletions
diff --git a/src/ostree/ot-builtin-find-remotes.c b/src/ostree/ot-builtin-find-remotes.c index 03ab1bef..b13ab4e4 100644 --- a/src/ostree/ot-builtin-find-remotes.c +++ b/src/ostree/ot-builtin-find-remotes.c @@ -22,9 +22,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" #include "ostree-remote-private.h" @@ -35,20 +35,21 @@ static gboolean opt_disable_fsync = FALSE; static gboolean opt_pull = FALSE; static gboolean opt_mirror = FALSE; -static GOptionEntry options[] = - { - { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, - { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, - { "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" }, - { "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL }, - { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Do a mirror pull (see ostree pull --mirror)", NULL}, - { NULL } - }; +static GOptionEntry options[] + = { { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, + { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", + NULL }, + { "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, + "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" }, + { "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL }, + { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, + "Do a mirror pull (see ostree pull --mirror)", NULL }, + { NULL } }; static gchar * uint64_secs_to_iso8601 (guint64 secs) { - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); + g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc (secs); if (dt != NULL) return g_date_time_format (dt, "%FT%TZ"); @@ -57,21 +58,20 @@ uint64_secs_to_iso8601 (guint64 secs) } static gchar * -format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, +format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, const gchar *line_prefix) { GHashTableIter iter; const OstreeCollectionRef *ref; const gchar *checksum; - g_autoptr(GString) out = NULL; + g_autoptr (GString) out = NULL; g_hash_table_iter_init (&iter, ref_to_checksum); out = g_string_new (""); - while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum)) - g_string_append_printf (out, "%s - (%s, %s) = %s\n", - line_prefix, ref->collection_id, ref->ref_name, - (checksum != NULL) ? checksum : "(not found)"); + while (g_hash_table_iter_next (&iter, (gpointer *)&ref, (gpointer *)&checksum)) + g_string_append_printf (out, "%s - (%s, %s) = %s\n", line_prefix, ref->collection_id, + ref->ref_name, (checksum != NULL) ? checksum : "(not found)"); return g_string_free (g_steal_pointer (&out), FALSE); } @@ -79,7 +79,7 @@ format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCol static gchar * remote_get_uri (OstreeRemote *remote) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_autofree gchar *uri = NULL; uri = g_key_file_get_string (remote->options, remote->group, "url", &error); @@ -90,8 +90,7 @@ remote_get_uri (OstreeRemote *remote) /* Add each key from @keys_input to @set iff its value is non-%NULL. */ static void -add_keys_to_set_if_non_null (GHashTable *set, - GHashTable *keys_input) +add_keys_to_set_if_non_null (GHashTable *set, GHashTable *keys_input) { GHashTableIter iter; gpointer key, value; @@ -104,9 +103,7 @@ add_keys_to_set_if_non_null (GHashTable *set, } static void -get_result_cb (GObject *obj, - GAsyncResult *result, - gpointer user_data) +get_result_cb (GObject *obj, GAsyncResult *result, gpointer user_data) { GAsyncResult **result_out = user_data; *result_out = g_object_ref (result); @@ -121,19 +118,16 @@ collection_ref_free0 (OstreeCollectionRef *ref) } static gboolean -validate_finders_list (const char **finders, - GOptionContext *context, - GError **error) +validate_finders_list (const char **finders, GOptionContext *context, GError **error) { - typedef struct { + typedef struct + { gchar *finder_name; gboolean already_used; } Finder; - Finder valid_finders[] = { - {.finder_name = "config", .already_used = FALSE}, - {.finder_name = "lan", .already_used = FALSE}, - {.finder_name = "mount", .already_used = FALSE} - }; + Finder valid_finders[] = { { .finder_name = "config", .already_used = FALSE }, + { .finder_name = "lan", .already_used = FALSE }, + { .finder_name = "mount", .already_used = FALSE } }; if (finders == NULL || *finders == NULL) { @@ -157,7 +151,8 @@ validate_finders_list (const char **finders, if (!is_valid_finder) { g_autofree gchar *error_msg = NULL; - error_msg = g_strdup_printf ("Unknown or duplicate finder type given in --finders option: ‘%s’", *iter); + error_msg = g_strdup_printf ( + "Unknown or duplicate finder type given in --finders option: ‘%s’", *iter); ot_util_usage_error (context, error_msg, error); return FALSE; } @@ -167,33 +162,33 @@ validate_finders_list (const char **finders, } gboolean -ostree_builtin_find_remotes (int argc, - char **argv, - OstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +ostree_builtin_find_remotes (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GPtrArray) refs = NULL; /* (element-type OstreeCollectionRef) */ - g_autoptr(GPtrArray) finders = NULL; /* (element-type OstreeRepoFinder) */ - g_autoptr(OstreeRepoFinder) finder_config = NULL; - g_autoptr(OstreeRepoFinder) finder_mount = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GPtrArray) refs = NULL; /* (element-type OstreeCollectionRef) */ + g_autoptr (GPtrArray) finders = NULL; /* (element-type OstreeRepoFinder) */ + g_autoptr (OstreeRepoFinder) finder_config = NULL; + g_autoptr (OstreeRepoFinder) finder_mount = NULL; #ifdef HAVE_AVAHI - g_autoptr(OstreeRepoFinder) finder_avahi = NULL; -#endif /* HAVE_AVAHI */ - g_autoptr(OstreeAsyncProgress) progress = NULL; + g_autoptr (OstreeRepoFinder) finder_avahi = NULL; +#endif /* HAVE_AVAHI */ + g_autoptr (OstreeAsyncProgress) progress = NULL; gsize i; - g_autoptr(GAsyncResult) find_result = NULL, pull_result = NULL; - g_auto(OstreeRepoFinderResultv) results = NULL; - g_auto(GLnxConsoleRef) console = { 0, }; - g_autoptr(GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */ - g_autoptr(GVariant) pull_options = NULL; + g_autoptr (GAsyncResult) find_result = NULL, pull_result = NULL; + g_auto (OstreeRepoFinderResultv) results = NULL; + g_auto (GLnxConsoleRef) console = { + 0, + }; + g_autoptr (GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */ + g_autoptr (GVariant) pull_options = NULL; context = g_option_context_new ("COLLECTION-ID REF [COLLECTION-ID REF...]"); /* Parse options. */ - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (!ostree_ensure_repo_writable (repo, error)) @@ -207,7 +202,8 @@ ostree_builtin_find_remotes (int argc, if (argc % 2 == 0) { - ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", error); + ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", + error); return FALSE; } @@ -220,17 +216,17 @@ ostree_builtin_find_remotes (int argc, if (opt_disable_fsync) ostree_repo_set_disable_fsync (repo, TRUE); - if (opt_cache_dir && - !ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error)) + if (opt_cache_dir + && !ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error)) return FALSE; /* Read in the refs to search for remotes for. */ - refs = g_ptr_array_new_full (argc, (GDestroyNotify) collection_ref_free0); + refs = g_ptr_array_new_full (argc, (GDestroyNotify)collection_ref_free0); for (i = 1; i < argc; i += 2) { - if (!ostree_validate_collection_id (argv[i], error) || - !ostree_validate_rev (argv[i + 1], error)) + if (!ostree_validate_collection_id (argv[i], error) + || !ostree_validate_rev (argv[i + 1], error)) return FALSE; g_ptr_array_add (refs, ostree_collection_ref_new (argv[i], argv[i + 1])); @@ -241,7 +237,7 @@ ostree_builtin_find_remotes (int argc, /* Build the array of OstreeRepoFinder instances */ if (opt_finders != NULL) { - g_auto(GStrv) finders_strings = NULL; + g_auto (GStrv) finders_strings = NULL; finders_strings = g_strsplit (opt_finders, ",", 0); if (!validate_finders_list ((const char **)finders_strings, context, error)) @@ -264,10 +260,11 @@ ostree_builtin_find_remotes (int argc, { #ifdef HAVE_AVAHI GMainContext *main_context = g_main_context_get_thread_default (); - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; finder_avahi = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (main_context)); - ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), &local_error); + ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), + &local_error); if (local_error != NULL) { @@ -277,9 +274,11 @@ ostree_builtin_find_remotes (int argc, else g_ptr_array_add (finders, finder_avahi); #else - ot_util_usage_error (context, "LAN repo finder requested but ostree was compiled without Avahi support", error); + ot_util_usage_error ( + context, + "LAN repo finder requested but ostree was compiled without Avahi support", error); return FALSE; -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ } else g_assert_not_reached (); @@ -291,14 +290,13 @@ ostree_builtin_find_remotes (int argc, glnx_console_lock (&console); if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); - ostree_repo_find_remotes_async (repo, - (const OstreeCollectionRef * const *) refs->pdata, - NULL /* no options */, - finders != NULL ? (OstreeRepoFinder **) finders->pdata : NULL, - progress, cancellable, - get_result_cb, &find_result); + ostree_repo_find_remotes_async (repo, (const OstreeCollectionRef *const *)refs->pdata, + NULL /* no options */, + finders != NULL ? (OstreeRepoFinder **)finders->pdata : NULL, + progress, cancellable, get_result_cb, &find_result); while (find_result == NULL) g_main_context_iteration (NULL, TRUE); @@ -312,8 +310,8 @@ ostree_builtin_find_remotes (int argc, ostree_async_progress_finish (progress); /* Print results and work out which refs were not found. */ - refs_found = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, NULL, NULL); + refs_found + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, NULL); for (i = 0; results[i] != NULL; i++) { @@ -350,7 +348,7 @@ ostree_builtin_find_remotes (int argc, g_print ("%u/%u refs were found.\n", g_hash_table_size (refs_found), refs->len - 1); /* Print out the refs which weren’t found. */ - if (g_hash_table_size (refs_found) != refs->len - 1 /* NULL terminator */) + if (g_hash_table_size (refs_found) != refs->len - 1 /* NULL terminator */) { g_print ("Refs not found in any remote:\n"); @@ -371,21 +369,21 @@ ostree_builtin_find_remotes (int argc, g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); if (opt_mirror) - g_variant_builder_add (&builder, "{s@v}", "flags", - g_variant_new_variant (g_variant_new_int32 (OSTREE_REPO_PULL_FLAGS_MIRROR))); + g_variant_builder_add ( + &builder, "{s@v}", "flags", + g_variant_new_variant (g_variant_new_int32 (OSTREE_REPO_PULL_FLAGS_MIRROR))); pull_options = g_variant_ref_sink (g_variant_builder_end (&builder)); } /* Run the pull operation. */ if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); - ostree_repo_pull_from_remotes_async (repo, - (const OstreeRepoFinderResult * const *) results, - pull_options, - progress, cancellable, - get_result_cb, &pull_result); + ostree_repo_pull_from_remotes_async (repo, (const OstreeRepoFinderResult *const *)results, + pull_options, progress, cancellable, get_result_cb, + &pull_result); while (pull_result == NULL) g_main_context_iteration (NULL, TRUE); |