bin/commit: Support committing archives from stdin

This commit interprets archive filenames specified as '-' to
indicate that the input should be read from stdin.

Closes: #1862
Approved by: jlebon
This commit is contained in:
Tristan Van Berkom 2019-05-21 22:26:55 +09:00 committed by Atomic Bot
parent da4d0245af
commit bebd8d6980
1 changed files with 23 additions and 6 deletions

View File

@ -636,11 +636,22 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
{ {
if (!opt_tar_pathname_filter) if (!opt_tar_pathname_filter)
{ {
object_to_commit = g_file_new_for_path (tree); if (strcmp (tree, "-") == 0)
if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier, {
opt_tar_autocreate_parents, if (!ostree_repo_write_archive_to_mtree_from_fd (repo, STDIN_FILENO, mtree, modifier,
cancellable, error)) opt_tar_autocreate_parents,
goto out; cancellable, error))
goto out;
}
else
{
object_to_commit = g_file_new_for_path (tree);
if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier,
opt_tar_autocreate_parents,
cancellable, error))
goto out;
}
} }
else else
{ {
@ -666,7 +677,13 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
goto out; goto out;
} }
opts.translate_pathname_user_data = &tpdata; opts.translate_pathname_user_data = &tpdata;
g_autoptr(OtAutoArchiveRead) archive = ot_open_archive_read (tree, error);
g_autoptr(OtAutoArchiveRead) archive;
if (strcmp (tree, "-") == 0)
archive = ot_open_archive_read_fd (STDIN_FILENO, error);
else
archive = ot_open_archive_read (tree, error);
if (!archive) if (!archive)
goto out; goto out;
if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree, if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree,