lib/pull: Minor refactoring of metadata scanning function
authorColin Walters <walters@verbum.org>
Sat, 23 Sep 2017 13:44:49 +0000 (09:44 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 26 Sep 2017 18:07:43 +0000 (18:07 +0000)
Make the "local repo" processing conditional the same as the "localcache" bits;
this is really just a de-indent. Also add some comments. Prep for further work.

Closes: #1212
Approved by: jlebon

src/libostree/ostree-repo-pull.c

index d8048e757e4b905e7d7512dc689b0f8eddf8b67e..bb34f2f61533b3dfc9d9ca9caff60cf29da1d4b0 100644 (file)
@@ -1749,35 +1749,36 @@ scan_one_metadata_object_c (OtPullData                 *pull_data,
   g_autofree char *tmp_checksum = ostree_checksum_from_bytes (csum);
   g_autoptr(GVariant) object = ostree_object_name_serialize (tmp_checksum, objtype);
 
+  /* It may happen that we've already looked at this object (think shared
+   * dirtree subtrees), if that's the case, we're done */
   if (g_hash_table_lookup (pull_data->scanned_metadata, object))
     return TRUE;
 
   gboolean is_requested = g_hash_table_lookup (pull_data->requested_metadata, object) != NULL;
+  /* Determine if we already have the object */
   gboolean is_stored;
   if (!ostree_repo_has_object (pull_data->repo, objtype, tmp_checksum, &is_stored,
                                cancellable, error))
     return FALSE;
 
-  if (pull_data->remote_repo_local)
+  /* Are we pulling an object we don't have from a local repo? */
+  if (!is_stored && pull_data->remote_repo_local)
     {
-      if (!is_stored)
+      if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
         {
-          if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
-            {
-              /* mark as partial to ensure we scan the commit below */
-              if (!write_commitpartial_for (pull_data, tmp_checksum, error))
-                return FALSE;
-            }
-          if (!ostree_repo_import_object_from_with_trust (pull_data->repo, pull_data->remote_repo_local,
-                                                          objtype, tmp_checksum, !pull_data->is_untrusted,
-                                                          cancellable, error))
+          /* mark as partial to ensure we scan the commit below */
+          if (!write_commitpartial_for (pull_data, tmp_checksum, error))
             return FALSE;
-          /* The import API will fetch both the commit and detached metadata, so
-           * add it to the hash to avoid re-fetching it below.
-           */
-          if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
-            g_hash_table_add (pull_data->fetched_detached_metadata, g_strdup (tmp_checksum));
         }
+      if (!ostree_repo_import_object_from_with_trust (pull_data->repo, pull_data->remote_repo_local,
+                                                      objtype, tmp_checksum, !pull_data->is_untrusted,
+                                                      cancellable, error))
+        return FALSE;
+      /* The import API will fetch both the commit and detached metadata, so
+       * add it to the hash to avoid re-fetching it below.
+       */
+      if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
+        g_hash_table_add (pull_data->fetched_detached_metadata, g_strdup (tmp_checksum));
       is_stored = TRUE;
       is_requested = TRUE;
     }