ostree/builtins: Add support for collection–refs to a few utilities
These utilities were not needed for the initial port to support OstreeCollectionRef, so have been delayed a bit and, in some cases, left as FIXME comments for follow up later. Signed-off-by: Philip Withnall <withnall@endlessm.com> Closes: #924 Approved by: cgwalters
This commit is contained in:
parent
18456d25fb
commit
3dd4848c96
|
|
@ -241,6 +241,28 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
|
||||||
return glnx_prefix_error (error, "Loading commit for ref %s", refname);
|
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)
|
if (!opt_quiet)
|
||||||
g_print ("Enumerating objects...\n");
|
g_print ("Enumerating objects...\n");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,15 @@ static GOptionEntry options[] = {
|
||||||
static gboolean
|
static gboolean
|
||||||
delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *cancellable, GError **error)
|
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;
|
GHashTableIter hashiter;
|
||||||
gpointer hashkey, hashvalue;
|
gpointer hashkey, hashvalue;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
/* Check refs which are not in a collection. */
|
||||||
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
|
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -71,6 +75,26 @@ delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *can
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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))
|
if (!ot_enable_tombstone_commits (repo, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -249,6 +273,7 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We start from the refs */
|
/* 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,
|
if (!ostree_repo_list_refs (repo, NULL, &all_refs,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,8 @@ ostree_builtin_pull_local (int argc, char **argv, GCancellable *cancellable, GEr
|
||||||
if (!ostree_repo_open (src_repo, cancellable, error))
|
if (!ostree_repo_open (src_repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
/* FIXME: This should grow support for pulling refs from refs/mirrors on
|
||||||
|
* a local repository, using ostree_repo_list_collection_refs(). */
|
||||||
if (!ostree_repo_list_refs (src_repo, NULL, &refs_to_clone,
|
if (!ostree_repo_list_refs (src_repo, NULL, &refs_to_clone,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ ostree_builtin_reset (int argc,
|
||||||
const char *target = NULL;
|
const char *target = NULL;
|
||||||
g_autofree char *checksum = 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");
|
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))
|
if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue