bin/commit: move parent checking code higher up

No functional change. Prep for the next commit.

Closes: #1402
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-01-09 20:00:24 +00:00 committed by Atomic Bot
parent 2c2e6799be
commit 95e574d09b

View File

@ -466,6 +466,38 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
goto out;
}
if (!(opt_branch || opt_orphan))
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"A branch must be specified with --branch, or use --orphan");
goto out;
}
if (opt_parent)
{
if (g_str_equal (opt_parent, "none"))
parent = NULL;
else
{
if (!ostree_validate_checksum_string (opt_parent, error))
goto out;
parent = g_strdup (opt_parent);
}
}
else if (!opt_orphan)
{
if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
{
if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY))
{
/* A folder exists with the specified ref name,
* which is handled by _ostree_repo_write_ref */
g_clear_error (error);
}
else goto out;
}
}
if (opt_metadata_strings || opt_metadata_variants)
{
g_autoptr(GVariantBuilder) builder =
@ -493,13 +525,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
detached_metadata = g_variant_ref_sink (g_variant_builder_end (builder));
}
if (!(opt_branch || opt_orphan))
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"A branch must be specified with --branch, or use --orphan");
goto out;
}
if (opt_no_xattrs)
flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS;
if (opt_consume)
@ -543,31 +568,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
}
}
if (opt_parent)
{
if (g_str_equal (opt_parent, "none"))
parent = NULL;
else
{
if (!ostree_validate_checksum_string (opt_parent, error))
goto out;
parent = g_strdup (opt_parent);
}
}
else if (!opt_orphan)
{
if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
{
if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY))
{
/* A folder exists with the specified ref name,
* which is handled by _ostree_repo_write_ref */
g_clear_error (error);
}
else goto out;
}
}
if (opt_editor)
{
if (!commit_editor (repo, opt_branch, &opt_subject, &commit_body, cancellable, error))