codebase: start using GLNX_HASH_TABLE_FOREACH macros

Use the new macros introduced recently in libglnx to make iterating over
hash tables cleaner. This is just a start, it does not migrate the whole
tree.

Update submodule: libglnx

Closes: #971
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-06-28 08:06:50 -07:00 committed by Atomic Bot
parent ba918e49c5
commit 373dc4b66c
9 changed files with 59 additions and 163 deletions

View File

@ -48,15 +48,11 @@ OstreeBootconfigParser *
ostree_bootconfig_parser_clone (OstreeBootconfigParser *self) ostree_bootconfig_parser_clone (OstreeBootconfigParser *self)
{ {
OstreeBootconfigParser *parser = ostree_bootconfig_parser_new (); OstreeBootconfigParser *parser = ostree_bootconfig_parser_new ();
guint i;
GHashTableIter hashiter;
gpointer k, v;
for (i = 0; i < self->lines->len; i++) for (guint i = 0; i < self->lines->len; i++)
g_ptr_array_add (parser->lines, g_variant_ref (self->lines->pdata[i])); g_ptr_array_add (parser->lines, g_variant_ref (self->lines->pdata[i]));
g_hash_table_iter_init (&hashiter, self->options); GLNX_HASH_TABLE_FOREACH_KV (self->options, const char*, k, const char*, v)
while (g_hash_table_iter_next (&hashiter, &k, &v))
g_hash_table_replace (parser->options, g_strdup (k), g_strdup (v)); g_hash_table_replace (parser->options, g_strdup (k), g_strdup (v));
return parser; return parser;
@ -183,14 +179,11 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
} }
} }
GHashTableIter hashiter; GLNX_HASH_TABLE_FOREACH_KV (self->options, const char*, k, const char*, v)
gpointer hashkey, hashvalue;
g_hash_table_iter_init (&hashiter, self->options);
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
{ {
if (g_hash_table_lookup (written_overrides, hashkey)) if (g_hash_table_lookup (written_overrides, k))
continue; continue;
write_key (self, buf, hashkey, hashvalue); write_key (self, buf, k, v);
} }
if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len, if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len,

View File

