lib/repo-pull: Use resolve() instead of list() in fetch_ref_contents()
authorPhilip Withnall <withnall@endlessm.com>
Tue, 26 Sep 2017 14:17:47 +0000 (15:17 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 27 Sep 2017 14:44:00 +0000 (14:44 +0000)
This is more efficient in the non-collection case; in the collection
case, the implementation of ostree_repo_resolve_collection_ref() needs
to be rewritten to improve efficiency.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #1182
Approved by: cgwalters

src/libostree/ostree-repo-pull.c

index 4e6031d64760394f074658dad2df739a1c7f949b..4aff9e091972d159c71e9aefd1bbec609b994114 100644 (file)
@@ -839,26 +839,22 @@ fetch_ref_contents (OtPullData                 *pull_data,
   if (pull_data->remote_repo_local != NULL && ref->collection_id != NULL)
     {
 #ifdef OSTREE_ENABLE_EXPERIMENTAL_API
-      g_autoptr(GHashTable) refs = NULL;  /* (element-type OstreeCollectionRef utf8) */
-      if (!ostree_repo_list_collection_refs (pull_data->remote_repo_local,
-                                             ref->collection_id, &refs,
-                                             OSTREE_REPO_LIST_REFS_EXT_NONE,
-                                             cancellable, error))
+      if (!ostree_repo_resolve_collection_ref (pull_data->remote_repo_local,
+                                               ref, TRUE  /* ignore enoent */,
+                                               OSTREE_REPO_RESOLVE_REV_EXT_NONE,
+                                               &ret_contents, cancellable, error))
         return FALSE;
-
-      ret_contents = g_strdup (g_hash_table_lookup (refs, ref));
 #else  /* if !OSTREE_ENABLE_EXPERIMENTAL_API */
       g_assert_not_reached ();
 #endif  /* !OSTREE_ENABLE_EXPERIMENTAL_API */
     }
   else if (pull_data->remote_repo_local != NULL)
     {
-      g_autoptr(GHashTable) refs = NULL;  /* (element-type utf8 utf8) */
-      if (!ostree_repo_list_refs (pull_data->remote_repo_local, NULL,
-                                  &refs, cancellable, error))
+      if (!ostree_repo_resolve_rev_ext (pull_data->remote_repo_local,
+                                        ref->ref_name, TRUE  /* ignore enoent */,
+                                        OSTREE_REPO_RESOLVE_REV_EXT_NONE,
+                                        &ret_contents, error))
         return FALSE;
-
-      ret_contents = g_strdup (g_hash_table_lookup (refs, ref->ref_name));
     }
   else
     {
@@ -877,9 +873,11 @@ fetch_ref_contents (OtPullData                 *pull_data,
     }
 
   /* Validate and return. */
-  g_strchomp (ret_contents);
+  if (ret_contents != NULL)
+    g_strchomp (ret_contents);
 
-  if (!ostree_validate_checksum_string (ret_contents, error))
+  if (ret_contents == NULL ||
+      !ostree_validate_checksum_string (ret_contents, error))
     return glnx_prefix_error (error, "Fetching checksum for ref (%s, %s)",
                               ref->collection_id ? ref->collection_id : "(empty)",
                               ref->ref_name);