diff options
author | Matthew Leeds <matthew.leeds@endlessm.com> | 2019-02-21 15:47:16 -0800 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2019-04-15 15:56:40 +0000 |
commit | 78747a8a17fccf73486fe9e74b180f4cc8c2ad72 (patch) | |
tree | 5f1d814b37f421c34aefb2b327ff609ea565fddd | |
parent | 0ecbc6f2a9ddd6ab9700e98da794eef7290ffdc7 (diff) | |
download | ostree-78747a8a17fccf73486fe9e74b180f4cc8c2ad72.tar.gz |
lib/repo-refs: Allow resolving local collection-refs
Currently for a "normal" refspec you can choose to use
ostree_repo_resolve_rev_ext() instead of ostree_repo_resolve_rev() if
you only want to look at local refs (in refs/heads/) not remote ones.
This commit provides the analogous functionality for
ostree_repo_resolve_collection_ref() by adding a flag
OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY and implementing it. This
will be used by Flatpak.
Closes: #1825
Approved by: jlebon
-rw-r--r-- | src/libostree/ostree-repo-refs.c | 28 | ||||
-rw-r--r-- | src/libostree/ostree-repo.h | 2 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index fec36420..c512787a 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -479,6 +479,9 @@ ostree_repo_resolve_rev (OstreeRepo *self, * the parameter @out_rev. Differently from ostree_repo_resolve_rev(), * this will not fall back to searching through remote repos if a * local ref is specified but not found. + * + * The flag %OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY is implied so + * using it has no effect. */ gboolean ostree_repo_resolve_rev_ext (OstreeRepo *self, @@ -511,7 +514,9 @@ ostree_repo_resolve_rev_ext (OstreeRepo *self, * 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. + * If you want to check only local refs, not remote or mirrored ones, use the + * flag %OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY. This is analogous to using + * ostree_repo_resolve_rev_ext() but for collection-refs. * * Returns: %TRUE on success, %FALSE on failure * Since: 2018.6 @@ -539,7 +544,16 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, { g_mutex_lock (&self->txn_lock); if (self->txn.collection_refs) - ret_contents = g_strdup (g_hash_table_lookup (self->txn.collection_refs, ref)); + { + const char *repo_collection_id = ostree_repo_get_collection_id (self); + /* If the collection ID doesn't match it's a remote ref */ + if (!(flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY) || + repo_collection_id == NULL || + g_strcmp0 (repo_collection_id, ref->collection_id) == 0) + { + ret_contents = g_strdup (g_hash_table_lookup (self->txn.collection_refs, ref)); + } + } g_mutex_unlock (&self->txn_lock); } @@ -547,9 +561,15 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, if (ret_contents == NULL) { g_autoptr(GHashTable) refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + OstreeRepoListRefsExtFlags list_refs_flags; + + if (flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY) + list_refs_flags = OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES | OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS; + else + list_refs_flags = OSTREE_REPO_LIST_REFS_EXT_NONE; + if (!ostree_repo_list_collection_refs (self, ref->collection_id, &refs, - OSTREE_REPO_LIST_REFS_EXT_NONE, - cancellable, error)) + list_refs_flags, cancellable, error)) return FALSE; ret_contents = g_strdup (g_hash_table_lookup (refs, ref)); diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index d24077c9..afa33155 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -465,9 +465,11 @@ gboolean ostree_repo_resolve_rev (OstreeRepo *self, /** * OstreeRepoResolveRevExtFlags: * @OSTREE_REPO_RESOLVE_REV_EXT_NONE: No flags. + * @OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY: Exclude remote and mirrored refs. Since: 2019.2 */ typedef enum { OSTREE_REPO_RESOLVE_REV_EXT_NONE = 0, + OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY = (1 << 0), } OstreeRepoResolveRevExtFlags; _OSTREE_PUBLIC |