Skip to content

Commit

Permalink
compose: Add --parent option
Browse files Browse the repository at this point in the history
This may seem like a backflip on coreos#1829, but there's a common theme here:
in a promotion workflow, the parent (or lack of parent) of a commit is
an important parameter, so we need full flexibility in configuring it.

But again, like coreos#1829, we still want e.g. change detection, versioning,
and various optimizations to happen on whatever the latest commit on
that ref is in the build repo.
  • Loading branch information
jlebon committed Jul 18, 2019
1 parent 8c6402d commit 157261e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/app/rpmostree-compose-builtin-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static char *opt_write_composejson_to;
static gboolean opt_no_parent;
static char *opt_write_lockfile;
static char *opt_read_lockfile;
static char *opt_parent;

/* shared by both install & commit */
static GOptionEntry common_option_entries[] = {
Expand Down Expand Up @@ -116,6 +117,7 @@ static GOptionEntry commit_option_entries[] = {
{ "write-commitid-to", 0, 0, G_OPTION_ARG_STRING, &opt_write_commitid_to, "File to write the composed commitid to instead of updating the ref", "FILE" },
{ "write-composejson-to", 0, 0, G_OPTION_ARG_STRING, &opt_write_composejson_to, "Write JSON to FILE containing information about the compose run", "FILE" },
{ "no-parent", 0, 0, G_OPTION_ARG_NONE, &opt_no_parent, "Always commit without a parent", NULL },
{ "parent", 0, 0, G_OPTION_ARG_STRING, &opt_parent, "Commit with specific parent", "REV" },
{ NULL }
};

Expand Down Expand Up @@ -1063,7 +1065,12 @@ impl_commit_tree (RpmOstreeTreeComposeContext *self,
}

g_autofree char *parent_revision = NULL;
if (self->ref && !opt_no_parent)
if (opt_parent)
{
if (!ostree_repo_resolve_rev (self->repo, opt_parent, FALSE, &parent_revision, error))
return FALSE;
}
else if (self->ref && !opt_no_parent)
{
if (!ostree_repo_resolve_rev (self->repo, self->ref, TRUE, &parent_revision, error))
return FALSE;
Expand Down
17 changes: 13 additions & 4 deletions src/app/rpmostree-composeutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,20 @@ rpmostree_composeutil_write_composejson (OstreeRepo *repo,
g_autofree char *parent_revision = ostree_commit_get_parent (new_commit);
if (path && parent_revision)
{
g_autoptr(GVariant) diffv = NULL;
if (!rpm_ostree_db_diff_variant (repo, parent_revision, new_revision,
FALSE, &diffv, NULL, error))
/* don't error if the parent doesn't exist */
gboolean parent_exists;
if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_COMMIT, parent_revision,
&parent_exists, NULL, error))
return FALSE;
g_variant_builder_add (builder, "{sv}", "pkgdiff", diffv);

if (parent_exists)
{
g_autoptr(GVariant) diffv = NULL;
if (!rpm_ostree_db_diff_variant (repo, parent_revision, new_revision,
TRUE, &diffv, NULL, error))
return FALSE;
g_variant_builder_add (builder, "{sv}", "pkgdiff", diffv);
}
}

if (path)
Expand Down
5 changes: 5 additions & 0 deletions tests/compose-tests/libbasic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ echo "ok compose pkglist"
ostree --repo=${repobuild} cat ${treeref} /usr/share/rpm-ostree/treefile.json > treefile.json
assert_jq treefile.json '.basearch == "x86_64"'
echo "ok basearch"

ostree --repo=${repobuild} rev-parse ${treeref}^ > parent.txt
assert_file_has_content parent.txt 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
echo "ok --parent"
}

4 changes: 3 additions & 1 deletion tests/compose-tests/test-basic-unified.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ cat > metadata.json <<EOF
"overrideme": "new val"
}
EOF
runcompose --ex-unified-core --add-metadata-from-json metadata.json
# Test --parent at the same time (hash is `echo | sha256sum`)
runcompose --ex-unified-core --add-metadata-from-json metadata.json \
--parent 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b

# Run it again, but without RPMOSTREE_PRESERVE_TMPDIR. Should be a no-op. This
# exercises fd handling in the tree context.
Expand Down
4 changes: 3 additions & 1 deletion tests/compose-tests/test-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ cat > metadata.json <<EOF
"overrideme": "new val"
}
EOF
runcompose --add-metadata-from-json metadata.json
# Test --parent at the same time (hash is `echo | sha256sum`)
runcompose --add-metadata-from-json metadata.json \
--parent 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b

. ${dn}/libbasic-test.sh
basic_test
Expand Down

0 comments on commit 157261e

Please sign in to comment.