lib/repo-refs: Add first version of ostree_repo_resolve_collection_ref()
This is a parallel for ostree_repo_resolve_rev_ext() which works on collection–refs. At the moment, the implementation is simple and uses ostree_repo_list_collection_refs(). In future, it could be rewritten to check the checksum directly rather than enumerating all potentially-relevant checksums. Signed-off-by: Philip Withnall <withnall@endlessm.com> Closes: #1182 Approved by: cgwalters
This commit is contained in:
parent
9546e6795e
commit
149aec1099
|
|
@ -85,4 +85,5 @@ ostree_repo_list_collection_refs
|
|||
ostree_repo_remote_list_collection_refs
|
||||
ostree_repo_set_collection_ref_immediate
|
||||
ostree_repo_transaction_set_collection_ref
|
||||
ostree_repo_resolve_collection_ref
|
||||
</SECTION>
|
||||
|
|
|
|||
|
|
@ -77,3 +77,8 @@ global:
|
|||
ostree_repo_transaction_set_collection_ref;
|
||||
ostree_validate_collection_id;
|
||||
} LIBOSTREE_2017.7_EXPERIMENTAL;
|
||||
|
||||
LIBOSTREE_2017.12_EXPERIMENTAL {
|
||||
global:
|
||||
ostree_repo_resolve_collection_ref;
|
||||
} LIBOSTREE_2017.8_EXPERIMENTAL;
|
||||
|
|
|
|||
|
|
@ -468,6 +468,69 @@ ostree_repo_resolve_rev_ext (OstreeRepo *self,
|
|||
return _ostree_repo_resolve_rev_internal (self, refspec, allow_noent, FALSE, out_rev, error);
|
||||
}
|
||||
|
||||
#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
|
||||
/**
|
||||
* ostree_repo_resolve_collection_ref:
|
||||
* @self: an #OstreeRepo
|
||||
* @ref: a collection–ref to resolve
|
||||
* @allow_noent: %TRUE to not throw an error if @ref doesn’t exist
|
||||
* @flags: options controlling behaviour
|
||||
* @out_rev: (out) (transfer full) (optional) (nullable): return location for
|
||||
* the checksum corresponding to @ref, or %NULL if @allow_noent is %TRUE and
|
||||
* the @ref could not be found
|
||||
* @cancellable: (nullable): a #GCancellable, or %NULL
|
||||
* @error: return location for a #GError, or %NULL
|
||||
*
|
||||
* Look up the checksum for the given collection–ref, returning it in @out_rev.
|
||||
* This will search through the mirrors and remote refs.
|
||||
*
|
||||
* If @allow_noent is %TRUE and the given @ref cannot be found, %TRUE will be
|
||||
* returned and @out_rev will be set to %NULL. If @allow_noent is %FALSE and
|
||||
* the given @ref cannot be found, a %G_IO_ERROR_NOT_FOUND error will be
|
||||
* returned.
|
||||
*
|
||||
* There are currently no @flags which affect the behaviour of this function.
|
||||
*
|
||||
* Returns: %TRUE on success, %FALSE on failure
|
||||
* Since: 2017.12
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_resolve_collection_ref (OstreeRepo *self,
|
||||
const OstreeCollectionRef *ref,
|
||||
gboolean allow_noent,
|
||||
OstreeRepoResolveRevExtFlags flags,
|
||||
char **out_rev,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE);
|
||||
g_return_val_if_fail (ref != NULL, FALSE);
|
||||
g_return_val_if_fail (ref->collection_id != NULL && ref->ref_name != NULL, FALSE);
|
||||
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
g_autoptr(GHashTable) refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
if (!ostree_repo_list_collection_refs (self, ref->collection_id, &refs,
|
||||
OSTREE_REPO_LIST_REFS_EXT_NONE,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
const char *ret_contents = g_hash_table_lookup (refs, ref);
|
||||
|
||||
if (ret_contents == NULL && !allow_noent)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Collection–ref (%s, %s) not found",
|
||||
ref->collection_id, ref->ref_name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (out_rev != NULL)
|
||||
*out_rev = g_strdup (ret_contents);
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
|
||||
|
||||
static gboolean
|
||||
enumerate_refs_recurse (OstreeRepo *repo,
|
||||
const char *remote,
|
||||
|
|
|
|||
|
|
@ -471,6 +471,17 @@ gboolean ostree_repo_resolve_rev_ext (OstreeRepo *self,
|
|||
char **out_rev,
|
||||
GError **error);
|
||||
|
||||
#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_resolve_collection_ref (OstreeRepo *self,
|
||||
const OstreeCollectionRef *ref,
|
||||
gboolean allow_noent,
|
||||
OstreeRepoResolveRevExtFlags flags,
|
||||
char **out_rev,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_list_refs (OstreeRepo *self,
|
||||
const char *refspec_prefix,
|
||||
|
|
|
|||
Loading…
Reference in New Issue