return glnx_prefix_error (error, "Loading commit for ref %s", refname);
}
+#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
+ if (!opt_quiet)
+ g_print ("Validating refs in collections...\n");
+
+ g_autoptr(GHashTable) all_collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
+ if (!ostree_repo_list_collection_refs (repo, NULL, &all_collection_refs,
+ cancellable, error))
+ return FALSE;
+
+ g_hash_table_iter_init (&hash_iter, all_collection_refs);
+ while (g_hash_table_iter_next (&hash_iter, &key, &value))
+ {
+ const OstreeCollectionRef *ref = key;
+ const char *checksum = value;
+ g_autoptr(GVariant) commit = NULL;
+ if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
+ checksum, &commit, error))
+ return glnx_prefix_error (error, "Loading commit for ref (%s, %s)",
+ ref->collection_id, ref->ref_name);
+ }
+#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
+
if (!opt_quiet)
g_print ("Enumerating objects...\n");
static gboolean
delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *cancellable, GError **error)
{
- g_autoptr(GHashTable) refs = NULL;
+ g_autoptr(GHashTable) refs = NULL; /* (element-type utf8 utf8) */
+#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
+ g_autoptr(GHashTable) collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
+#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
GHashTableIter hashiter;
gpointer hashkey, hashvalue;
gboolean ret = FALSE;
+ /* Check refs which are not in a collection. */
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
goto out;
}
}
+#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
+ /* And check refs which *are* in a collection. */
+ if (!ostree_repo_list_collection_refs (repo, NULL, &collection_refs, cancellable, error))
+ goto out;
+
+ g_hash_table_iter_init (&hashiter, collection_refs);
+ while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
+ {
+ const OstreeCollectionRef *ref = hashkey;
+ const char *commit = hashvalue;
+ if (g_strcmp0 (commit_to_delete, commit) == 0)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Commit '%s' is referenced by (%s, %s)",
+ commit_to_delete, ref->collection_id, ref->ref_name);
+ goto out;
+ }
+ }
+#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
+
if (!ot_enable_tombstone_commits (repo, error))
goto out;
}
/* We start from the refs */
+ /* FIXME: Do we also want to look at ostree_repo_list_collection_refs()? */
if (!ostree_repo_list_refs (repo, NULL, &all_refs,
cancellable, error))
return FALSE;
const char *target = NULL;
g_autofree char *checksum = NULL;
+ /* FIXME: Add support for collection–refs. */
context = g_option_context_new ("REF COMMIT - Reset a REF to a previous COMMIT");
if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))