GVariant *
rpmostreed_commit_generate_cached_details_variant (OstreeDeployment *deployment,
        OstreeRepo *repo,
        const gchar *refspec,
        GError **error)
{
    g_autoptr(GVariant) commit = NULL;
    g_autofree gchar *origin_refspec = NULL;
    g_autofree gchar *head = NULL;
    gboolean gpg_enabled;
    const gchar *osname;
    GVariant *sigs = NULL; /* floating variant */
    GVariantDict dict;

    osname = ostree_deployment_get_osname (deployment);

    if (refspec)
        origin_refspec = g_strdup (refspec);
    else
        origin_refspec = rpmostreed_deployment_get_refspec (deployment);

    g_assert (origin_refspec);

    /* allow_noent=TRUE since the ref may have been deleted for a
     * rebase.
     */
    if (!ostree_repo_resolve_rev (repo, origin_refspec,
                                  TRUE, &head, error))
        return NULL;

    if (head == NULL)
        head = g_strdup (ostree_deployment_get_csum (deployment));

    if (!ostree_repo_load_variant (repo,
                                   OSTREE_OBJECT_TYPE_COMMIT,
                                   head,
                                   &commit,
                                   error))
        return NULL;

    sigs = rpmostreed_deployment_gpg_results (repo, origin_refspec, head, &gpg_enabled);

    g_variant_dict_init (&dict, NULL);
    if (osname != NULL)
        g_variant_dict_insert (&dict, "osname", "s", osname);
    g_variant_dict_insert (&dict, "checksum", "s", head);
    variant_add_commit_details (&dict, commit);
    g_variant_dict_insert (&dict, "origin", "s", origin_refspec);
    if (sigs != NULL)
        g_variant_dict_insert_value (&dict, "signatures", sigs);
    g_variant_dict_insert (&dict, "gpg-enabled", "b", gpg_enabled);
    return g_variant_dict_end (&dict);
}
GVariant *
rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
                                        OstreeRepo *repo)
{
  g_autoptr(GVariant) commit = NULL;

  g_autofree gchar *origin_refspec = NULL;
  g_autofree gchar *version_commit = NULL;
  g_autofree gchar *id = NULL;

  GVariant *sigs = NULL; /* floating variant */
  GError *error = NULL;

  GVariantDict dict;
  guint64 timestamp = 0;

  const gchar *osname = ostree_deployment_get_osname (deployment);
  const gchar *csum = ostree_deployment_get_csum (deployment);
  gint serial = ostree_deployment_get_deployserial (deployment);
  id = rpmostreed_deployment_generate_id (deployment);

  if (ostree_repo_load_variant (repo,
                                OSTREE_OBJECT_TYPE_COMMIT,
                                csum,
                                &commit,
                                &error))
    {
      g_autoptr(GVariant) metadata = NULL;
      timestamp = ostree_commit_get_timestamp (commit);
      metadata = g_variant_get_child_value (commit, 0);
      if (metadata != NULL)
          g_variant_lookup (metadata, "version", "s", &version_commit);
    }
  else
    {
      g_warning ("Error loading commit %s", error->message);
    }
  g_clear_error (&error);

  origin_refspec = rpmostreed_deployment_get_refspec (deployment);
  if (origin_refspec)
    sigs = rpmostreed_deployment_gpg_results (repo, origin_refspec, csum);

  g_variant_dict_init (&dict, NULL);

  g_variant_dict_insert (&dict, "id", "s", id);
  if (osname != NULL)
    g_variant_dict_insert (&dict, "osname", "s", osname);
  g_variant_dict_insert (&dict, "serial", "i", serial);
  g_variant_dict_insert (&dict, "checksum", "s", csum);
  if (version_commit != NULL)
    g_variant_dict_insert (&dict, "version", "s", version_commit);
  if (timestamp > 0)
    g_variant_dict_insert (&dict, "timestamp", "t", timestamp);
  if (origin_refspec != NULL)
    g_variant_dict_insert (&dict, "origin", "s", origin_refspec);
  if (sigs != NULL)
    g_variant_dict_insert_value (&dict, "signatures", sigs);

  return g_variant_dict_end (&dict);
}