Merge pull request #2059 from cgwalters/commit-from-base-tree

commit: Add --base argument
This commit is contained in:
OpenShift Merge Robot 2020-04-06 22:18:49 +02:00 committed by GitHub
commit 1b0eec02d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 2 deletions

View File

@ -106,6 +106,15 @@ Boston, MA 02111-1307, USA.
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--base</option>="REV"</term>
<listitem><para>
Start from the content in a commit. This differs from <literal>--tree=ref=REV</literal> in that no commit modifiers are applied. This is usually what you want when
creating a derived commit. This is also used for <literal>--selinux-policy-from-base</literal>.
</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--add-metadata-string</option>="KEY=VALUE"</term> <term><option>--add-metadata-string</option>="KEY=VALUE"</term>

View File

@ -58,6 +58,7 @@ static gboolean opt_selinux_policy_from_base;
static gboolean opt_canonical_permissions; static gboolean opt_canonical_permissions;
static gboolean opt_consume; static gboolean opt_consume;
static gboolean opt_devino_canonical; static gboolean opt_devino_canonical;
static char *opt_base;
static char **opt_trees; static char **opt_trees;
static gint opt_owner_uid = -1; static gint opt_owner_uid = -1;
static gint opt_owner_gid = -1; static gint opt_owner_gid = -1;
@ -101,6 +102,7 @@ static GOptionEntry options[] = {
{ "orphan", 0, 0, G_OPTION_ARG_NONE, &opt_orphan, "Create a commit without writing a ref", NULL }, { "orphan", 0, 0, G_OPTION_ARG_NONE, &opt_orphan, "Create a commit without writing a ref", NULL },
{ "no-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_no_bindings, "Do not write any ref bindings", NULL }, { "no-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_no_bindings, "Do not write any ref bindings", NULL },
{ "bind-ref", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_bind_refs, "Add a ref to ref binding commit metadata", "BRANCH" }, { "bind-ref", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_bind_refs, "Add a ref to ref binding commit metadata", "BRANCH" },
{ "base", 0, 0, G_OPTION_ARG_STRING, &opt_base, "Start from the given commit as a base (no modifiers apply)" },
{ "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", "dir=PATH or tar=TARFILE or ref=COMMIT" }, { "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", "dir=PATH or tar=TARFILE or ref=COMMIT" },
{ "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_strings, "Add a key/value pair to metadata", "KEY=VALUE" }, { "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_strings, "Add a key/value pair to metadata", "KEY=VALUE" },
{ "add-metadata", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_variants, "Add a key/value pair to metadata, where the KEY is a string, an VALUE is g_variant_parse() formatted", "KEY=VALUE" }, { "add-metadata", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_variants, "Add a key/value pair to metadata, where the KEY is a string, an VALUE is g_variant_parse() formatted", "KEY=VALUE" },
@ -600,7 +602,32 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
if (opt_link_checkout_speedup && !ostree_repo_scan_hardlinks (repo, cancellable, error)) if (opt_link_checkout_speedup && !ostree_repo_scan_hardlinks (repo, cancellable, error))
goto out; goto out;
if (opt_base)
{
g_autofree char *base_commit = NULL;
g_autoptr(GFile) root = NULL;
if (!ostree_repo_read_commit (repo, opt_base, &root, &base_commit, cancellable, error))
goto out;
OstreeRepoFile *rootf = (OstreeRepoFile*) root;
mtree = ostree_mutable_tree_new_from_checksum (repo,
ostree_repo_file_tree_get_contents_checksum (rootf),
ostree_repo_file_tree_get_metadata_checksum (rootf));
if (opt_selinux_policy_from_base)
{
g_assert (modifier);
if (!ostree_repo_commit_modifier_set_sepolicy_from_commit (modifier, repo, base_commit, cancellable, error))
goto out;
/* Don't try to handle it twice */
opt_selinux_policy_from_base = FALSE;
}
}
else
{
mtree = ostree_mutable_tree_new (); mtree = ostree_mutable_tree_new ();
}
/* Convert implicit . or explicit path via argv into /* Convert implicit . or explicit path via argv into
* --tree=dir= so that we only have one primary code path below. * --tree=dir= so that we only have one primary code path below.

View File

@ -68,3 +68,11 @@ echo "ok cat-file"
cd ${test_tmpdir} cd ${test_tmpdir}
$OSTREE fsck $OSTREE fsck
echo "ok fsck" echo "ok fsck"
mkdir -p test-overlays
date > test-overlays/overlaid-file
$OSTREE commit ${COMMIT_ARGS} -b test-base --base test2 --owner-uid 42 --owner-gid 42 test-overlays/
$OSTREE ls -R test-base > ls.txt
assert_streq "$(wc -l < ls.txt)" 14
assert_streq "$(grep '42.*42' ls.txt | wc -l)" 2
echo "ok commit overlay base"

View File

@ -23,7 +23,7 @@ set -euo pipefail
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh
echo '1..12' echo '1..13'
setup_test_repository "archive" setup_test_repository "archive"