Skip to content

Commit

Permalink
Merge pull request #3006 from cgwalters/misc-c99-style-5
Browse files Browse the repository at this point in the history
Misc c99 style 5
  • Loading branch information
ericcurtin committed Aug 26, 2023
2 parents 4dd3cb3 + cce1814 commit 7c13631
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 103 deletions.
81 changes: 23 additions & 58 deletions src/ostree/ot-builtin-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,95 +51,66 @@ static GOptionEntry options[]
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_path, "Output to PATH ", "PATH" },
{ NULL } };

#ifdef HAVE_LIBARCHIVE

static void
propagate_libarchive_error (GError **error, struct archive *a)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", archive_error_string (a));
}

#endif

gboolean
ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
g_autoptr (GOptionContext) context = NULL;
g_autoptr (OstreeRepo) repo = NULL;
gboolean ret = FALSE;
g_autoptr (GFile) root = NULL;
g_autoptr (GFile) subtree = NULL;
g_autofree char *commit = NULL;
g_autoptr (GVariant) commit_data = NULL;
#ifdef HAVE_LIBARCHIVE
const char *rev;
g_autoptr (OtAutoArchiveWrite) a = NULL;
OstreeRepoExportArchiveOptions opts = {
0,
};
#endif

context = g_option_context_new ("COMMIT");
g_autoptr (GOptionContext) context = g_option_context_new ("COMMIT");

g_autoptr (OstreeRepo) repo = NULL;
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable,
error))
goto out;
return FALSE;

#ifdef HAVE_LIBARCHIVE

if (argc <= 1)
{
ot_util_usage_error (context, "A COMMIT argument is required", error);
goto out;
return FALSE;
}
rev = argv[1];
const char *rev = argv[1];

a = archive_write_new ();
g_autoptr (OtAutoArchiveWrite) a = archive_write_new ();
/* Yes, this is hardcoded for now. There is
* archive_write_set_format_filter_by_ext() but it's fairly magic.
* Many programs have support now for GNU tar, so should be a good
* default. I also don't want to lock us into everything libarchive
* supports.
*/
if (archive_write_set_format_gnutar (a) != ARCHIVE_OK)
{
propagate_libarchive_error (error, a);
goto out;
}
return glnx_throw (error, "%s", archive_error_string (a));
if (archive_write_add_filter_none (a) != ARCHIVE_OK)
{
propagate_libarchive_error (error, a);
goto out;
}
return glnx_throw (error, "%s", archive_error_string (a));
if (opt_output_path)
{
if (archive_write_open_filename (a, opt_output_path) != ARCHIVE_OK)
{
propagate_libarchive_error (error, a);
goto out;
}
return glnx_throw (error, "%s", archive_error_string (a));
}
else
{
if (archive_write_open_FILE (a, stdout) != ARCHIVE_OK)
{
propagate_libarchive_error (error, a);
goto out;
}
return glnx_throw (error, "%s", archive_error_string (a));
}

OstreeRepoExportArchiveOptions opts = {
0,
};
if (opt_no_xattrs)
opts.disable_xattrs = TRUE;

g_autofree char *commit = NULL;
g_autoptr (GFile) root = NULL;
if (!ostree_repo_read_commit (repo, rev, &root, &commit, cancellable, error))
goto out;
return FALSE;

g_autoptr (GVariant) commit_data = NULL;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit, &commit_data, error))
goto out;
return FALSE;

opts.timestamp_secs = ostree_commit_get_timestamp (commit_data);

g_autoptr (GFile) subtree = NULL;
if (opt_subpath)
subtree = g_file_resolve_relative_path (root, opt_subpath);
else
Expand All @@ -149,21 +120,15 @@ ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocatio

if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile *)subtree, a, cancellable,
error))
goto out;
return FALSE;

if (archive_write_close (a) != ARCHIVE_OK)
{
propagate_libarchive_error (error, a);
goto out;
}
return glnx_throw (error, "%s", archive_error_string (a));

return TRUE;
#else
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"This version of ostree is not compiled with libarchive support");
goto out;
return FALSE;
#endif

ret = TRUE;
out:
return ret;
}
46 changes: 18 additions & 28 deletions src/ostree/ot-builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,62 @@ static gboolean
log_commit (OstreeRepo *repo, const gchar *checksum, gboolean is_recurse, OstreeDumpFlags flags,
GError **error)
{
g_autoptr (GVariant) variant = NULL;
g_autofree char *parent = NULL;
gboolean ret = FALSE;
GError *local_error = NULL;

g_autoptr (GVariant) variant = NULL;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, &variant, &local_error))
{
if (is_recurse && g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_print ("<< History beyond this commit not fetched >>\n");
g_clear_error (&local_error);
ret = TRUE;
return TRUE;
}
else
{
g_propagate_error (error, local_error);
return FALSE;
}
goto out;
}

ot_dump_object (OSTREE_OBJECT_TYPE_COMMIT, checksum, variant, flags);

/* Get the parent of this commit */
parent = ostree_commit_get_parent (variant);
g_autofree char *parent = ostree_commit_get_parent (variant);
if (parent && !log_commit (repo, parent, TRUE, flags, error))
goto out;
return FALSE;

ret = TRUE;
out:
return ret;
return TRUE;
}

gboolean
ostree_builtin_log (int argc, char **argv, OstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
g_autoptr (GOptionContext) context = NULL;
g_autoptr (OstreeRepo) repo = NULL;
gboolean ret = FALSE;
const char *rev;
g_autofree char *checksum = NULL;
OstreeDumpFlags flags = OSTREE_DUMP_NONE;

context = g_option_context_new ("REV");
g_autoptr (GOptionContext) context = g_option_context_new ("REV");

g_autoptr (OstreeRepo) repo = NULL;
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable,
error))
goto out;

if (opt_raw)
flags |= OSTREE_DUMP_RAW;
return FALSE;

if (argc <= 1)
{
ot_util_usage_error (context, "A rev argument is required", error);
goto out;
return FALSE;
}
rev = argv[1];
const char *rev = argv[1];
OstreeDumpFlags flags = OSTREE_DUMP_NONE;
if (opt_raw)
flags |= OSTREE_DUMP_RAW;

g_autofree char *checksum = NULL;
if (!ostree_repo_resolve_rev (repo, rev, FALSE, &checksum, error))
goto out;
return FALSE;

if (!log_commit (repo, checksum, FALSE, flags, error))
goto out;
return FALSE;

ret = TRUE;
out:
return ret;
return TRUE;
}
26 changes: 9 additions & 17 deletions src/ostree/ot-remote-builtin-show-url.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,24 @@ gboolean
ot_remote_builtin_show_url (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;
const char *remote_name;
g_autofree char *remote_url = NULL;
gboolean ret = FALSE;

context = g_option_context_new ("NAME");

if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo,
cancellable, error))
goto out;
return FALSE;

if (argc < 2)
{
ot_util_usage_error (context, "NAME must be specified", error);
goto out;
return FALSE;
}

remote_name = argv[1];
const char *remote_name = argv[1];

if (ostree_repo_remote_get_url (repo, remote_name, &remote_url, error))
{
g_print ("%s\n", remote_url);
ret = TRUE;
}
g_autofree char *remote_url = NULL;
if (!ostree_repo_remote_get_url (repo, remote_name, &remote_url, error))
return FALSE;

out:
return ret;
g_print ("%s\n", remote_url);
return TRUE;
}

0 comments on commit 7c13631

Please sign in to comment.