app/db-diff: Add --base switch

Support a `--base` switch to perform the diff on the base layer if
deployment checksum was locally composed. This is useful to filter out
from the diff changes due to layered packages.

Closes: #1299
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-03-12 15:28:15 +00:00 committed by Atomic Bot
parent 4e99052d07
commit d6172ddee2
2 changed files with 30 additions and 2 deletions

View File

@ -28,11 +28,13 @@
static char *opt_format = "block";
static gboolean opt_changelogs;
static char *opt_sysroot;
static gboolean opt_base;
static GOptionEntry option_entries[] = {
{ "format", 'F', 0, G_OPTION_ARG_STRING, &opt_format, "Output format: \"diff\" or (default) \"block\"", "FORMAT" },
{ "changelogs", 'c', 0, G_OPTION_ARG_NONE, &opt_changelogs, "Also output RPM changelogs", NULL },
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "base", 0, 0, G_OPTION_ARG_NONE, &opt_base, "Diff against deployments' base, not layered commits", NULL },
{ NULL }
};
@ -93,6 +95,27 @@ print_diff (OstreeRepo *repo,
return TRUE;
}
static gboolean
get_checksum_from_deployment (OstreeRepo *repo,
OstreeDeployment *deployment,
char **out_checksum,
GError **error)
{
g_autofree char *checksum = NULL;
if (opt_base)
{
if (!rpmostree_deployment_get_layered_info (repo, deployment, NULL, &checksum,
NULL, NULL, NULL, error))
return FALSE;
}
if (!checksum)
checksum = g_strdup (ostree_deployment_get_csum (deployment));
*out_checksum = g_steal_pointer (&checksum);
return TRUE;
}
gboolean
rpmostree_db_builtin_diff (int argc, char **argv,
RpmOstreeCommandInvocation *invocation,
@ -132,7 +155,8 @@ rpmostree_db_builtin_diff (int argc, char **argv,
return glnx_throw (error, "Not booted into any deployment");
old_desc = "booted deployment";
old_checksum = g_strdup (ostree_deployment_get_csum (booted));
if (!get_checksum_from_deployment (repo, booted, &old_checksum, error))
return FALSE;
if (argc < 2)
{
@ -142,7 +166,8 @@ rpmostree_db_builtin_diff (int argc, char **argv,
ostree_sysroot_query_deployments_for (sysroot, NULL, &pending, NULL);
if (!pending || ostree_deployment_equal (pending, booted))
return glnx_throw (error, "No pending deployment to diff against");
new_checksum = g_strdup (ostree_deployment_get_csum (pending));
if (!get_checksum_from_deployment (repo, pending, &new_checksum, error))
return FALSE;
}
else
{

View File

@ -74,6 +74,9 @@ check_diff "$pending_csum" "" \
+pkg-to-replace \
+pkg-to-replace-archtrans
# check that diff'ing with --base yields 0 diffs
check_not_diff "--base" "" pkg-to-
# now let's make the pending csum become an update
vm_cmd ostree commit -b vmcheck --tree=ref=$pending_csum
vm_rpmostree cleanup -p