Merge pull request #2644 from cgwalters/list-commit-objects

fsck: Don't load all object names into memory
This commit is contained in:
Colin Walters 2022-06-11 08:09:35 -04:00 committed by GitHub
commit e6ad897850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -4999,7 +4999,7 @@ ostree_repo_list_objects (OstreeRepo *self,
/** /**
* ostree_repo_list_commit_objects_starting_with: * ostree_repo_list_commit_objects_starting_with:
* @self: Repo * @self: Repo
* @start: List commits starting with this checksum * @start: List commits starting with this checksum (empty string for all)
* @out_commits: (out) (transfer container) (element-type GVariant GVariant): * @out_commits: (out) (transfer container) (element-type GVariant GVariant):
* Map of serialized commit name to variant data * Map of serialized commit name to variant data
* @cancellable: Cancellable * @cancellable: Cancellable
@ -5008,6 +5008,8 @@ ostree_repo_list_objects (OstreeRepo *self,
* This function synchronously enumerates all commit objects starting * This function synchronously enumerates all commit objects starting
* with @start, returning data in @out_commits. * with @start, returning data in @out_commits.
* *
* To list all commit objects, provide the empty string `""` for @start.
*
* Returns: %TRUE on success, %FALSE on error, and @error will be set * Returns: %TRUE on success, %FALSE on error, and @error will be set
*/ */
gboolean gboolean

View File

@ -282,17 +282,16 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation,
} }
if (!opt_quiet) if (!opt_quiet)
g_print ("Enumerating objects...\n"); g_print ("Enumerating commits...\n");
g_autoptr(GHashTable) objects = NULL; // Find all commit objects, including partial ones
if (!ostree_repo_list_objects (repo, OSTREE_REPO_LIST_OBJECTS_ALL, g_autoptr(GHashTable) all_commits = NULL;
&objects, cancellable, error)) if (!ostree_repo_list_commit_objects_starting_with (repo, "", &all_commits, cancellable, error))
return FALSE; return FALSE;
// And gather a set of non-partial commits for further analysis
g_autoptr(GHashTable) commits = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, g_autoptr(GHashTable) commits = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
(GDestroyNotify)g_variant_unref, NULL); (GDestroyNotify)g_variant_unref, NULL);
g_autoptr(GPtrArray) tombstones = NULL; g_autoptr(GPtrArray) tombstones = NULL;
if (opt_add_tombstones) if (opt_add_tombstones)
tombstones = g_ptr_array_new_with_free_func (g_free); tombstones = g_ptr_array_new_with_free_func (g_free);
@ -302,8 +301,8 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation,
guint n_partial = 0; guint n_partial = 0;
guint n_fsck_partial = 0; guint n_fsck_partial = 0;
g_hash_table_iter_init (&hash_iter, objects); g_hash_table_iter_init (&hash_iter, all_commits);
while (g_hash_table_iter_next (&hash_iter, &key, &value)) while (g_hash_table_iter_next (&hash_iter, &key, NULL))
{ {
GVariant *serialized_key = key; GVariant *serialized_key = key;
const char *checksum; const char *checksum;
@ -313,7 +312,9 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation,
ostree_object_name_deserialize (serialized_key, &checksum, &objtype); ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
if (objtype == OSTREE_OBJECT_TYPE_COMMIT) g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT);
if (TRUE) // Temporarily avoiding the noise of de-indenting this whole thing
{ {
if (!ostree_repo_load_commit (repo, checksum, &commit, &commitstate, error)) if (!ostree_repo_load_commit (repo, checksum, &commit, &commitstate, error))
return FALSE; return FALSE;
@ -420,7 +421,7 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation,
} }
} }
g_clear_pointer (&objects, g_hash_table_unref); g_clear_pointer (&all_commits, g_hash_table_unref);
if (!opt_quiet) if (!opt_quiet)
g_print ("Verifying content integrity of %u commit objects...\n", g_print ("Verifying content integrity of %u commit objects...\n",