mirror of
https://github.com/flatpak/flatpak.git
synced 2026-03-24 09:52:48 -04:00
Add flatpak_dir_list_remote_refs_decomposed()
This commit is contained in:
committed by
Alexander Larsson
parent
7465ba0f18
commit
089a5bebd5
@@ -920,6 +920,11 @@ gboolean flatpak_dir_list_remote_refs (FlatpakDir *self,
|
||||
GHashTable **refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean flatpak_dir_list_remote_refs_decomposed (FlatpakDir *self,
|
||||
FlatpakRemoteState *state,
|
||||
GHashTable **refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean flatpak_dir_list_all_remote_refs (FlatpakDir *self,
|
||||
FlatpakRemoteState *state,
|
||||
GHashTable **out_all_refs,
|
||||
|
||||
@@ -14136,9 +14136,9 @@ flatpak_dir_modify_remote (FlatpakDir *self,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
remove_unless_in_hash (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
remove_unless_ref_in_hash (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
{
|
||||
GHashTable *table = user_data;
|
||||
const char *ref_name = key;
|
||||
@@ -14190,13 +14190,74 @@ flatpak_dir_list_remote_refs (FlatpakDir *self,
|
||||
|
||||
/* Then we remove all remote refs not in the local refs set */
|
||||
g_hash_table_foreach_remove (*refs,
|
||||
remove_unless_in_hash,
|
||||
remove_unless_ref_in_hash,
|
||||
unprefixed_local_refs);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
remove_unless_decomposed_in_hash (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
{
|
||||
GHashTable *table = user_data;
|
||||
const FlatpakDecomposed *d = key;
|
||||
|
||||
return !g_hash_table_contains (table, d);
|
||||
}
|
||||
|
||||
gboolean
|
||||
flatpak_dir_list_remote_refs_decomposed (FlatpakDir *self,
|
||||
FlatpakRemoteState *state,
|
||||
GHashTable **refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GError) my_error = NULL;
|
||||
|
||||
if (error == NULL)
|
||||
error = &my_error;
|
||||
|
||||
if (!flatpak_dir_list_all_remote_refs_decomposed (self, state, refs,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (flatpak_dir_get_remote_noenumerate (self, state->remote_name))
|
||||
{
|
||||
g_autoptr(GHashTable) decomposed_local_refs =
|
||||
g_hash_table_new_full ((GHashFunc)flatpak_decomposed_hash, (GEqualFunc)flatpak_decomposed_equal, (GDestroyNotify)flatpak_decomposed_unref, NULL);
|
||||
g_autoptr(GHashTable) local_refs = NULL;
|
||||
GHashTableIter hash_iter;
|
||||
gpointer key;
|
||||
g_autofree char *refspec_prefix = g_strconcat (state->remote_name, ":.", NULL);
|
||||
|
||||
/* For noenumerate remotes, only return data for already locally
|
||||
* available refs */
|
||||
|
||||
if (!ostree_repo_list_refs (self->repo, refspec_prefix, &local_refs,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
g_hash_table_iter_init (&hash_iter, local_refs);
|
||||
while (g_hash_table_iter_next (&hash_iter, &key, NULL))
|
||||
{
|
||||
const char *refspec = key;
|
||||
g_autoptr(FlatpakDecomposed) d = flatpak_decomposed_new_from_refspec (refspec, NULL);
|
||||
if (d)
|
||||
g_hash_table_insert (decomposed_local_refs, g_steal_pointer (&d), NULL);
|
||||
}
|
||||
|
||||
/* Then we remove all remote refs not in the local refs set */
|
||||
g_hash_table_foreach_remove (*refs,
|
||||
remove_unless_decomposed_in_hash,
|
||||
decomposed_local_refs);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
strv_contains_prefix (const gchar * const *strv,
|
||||
const gchar *str)
|
||||
|
||||
Reference in New Issue
Block a user