main/commit: Rework control flow to use --tree=X path

Rework the simple cases of "commit ." and "commit argv[1]" to
generate the more general "--tree=X --tree=Y" path, so that we
only have one primary control flow here.

Prep for a future patch around loading SELinux policy from
the first argument.
This commit is contained in:
Colin Walters 2020-03-21 17:54:13 +00:00
parent d87301b111
commit a717535490
1 changed files with 99 additions and 101 deletions

View File

@ -601,18 +601,24 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
mtree = ostree_mutable_tree_new ();
if (argc <= 1 && (opt_trees == NULL || opt_trees[0] == NULL))
/* Convert implicit . or explicit path via argv into
* --tree=dir= so that we only have one primary code path below.
*/
if (opt_trees == NULL || opt_trees[0] == NULL)
{
if (!ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, ".", mtree, modifier,
cancellable, error))
goto out;
char *path;
if (argc <= 1)
path = ".";
else
path = argv[1];
opt_trees = g_new0 (char *, 2);
opt_trees[0] = g_strconcat ("dir=", path, NULL);
}
else if (opt_trees != NULL)
{
const char *const*tree_iter;
const char *tree;
const char *eq;
g_assert (opt_trees && *opt_trees);
for (tree_iter = (const char *const*)opt_trees; *tree_iter; tree_iter++)
{
tree = *tree_iter;
@ -715,14 +721,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
goto out;
}
}
}
else
{
g_assert (argc > 1);
if (!ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, argv[1], mtree, modifier,
cancellable, error))
goto out;
}
if (mode_adds && g_hash_table_size (mode_adds) > 0)
{