@ -690,9 +690,6 @@ static void
adopt_steal_mainctx (OstreeFetcher *self, adopt_steal_mainctx (OstreeFetcher *self,
GMainContext *mainctx) GMainContext *mainctx)
{ {
GHashTableIter hiter;
gpointer key, value;
g_assert (self->mainctx == NULL); g_assert (self->mainctx == NULL);
self->mainctx = mainctx; /* Transfer */ self->mainctx = mainctx; /* Transfer */
@ -706,13 +703,9 @@ adopt_steal_mainctx (OstreeFetcher *self,
update_timeout_cb (self->multi, timeout_micros / 1000, self); update_timeout_cb (self->multi, timeout_micros / 1000, self);
} }
g_hash_table_iter_init (&hiter, self->sockets); GLNX_HASH_TABLE_FOREACH (self->sockets, SockInfo*, fdp)
while (g_hash_table_iter_next (&hiter, &key, &value))
{
SockInfo *fdp = key;
setsock (fdp, fdp->sockfd, fdp->action, self); setsock (fdp, fdp->sockfd, fdp->action, self);
} }
}
static void static void
initiate_next_curl_request (FetcherRequest *req, initiate_next_curl_request (FetcherRequest *req,

View File

@ -1323,24 +1323,18 @@ _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
guint64 guint64
_ostree_fetcher_bytes_transferred (OstreeFetcher *self) _ostree_fetcher_bytes_transferred (OstreeFetcher *self)
{ {
GHashTableIter hiter;
gpointer key, value;
guint64 ret;
g_return_val_if_fail (OSTREE_IS_FETCHER (self), 0); g_return_val_if_fail (OSTREE_IS_FETCHER (self), 0);
g_mutex_lock (&self->thread_closure->output_stream_set_lock); g_mutex_lock (&self->thread_closure->output_stream_set_lock);
ret = self->thread_closure->total_downloaded; guint64 ret = self->thread_closure->total_downloaded;
g_hash_table_iter_init (&hiter, self->thread_closure->output_stream_set); GLNX_HASH_TABLE_FOREACH (self->thread_closure->output_stream_set,
while (g_hash_table_iter_next (&hiter, &key, &value)) GFileOutputStream*, stream)
{ {
GFileOutputStream *stream = key;
struct stat stbuf;
if (G_IS_FILE_DESCRIPTOR_BASED (stream)) if (G_IS_FILE_DESCRIPTOR_BASED (stream))
{ {
struct stat stbuf;
if (glnx_stream_fstat ((GFileDescriptorBased*)stream, &stbuf, NULL)) if (glnx_stream_fstat ((GFileDescriptorBased*)stream, &stbuf, NULL))
ret += stbuf.st_size; ret += stbuf.st_size;
} }

View File

@ -114,9 +114,6 @@ ostree_mutable_tree_set_contents_checksum (OstreeMutableTree *self,
const char * const char *
ostree_mutable_tree_get_contents_checksum (OstreeMutableTree *self) ostree_mutable_tree_get_contents_checksum (OstreeMutableTree *self)
{ {
GHashTableIter iter;
gpointer key, value;
if (!self->contents_checksum) if (!self->contents_checksum)
return NULL; return NULL;
@ -127,10 +124,8 @@ ostree_mutable_tree_get_contents_checksum (OstreeMutableTree *self)
* *
* However, we only call this function once right now. * However, we only call this function once right now.
*/ */
g_hash_table_iter_init (&iter, self->subdirs); GLNX_HASH_TABLE_FOREACH_V (self->subdirs, OstreeMutableTree*, subdir)
while (g_hash_table_iter_next (&iter, &key, &value))
{ {
OstreeMutableTree *subdir = value;
if (!ostree_mutable_tree_get_contents_checksum (subdir)) if (!ostree_mutable_tree_get_contents_checksum (subdir))
{ {
g_free (self->contents_checksum); g_free (self->contents_checksum);

View File

@ -1088,13 +1088,12 @@ ostree_repo_checkout_gc (OstreeRepo *self,
self->updated_uncompressed_dirs = g_hash_table_new (NULL, NULL); self->updated_uncompressed_dirs = g_hash_table_new (NULL, NULL);
g_mutex_unlock (&self->cache_lock); g_mutex_unlock (&self->cache_lock);
GHashTableIter iter; if (!to_clean_dirs)
gpointer key, value; return TRUE; /* Note early return */
if (to_clean_dirs)
g_hash_table_iter_init (&iter, to_clean_dirs); GLNX_HASH_TABLE_FOREACH (to_clean_dirs, guint, prefix)
while (to_clean_dirs && g_hash_table_iter_next (&iter, &key, &value))
{ {
g_autofree char *objdir_name = g_strdup_printf ("%02x", GPOINTER_TO_UINT (key)); g_autofree char *objdir_name = g_strdup_printf ("%02x", prefix);
g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
if (!glnx_dirfd_iterator_init_at (self->uncompressed_objects_dir_fd, objdir_name, FALSE, if (!glnx_dirfd_iterator_init_at (self->uncompressed_objects_dir_fd, objdir_name, FALSE,

View File

@ -369,26 +369,17 @@ add_size_index_to_metadata (OstreeRepo *self,
if (self->object_sizes && if (self->object_sizes &&
g_hash_table_size (self->object_sizes) > 0) g_hash_table_size (self->object_sizes) > 0)
{ {
GHashTableIter entries = { 0 };
gchar *e_checksum = NULL;
OstreeContentSizeCacheEntry *e_size = NULL;
GVariantBuilder index_builder; GVariantBuilder index_builder;
guint i;
g_autoptr(GPtrArray) sorted_keys = NULL;
g_hash_table_iter_init (&entries, self->object_sizes);
g_variant_builder_init (&index_builder, g_variant_builder_init (&index_builder,
G_VARIANT_TYPE ("a" _OSTREE_OBJECT_SIZES_ENTRY_SIGNATURE)); G_VARIANT_TYPE ("a" _OSTREE_OBJECT_SIZES_ENTRY_SIGNATURE));
/* Sort the checksums so we can bsearch if desired */ /* Sort the checksums so we can bsearch if desired */
sorted_keys = g_ptr_array_new (); g_autoptr(GPtrArray) sorted_keys = g_ptr_array_new ();
while (g_hash_table_iter_next (&entries, GLNX_HASH_TABLE_FOREACH (self->object_sizes, const char*, e_checksum)
(gpointer *) &e_checksum, g_ptr_array_add (sorted_keys, (gpointer)e_checksum);
(gpointer *) &e_size))
g_ptr_array_add (sorted_keys, e_checksum);
g_ptr_array_sort (sorted_keys, compare_ascii_checksums_for_sorting); g_ptr_array_sort (sorted_keys, compare_ascii_checksums_for_sorting);
for (i = 0; i < sorted_keys->len; i++) for (guint i = 0; i < sorted_keys->len; i++)
{ {
guint8 csum[OSTREE_SHA256_DIGEST_LEN]; guint8 csum[OSTREE_SHA256_DIGEST_LEN];
const char *e_checksum = sorted_keys->pdata[i]; const char *e_checksum = sorted_keys->pdata[i];
@ -397,7 +388,8 @@ add_size_index_to_metadata (OstreeRepo *self,
ostree_checksum_inplace_to_bytes (e_checksum, csum); ostree_checksum_inplace_to_bytes (e_checksum, csum);
g_string_append_len (buffer, (char*)csum, sizeof (csum)); g_string_append_len (buffer, (char*)csum, sizeof (csum));
e_size = g_hash_table_lookup (self->object_sizes, e_checksum); OstreeContentSizeCacheEntry *e_size =
g_hash_table_lookup (self->object_sizes, e_checksum);
_ostree_write_varuint64 (buffer, e_size->archived); _ostree_write_varuint64 (buffer, e_size->archived);
_ostree_write_varuint64 (buffer, e_size->unpacked); _ostree_write_varuint64 (buffer, e_size->unpacked);
@ -2234,8 +2226,6 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
GHashTable *dir_contents_checksums, GHashTable *dir_contents_checksums,
GHashTable *dir_metadata_checksums) GHashTable *dir_metadata_checksums)
{ {
GHashTableIter hash_iter;
gpointer key, value;
GVariantBuilder files_builder; GVariantBuilder files_builder;
GVariantBuilder dirs_builder; GVariantBuilder dirs_builder;
GSList *sorted_filenames = NULL; GSList *sorted_filenames = NULL;
@ -2245,11 +2235,8 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
g_variant_builder_init (&files_builder, G_VARIANT_TYPE ("a(say)")); g_variant_builder_init (&files_builder, G_VARIANT_TYPE ("a(say)"));
g_variant_builder_init (&dirs_builder, G_VARIANT_TYPE ("a(sayay)")); g_variant_builder_init (&dirs_builder, G_VARIANT_TYPE ("a(sayay)"));
g_hash_table_iter_init (&hash_iter, file_checksums); GLNX_HASH_TABLE_FOREACH (file_checksums, const char*, name)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *name = key;
/* Should have been validated earlier, but be paranoid */ /* Should have been validated earlier, but be paranoid */
g_assert (ot_util_filename_validate (name, NULL)); g_assert (ot_util_filename_validate (name, NULL));
@ -2270,13 +2257,8 @@ create_tree_variant_from_hashes (GHashTable *file_checksums,
g_slist_free (sorted_filenames); g_slist_free (sorted_filenames);
sorted_filenames = NULL; sorted_filenames = NULL;
GLNX_HASH_TABLE_FOREACH (dir_metadata_checksums, const char*, name)
g_hash_table_iter_init (&hash_iter, dir_metadata_checksums);
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{
const char *name = key;
sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name); sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name);
}
sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp); sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp);
@ -2993,15 +2975,10 @@ ostree_repo_write_mtree (OstreeRepo *self,
dir_metadata_checksums = g_hash_table_new_full (g_str_hash, g_str_equal, dir_metadata_checksums = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free); (GDestroyNotify)g_free, (GDestroyNotify)g_free);
GHashTableIter hash_iter; GLNX_HASH_TABLE_FOREACH_KV (ostree_mutable_tree_get_subdirs (mtree),
gpointer key, value; const char*, name, OstreeMutableTree*, child_dir)
g_hash_table_iter_init (&hash_iter, ostree_mutable_tree_get_subdirs (mtree));
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *name = key;
g_autoptr(GFile) child_file = NULL; g_autoptr(GFile) child_file = NULL;
OstreeMutableTree *child_dir = value;
if (!ostree_repo_write_mtree (self, child_dir, &child_file, if (!ostree_repo_write_mtree (self, child_dir, &child_file,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;

View File

@ -773,14 +773,11 @@ aic_import_deferred_hardlinks (OstreeRepoArchiveImportContext *ctx,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GHashTableIter iter; GLNX_HASH_TABLE_FOREACH_KV (ctx->deferred_hardlinks, const char*, target, GSList*, links)
gpointer key, value; {
if (!aic_import_deferred_hardlinks_for (ctx, target, links, error))
g_hash_table_iter_init (&iter, ctx->deferred_hardlinks);
while (g_hash_table_iter_next (&iter, &key, &value))
if (!aic_import_deferred_hardlinks_for (ctx, key, value, error))
return FALSE; return FALSE;
}
return TRUE; return TRUE;
} }

View File

@ -232,8 +232,6 @@ repo_prune_internal (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GHashTableIter hash_iter;
gpointer key, value;
OtPruneData data = { 0, }; OtPruneData data = { 0, };
data.repo = self; data.repo = self;
@ -241,11 +239,8 @@ repo_prune_internal (OstreeRepo *self,
g_autoptr(GHashTable) reachable_owned = g_hash_table_ref (options->reachable); g_autoptr(GHashTable) reachable_owned = g_hash_table_ref (options->reachable);
data.reachable = reachable_owned; data.reachable = reachable_owned;
g_hash_table_iter_init (&hash_iter, objects); GLNX_HASH_TABLE_FOREACH_KV (objects, GVariant*, serialized_key, GVariant*, objdata)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
GVariant *serialized_key = key;
GVariant *objdata = value;
const char *checksum; const char *checksum;
OstreeObjectType objtype; OstreeObjectType objtype;
gboolean is_loose; gboolean is_loose;
@ -309,13 +304,10 @@ ostree_repo_prune (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GHashTableIter hash_iter;
gpointer key, value;
g_autoptr(GHashTable) objects = NULL; g_autoptr(GHashTable) objects = NULL;
g_autoptr(GHashTable) reachable = NULL;
gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY; gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
reachable = ostree_repo_traverse_new_reachable (); g_autoptr(GHashTable) reachable = ostree_repo_traverse_new_reachable ();
/* This original prune API has fixed logic for traversing refs or all commits /* This original prune API has fixed logic for traversing refs or all commits
* combined with actually deleting content. The newer backend API just does * combined with actually deleting content. The newer backend API just does
@ -331,12 +323,8 @@ ostree_repo_prune (OstreeRepo *self,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
g_hash_table_iter_init (&hash_iter, all_refs); GLNX_HASH_TABLE_FOREACH_V (all_refs, const char*, checksum)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *checksum = value;
g_debug ("Finding objects to keep for commit %s", checksum); g_debug ("Finding objects to keep for commit %s", checksum);
if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable, if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable,
cancellable, error)) cancellable, error))
@ -350,12 +338,8 @@ ostree_repo_prune (OstreeRepo *self,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
g_hash_table_iter_init (&hash_iter, all_collection_refs); GLNX_HASH_TABLE_FOREACH_V (all_collection_refs, const char*, checksum)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *checksum = value;
g_debug ("Finding objects to keep for commit %s", checksum); g_debug ("Finding objects to keep for commit %s", checksum);
if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable, if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable,
cancellable, error)) cancellable, error))
@ -369,10 +353,8 @@ ostree_repo_prune (OstreeRepo *self,
if (!refs_only) if (!refs_only)
{ {
g_hash_table_iter_init (&hash_iter, objects); GLNX_HASH_TABLE_FOREACH (objects, GVariant*, serialized_key)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
GVariant *serialized_key = key;
const char *checksum; const char *checksum;
OstreeObjectType objtype; OstreeObjectType objtype;

View File

@ -2023,23 +2023,19 @@ get_best_static_delta_start_for (OtPullData *pull_data,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GHashTableIter hiter;
gpointer hkey, hvalue;
/* Array<char*> of possible from checksums */ /* Array<char*> of possible from checksums */
g_autoptr(GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free); g_autoptr(GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free);
const char *newest_candidate = NULL; const char *newest_candidate = NULL;
guint64 newest_candidate_timestamp = 0; guint64 newest_candidate_timestamp = 0;
g_assert (pull_data->summary_deltas_checksums != NULL); g_assert (pull_data->summary_deltas_checksums != NULL);
g_hash_table_iter_init (&hiter, pull_data->summary_deltas_checksums);
*out_have_scratch_delta = FALSE; *out_have_scratch_delta = FALSE;
/* Loop over all deltas known from the summary file, /* Loop over all deltas known from the summary file,
* finding ones which go to to_revision */ * finding ones which go to to_revision */
while (g_hash_table_iter_next (&hiter, &hkey, &hvalue)) GLNX_HASH_TABLE_FOREACH (pull_data->summary_deltas_checksums, const char*, delta_name)
{ {
const char *delta_name = hkey;
g_autofree char *cur_from_rev = NULL; g_autofree char *cur_from_rev = NULL;
g_autofree char *cur_to_rev = NULL; g_autofree char *cur_to_rev = NULL;
@ -2893,8 +2889,6 @@ ostree_repo_pull_with_options (OstreeRepo *self,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GHashTableIter hash_iter;
gpointer key, value;
g_autoptr(GBytes) bytes_summary = NULL; g_autoptr(GBytes) bytes_summary = NULL;
g_autofree char *metalink_url_str = NULL; g_autofree char *metalink_url_str = NULL;
g_autoptr(GHashTable) requested_refs_to_fetch = NULL; /* (element-type OstreeCollectionRef utf8) */ g_autoptr(GHashTable) requested_refs_to_fetch = NULL; /* (element-type OstreeCollectionRef utf8) */
@ -3539,15 +3533,13 @@ ostree_repo_pull_with_options (OstreeRepo *self,
/* Resolve the checksum for each ref. This has to be done into a new hash table, /* Resolve the checksum for each ref. This has to be done into a new hash table,
* since we cant modify the keys of @requested_refs_to_fetch while iterating * since we cant modify the keys of @requested_refs_to_fetch while iterating
* over it, and we need to ensure the collection IDs are resolved too. */ * over it, and we need to ensure the collection IDs are resolved too. */
g_hash_table_iter_init (&hash_iter, requested_refs_to_fetch);
updated_requested_refs_to_fetch = g_hash_table_new_full (ostree_collection_ref_hash, updated_requested_refs_to_fetch = g_hash_table_new_full (ostree_collection_ref_hash,
ostree_collection_ref_equal, ostree_collection_ref_equal,
(GDestroyNotify) ostree_collection_ref_free, (GDestroyNotify) ostree_collection_ref_free,
g_free); g_free);
while (g_hash_table_iter_next (&hash_iter, &key, &value)) GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref,
const char*, override_commitid)
{ {
const OstreeCollectionRef *ref = key;
const char *override_commitid = value;
g_autofree char *contents = NULL; g_autofree char *contents = NULL;
/* Support specifying "" for an override commitid */ /* Support specifying "" for an override commitid */
@ -3621,20 +3613,16 @@ ostree_repo_pull_with_options (OstreeRepo *self,
g_debug ("resuming legacy transaction"); g_debug ("resuming legacy transaction");
/* Initiate requests for explicit commit revisions */ /* Initiate requests for explicit commit revisions */
g_hash_table_iter_init (&hash_iter, commits_to_fetch); GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char*, commit)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *commit = value;
if (!initiate_request (pull_data, NULL, commit, error)) if (!initiate_request (pull_data, NULL, commit, error))
goto out; goto out;
} }
/* Initiate requests for refs */ /* Initiate requests for refs */
g_hash_table_iter_init (&hash_iter, requested_refs_to_fetch); GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref,
while (g_hash_table_iter_next (&hash_iter, &key, &value)) const char*, to_revision)
{ {
const OstreeCollectionRef *ref = key;
const char *to_revision = value;
if (!initiate_request (pull_data, ref, to_revision, error)) if (!initiate_request (pull_data, ref, to_revision, error))
goto out; goto out;
} }
@ -3671,11 +3659,9 @@ ostree_repo_pull_with_options (OstreeRepo *self,
g_assert_cmpint (pull_data->n_outstanding_content_fetches, ==, 0); g_assert_cmpint (pull_data->n_outstanding_content_fetches, ==, 0);
g_assert_cmpint (pull_data->n_outstanding_content_write_requests, ==, 0); g_assert_cmpint (pull_data->n_outstanding_content_write_requests, ==, 0);
g_hash_table_iter_init (&hash_iter, requested_refs_to_fetch); GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref,
while (g_hash_table_iter_next (&hash_iter, &key, &value)) const char*, checksum)
{ {
const OstreeCollectionRef *ref = key;
const char *checksum = value;
g_autofree char *remote_ref = NULL; g_autofree char *remote_ref = NULL;
g_autofree char *original_rev = NULL; g_autofree char *original_rev = NULL;
@ -3762,22 +3748,16 @@ ostree_repo_pull_with_options (OstreeRepo *self,
/* iterate over commits fetched and delete any commitpartial files */ /* iterate over commits fetched and delete any commitpartial files */
if (pull_data->dirs == NULL && !pull_data->is_commit_only) if (pull_data->dirs == NULL && !pull_data->is_commit_only)
{ {
g_hash_table_iter_init (&hash_iter, requested_refs_to_fetch); GLNX_HASH_TABLE_FOREACH_V (requested_refs_to_fetch, const char*, checksum)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *checksum = value;
g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (checksum); g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (checksum);
if (!ot_ensure_unlinked_at (pull_data->repo->repo_dir_fd, commitpartial_path, 0)) if (!ot_ensure_unlinked_at (pull_data->repo->repo_dir_fd, commitpartial_path, 0))
goto out; goto out;
} }
g_hash_table_iter_init (&hash_iter, commits_to_fetch); GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char*, commit)
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *commit = value;
g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (commit); g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (commit);
if (!ot_ensure_unlinked_at (pull_data->repo->repo_dir_fd, commitpartial_path, 0)) if (!ot_ensure_unlinked_at (pull_data->repo->repo_dir_fd, commitpartial_path, 0))
goto out; goto out;
} }
@ -4326,18 +4306,16 @@ find_remotes_cb (GObject *obj,
GCancellable *cancellable; GCancellable *cancellable;
const FindRemotesData *data; const FindRemotesData *data;
const OstreeCollectionRef * const *refs; const OstreeCollectionRef * const *refs;
OstreeAsyncProgress *progress; /* FIXME: We currently do nothing with @progress. Comment out to assuage -Wunused-variable */
/* OstreeAsyncProgress *progress; */
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */
gsize i; gsize i;
GHashTableIter iter;
CommitMetadata *commit_metadata;
g_autoptr(PointerTable) refs_and_remotes_table = NULL; /* (element-type commit-checksum) */ g_autoptr(PointerTable) refs_and_remotes_table = NULL; /* (element-type commit-checksum) */
g_autoptr(GHashTable) commit_metadatas = NULL; /* (element-type commit-checksum CommitMetadata) */ g_autoptr(GHashTable) commit_metadatas = NULL; /* (element-type commit-checksum CommitMetadata) */
g_autoptr(OstreeFetcher) fetcher = NULL; g_autoptr(OstreeFetcher) fetcher = NULL;
g_autofree const gchar **ref_to_latest_commit = NULL; /* indexed as @refs; (element-type commit-checksum) */ g_autofree const gchar **ref_to_latest_commit = NULL; /* indexed as @refs; (element-type commit-checksum) */
gsize n_refs; gsize n_refs;
const gchar *checksum;
g_autoptr(GPtrArray) remotes_to_remove = NULL; /* (element-type OstreeRemote) */ g_autoptr(GPtrArray) remotes_to_remove = NULL; /* (element-type OstreeRemote) */
g_autoptr(GPtrArray) final_results = NULL; /* (element-type OstreeRepoFinderResult) */ g_autoptr(GPtrArray) final_results = NULL; /* (element-type OstreeRepoFinderResult) */
@ -4347,7 +4325,7 @@ find_remotes_cb (GObject *obj,
data = g_task_get_task_data (task); data = g_task_get_task_data (task);
refs = (const OstreeCollectionRef * const *) data->refs; refs = (const OstreeCollectionRef * const *) data->refs;
progress = data->progress; /* progress = data->progress; */
/* Finish finding the remotes. */ /* Finish finding the remotes. */
results = ostree_repo_finder_resolve_all_finish (result, &error); results = ostree_repo_finder_resolve_all_finish (result, &error);
@ -4383,8 +4361,6 @@ find_remotes_cb (GObject *obj,
* estimation for the actual pull operation. This should check the * estimation for the actual pull operation. This should check the
* disable-static-deltas option first. */ * disable-static-deltas option first. */
/* FIXME: We currently do nothing with @progress. */
/* Each key must be a pointer to the #CommitMetadata.checksum field of its value. */ /* Each key must be a pointer to the #CommitMetadata.checksum field of its value. */
commit_metadatas = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) commit_metadata_free); commit_metadatas = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) commit_metadata_free);
@ -4496,9 +4472,7 @@ find_remotes_cb (GObject *obj,
* the commit metadata from the remotes. The most recent commits are the * the commit metadata from the remotes. The most recent commits are the
* set of head commits pointed to by the refs we just resolved from the * set of head commits pointed to by the refs we just resolved from the
* summary files. */ * summary files. */
g_hash_table_iter_init (&iter, commit_metadatas); GLNX_HASH_TABLE_FOREACH_V (commit_metadatas, CommitMetadata*, commit_metadata)
while (g_hash_table_iter_next (&iter, (gpointer *) &checksum, (gpointer *) &commit_metadata))
{ {
char buf[_OSTREE_LOOSE_PATH_MAX]; char buf[_OSTREE_LOOSE_PATH_MAX];
g_autofree gchar *commit_filename = NULL; g_autofree gchar *commit_filename = NULL;
@ -4853,9 +4827,6 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self,
g_autoptr(GHashTable) refs_pulled = NULL; /* (element-type OstreeCollectionRef gboolean) */ g_autoptr(GHashTable) refs_pulled = NULL; /* (element-type OstreeCollectionRef gboolean) */
gsize i, j; gsize i, j;
g_autoptr(GString) refs_unpulled_string = NULL; g_autoptr(GString) refs_unpulled_string = NULL;
GHashTableIter iter;
const OstreeCollectionRef *ref;
gpointer is_pulled_pointer;
g_autoptr(GError) local_error = NULL; g_autoptr(GError) local_error = NULL;
g_auto(GVariantDict) options_dict = OT_VARIANT_BUILDER_INITIALIZER; g_auto(GVariantDict) options_dict = OT_VARIANT_BUILDER_INITIALIZER;
OstreeRepoPullFlags flags; OstreeRepoPullFlags flags;
@ -4900,16 +4871,14 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self,
g_auto(GVariantBuilder) refs_to_pull_builder = OT_VARIANT_BUILDER_INITIALIZER; g_auto(GVariantBuilder) refs_to_pull_builder = OT_VARIANT_BUILDER_INITIALIZER;
g_auto(GVariantDict) local_options_dict = OT_VARIANT_BUILDER_INITIALIZER; g_auto(GVariantDict) local_options_dict = OT_VARIANT_BUILDER_INITIALIZER;
g_autoptr(GVariant) local_options = NULL; g_autoptr(GVariant) local_options = NULL;
const gchar *checksum;
gboolean remove_remote; gboolean remove_remote;
refs_to_pull = g_ptr_array_new_with_free_func (NULL); refs_to_pull = g_ptr_array_new_with_free_func (NULL);
refs_to_pull_str = g_string_new (""); refs_to_pull_str = g_string_new ("");
g_variant_builder_init (&refs_to_pull_builder, G_VARIANT_TYPE ("a(sss)")); g_variant_builder_init (&refs_to_pull_builder, G_VARIANT_TYPE ("a(sss)"));
g_hash_table_iter_init (&iter, result->ref_to_checksum); GLNX_HASH_TABLE_FOREACH_KV (result->ref_to_checksum, const OstreeCollectionRef*, ref,
const char*, checksum)
while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum))
{ {
if (checksum != NULL && if (checksum != NULL &&
!GPOINTER_TO_INT (g_hash_table_lookup (refs_pulled, ref))) !GPOINTER_TO_INT (g_hash_table_lookup (refs_pulled, ref)))
@ -4996,12 +4965,9 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self,
} }
/* Any refs left un-downloaded? If so, weve failed. */ /* Any refs left un-downloaded? If so, weve failed. */
g_hash_table_iter_init (&iter, refs_pulled); GLNX_HASH_TABLE_FOREACH_KV (refs_pulled, const OstreeCollectionRef*, ref,
gboolean, is_pulled)
while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &is_pulled_pointer))
{ {
gboolean is_pulled = GPOINTER_TO_INT (is_pulled_pointer);
if (is_pulled) if (is_pulled)
continue; continue;