Merge pull request #2651 from cgwalters/misc-declare-and-initialize-2

cli: Port to C99 style (3)
This commit is contained in:
Colin Walters 2022-06-21 16:44:12 -04:00 committed by GitHub
commit b04c436bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 62 deletions

View File

@ -201,62 +201,52 @@ out:
gboolean gboolean
ostree_builtin_gpg_sign (int argc, char **argv,OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ostree_builtin_gpg_sign (int argc, char **argv,OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GOptionContext) context = g_option_context_new ("COMMIT KEY-ID...");
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
g_autofree char *resolved_commit = NULL;
const char *commit;
char **key_ids;
int n_key_ids, ii;
gboolean ret = FALSE;
context = g_option_context_new ("COMMIT KEY-ID...");
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))
goto out; return FALSE;
if (argc < 2) if (argc < 2)
{ {
usage_error (context, "Need a COMMIT to sign", error); usage_error (context, "Need a COMMIT to sign", error);
goto out; return FALSE;
} }
if (argc < 3) if (argc < 3)
{ {
usage_error (context, "Need at least one GPG KEY-ID to sign with", error); usage_error (context, "Need at least one GPG KEY-ID to sign with", error);
goto out; return FALSE;
} }
commit = argv[1]; const char *commit = argv[1];
key_ids = argv + 2; char **key_ids = argv + 2;
n_key_ids = argc - 2; int n_key_ids = argc - 2;
g_autofree char *resolved_commit = NULL;
if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error)) if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error))
goto out; return FALSE;
if (opt_delete) if (opt_delete)
{ {
guint n_deleted = 0; guint n_deleted = 0;
if (delete_signatures (repo, resolved_commit, if (!delete_signatures (repo, resolved_commit,
(const char * const *) key_ids, n_key_ids, (const char * const *) key_ids, n_key_ids,
&n_deleted, cancellable, error)) &n_deleted, cancellable, error))
{ return FALSE;
g_print ("Signatures deleted: %u\n", n_deleted); g_print ("Signatures deleted: %u\n", n_deleted);
ret = TRUE; return TRUE;
} }
goto out; for (int ii = 0; ii < n_key_ids; ii++)
}
for (ii = 0; ii < n_key_ids; ii++)
{ {
if (!ostree_repo_sign_commit (repo, resolved_commit, key_ids[ii], if (!ostree_repo_sign_commit (repo, resolved_commit, key_ids[ii],
opt_gpg_homedir, cancellable, error)) opt_gpg_homedir, cancellable, error))
goto out; return FALSE;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }

View File

@ -37,45 +37,38 @@ static GOptionEntry option_entries[] = {
gboolean gboolean
ot_remote_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_remote_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("");
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
g_auto(GStrv) remotes = NULL;
guint ii, n_remotes = 0;
gboolean ret = FALSE;
context = g_option_context_new ("");
if (!ostree_option_context_parse (context, option_entries, &argc, &argv, if (!ostree_option_context_parse (context, option_entries, &argc, &argv,
invocation, &repo, cancellable, error)) invocation, &repo, cancellable, error))
goto out; return FALSE;
remotes = ostree_repo_remote_list (repo, &n_remotes); guint n_remotes = 0;
g_auto(GStrv) remotes = ostree_repo_remote_list (repo, &n_remotes);
if (opt_show_urls) if (opt_show_urls)
{ {
int max_length = 0; int max_length = 0;
for (ii = 0; ii < n_remotes; ii++) for (guint ii = 0; ii < n_remotes; ii++)
max_length = MAX (max_length, strlen (remotes[ii])); max_length = MAX (max_length, strlen (remotes[ii]));
for (ii = 0; ii < n_remotes; ii++) for (guint ii = 0; ii < n_remotes; ii++)
{ {
g_autofree char *remote_url = NULL; g_autofree char *remote_url = NULL;
if (!ostree_repo_remote_get_url (repo, remotes[ii], &remote_url, error)) if (!ostree_repo_remote_get_url (repo, remotes[ii], &remote_url, error))
goto out; return FALSE;
g_print ("%-*s %s\n", max_length, remotes[ii], remote_url); g_print ("%-*s %s\n", max_length, remotes[ii], remote_url);
} }
} }
else else
{ {
for (ii = 0; ii < n_remotes; ii++) for (guint ii = 0; ii < n_remotes; ii++)
g_print ("%s\n", remotes[ii]); g_print ("%s\n", remotes[ii]);
} }
ret = TRUE; return TRUE;
out:
return ret;
} }

View File

@ -39,34 +39,30 @@ static GOptionEntry option_entries[] = {
gboolean gboolean
ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("NAME");
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
const char *remote_name;
gboolean ret = FALSE;
g_autoptr(GHashTable) refs = NULL;
context = g_option_context_new ("NAME");
if (!ostree_option_context_parse (context, option_entries, &argc, &argv, if (!ostree_option_context_parse (context, option_entries, &argc, &argv,
invocation, &repo, cancellable, error)) invocation, &repo, cancellable, error))
goto out; return FALSE;
if (argc < 2) if (argc < 2)
{ {
ot_util_usage_error (context, "NAME must be specified", error); ot_util_usage_error (context, "NAME must be specified", error);
goto out; return FALSE;
} }
if (opt_cache_dir) if (opt_cache_dir)
{ {
if (!ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error)) if (!ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error))
goto out; return FALSE;
} }
remote_name = argv[1]; const char *remote_name = argv[1];
g_autoptr(GHashTable) refs = NULL;
if (!ostree_repo_remote_list_refs (repo, remote_name, &refs, cancellable, error)) if (!ostree_repo_remote_list_refs (repo, remote_name, &refs, cancellable, error))
goto out; return FALSE;
else else
{ {
g_autoptr(GList) ordered_keys = NULL; g_autoptr(GList) ordered_keys = NULL;
@ -81,7 +77,5 @@ ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocati
} }
} }
ret = TRUE; return TRUE;
out:
return ret;
} }