From 4cdec26264d839436ae9ab5bcb97bb17f9f2543e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 4 Dec 2015 10:48:26 +0100 Subject: [PATCH] list/ls-remotes: Use the new remote helpers --- app/xdg-app-builtins-list-remotes.c | 23 +++++++++-------------- app/xdg-app-builtins-ls-remote.c | 20 +++++++++----------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/xdg-app-builtins-list-remotes.c b/app/xdg-app-builtins-list-remotes.c index 6fb8df5d..aafad111 100644 --- a/app/xdg-app-builtins-list-remotes.c +++ b/app/xdg-app-builtins-list-remotes.c @@ -49,7 +49,7 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable, g_autoptr(XdgAppDir) user_dir = NULL; g_autoptr(XdgAppDir) system_dir = NULL; XdgAppDir *dirs[2] = { 0 }; - guint ii, n_remotes = 0, n_dirs = 0, j; + guint i = 0, n_dirs = 0, j; XdgAppTablePrinter *printer; context = g_option_context_new (" - List remote repositories"); @@ -80,30 +80,25 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable, for (j = 0; j < n_dirs; j++) { XdgAppDir *dir = dirs[j]; - GKeyFile *config; g_auto(GStrv) remotes = NULL; - if (!xdg_app_dir_ensure_repo (dir, cancellable, NULL)) - continue; + remotes = xdg_app_dir_list_remotes (dir, cancellable, error); + if (remotes == NULL) + return FALSE; - config = ostree_repo_get_config (xdg_app_dir_get_repo (dir)); - remotes = ostree_repo_remote_list (xdg_app_dir_get_repo (dir), &n_remotes); - - for (ii = 0; ii < n_remotes; ii++) + for (i = 0; remotes[i] != NULL; i++) { + char *remote_name = remotes[i]; + if (opt_show_details) { - char *remote_name = remotes[ii]; g_autofree char *remote_url = NULL; - g_autofree char *group = NULL; g_autofree char *title = NULL; gboolean gpg_verify = TRUE; - group = g_strdup_printf ("remote \"%s\"", remote_name); - xdg_app_table_printer_add_column (printer, remote_name); - title = g_key_file_get_string (config, group, "xa.title", NULL); + title = xdg_app_dir_get_remote_title (dir, remote_name); if (title) xdg_app_table_printer_add_column (printer, title); else @@ -124,7 +119,7 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable, xdg_app_table_printer_append_with_comma (printer, dir == user_dir ? "user" : "system"); } else - xdg_app_table_printer_add_column (printer, remotes[ii]); + xdg_app_table_printer_add_column (printer, remote_name); xdg_app_table_printer_finish_row (printer); } diff --git a/app/xdg-app-builtins-ls-remote.c b/app/xdg-app-builtins-ls-remote.c index ff2194a2..b1eca8e8 100644 --- a/app/xdg-app-builtins-ls-remote.c +++ b/app/xdg-app-builtins-ls-remote.c @@ -49,9 +49,7 @@ xdg_app_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr { g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDir) dir = NULL; - OstreeRepo *repo = NULL; g_autoptr(GHashTable) refs = NULL; - g_autofree char *title = NULL; GHashTableIter iter; gpointer key; gpointer value; @@ -70,11 +68,11 @@ xdg_app_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr repository = argv[1]; - repo = xdg_app_dir_get_repo (dir); - if (!ostree_repo_remote_get_url (repo, repository, &url, error)) - return FALSE; - if (!ostree_repo_load_summary (url, &refs, &title, cancellable, error)) + if (!xdg_app_dir_list_remote_refs (dir, + repository, + &refs, + cancellable, error)) return FALSE; names = g_ptr_array_new_with_free_func (g_free); @@ -131,19 +129,19 @@ xdg_app_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr if (name) { - gboolean found = FALSE; + gboolean found = FALSE; for (i = 0; i < names->len; i++) { if (strcmp (name, g_ptr_array_index (names, i)) == 0) - found = TRUE; + found = TRUE; break; } - if (!found) + if (!found) g_ptr_array_add (names, name); - else - g_free (name); + else + g_free (name); } }