diff options
author | Colin Walters <walters@verbum.org> | 2018-04-30 14:31:33 +0000 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-24 12:56:11 +0000 |
commit | 371081d123a9263d8dbdd4dad69c0468e2db427d (patch) | |
tree | ad8d4d792a63a42473a92d3a8620a46f752a36b3 | |
parent | ce2995e1dc1557c4d97ef5af807eacf3ef4a22d8 (diff) | |
download | ostree-371081d123a9263d8dbdd4dad69c0468e2db427d.tar.gz |
lib: Add a public helper method for pruning to find all ref'd commits
Prep for reworking how we do sysroot cleanup. We're going to
start doing more lowlevel pruning work there, and I wanted to avoid
duplicating the ref enumeration.
Closes: #1566
Approved by: jlebon
-rw-r--r-- | apidoc/ostree-sections.txt | 1 | ||||
-rw-r--r-- | src/libostree/libostree-devel.sym | 1 | ||||
-rw-r--r-- | src/libostree/ostree-repo-prune.c | 87 | ||||
-rw-r--r-- | src/libostree/ostree-repo.h | 8 |
4 files changed, 69 insertions, 28 deletions
diff --git a/apidoc/ostree-sections.txt b/apidoc/ostree-sections.txt index 5162b2f7..6d4a3423 100644 --- a/apidoc/ostree-sections.txt +++ b/apidoc/ostree-sections.txt @@ -413,6 +413,7 @@ ostree_repo_commit_traverse_iter_next OstreeRepoPruneFlags ostree_repo_prune ostree_repo_prune_static_deltas +ostree_repo_traverse_reachable_refs ostree_repo_prune_from_reachable OstreeRepoPullFlags ostree_repo_pull diff --git a/src/libostree/libostree-devel.sym b/src/libostree/libostree-devel.sym index b217e3e5..eb3b3211 100644 --- a/src/libostree/libostree-devel.sym +++ b/src/libostree/libostree-devel.sym @@ -19,6 +19,7 @@ /* Add new symbols here. Release commits should copy this section into -released.sym. */ LIBOSTREE_2018.6 { + ostree_repo_traverse_reachable_refs; } LIBOSTREE_2018.5; /* Stub section for the stable release *after* this development one; don't diff --git a/src/libostree/ostree-repo-prune.c b/src/libostree/ostree-repo-prune.c index 4c883542..b93d35ac 100644 --- a/src/libostree/ostree-repo-prune.c +++ b/src/libostree/ostree-repo-prune.c @@ -302,6 +302,64 @@ repo_prune_internal (OstreeRepo *self, } /** + * ostree_repo_traverse_reachable_refs: + * @self: Repo + * @depth: Depth of traversal + * @reachable: (element-type GVariant GVariant): Set of reachable objects (will be modified) + * @cancellable: Cancellable + * @error: Error + * + * Add all commit objects directly reachable via a ref to @reachable. + * + * Locking: shared + * Since: 2018.6 + */ +gboolean +ostree_repo_traverse_reachable_refs (OstreeRepo *self, + guint depth, + GHashTable *reachable, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(OstreeRepoAutoLock) lock = + _ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_SHARED, cancellable, error); + if (!lock) + return FALSE; + + /* Ignoring collections. */ + g_autoptr(GHashTable) all_refs = NULL; /* (element-type utf8 utf8) */ + + if (!ostree_repo_list_refs (self, NULL, &all_refs, + cancellable, error)) + return FALSE; + + GLNX_HASH_TABLE_FOREACH_V (all_refs, const char*, checksum) + { + g_debug ("Finding objects to keep for commit %s", checksum); + if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable, + cancellable, error)) + return FALSE; + } + + /* Using collections. */ + g_autoptr(GHashTable) all_collection_refs = NULL; /* (element-type OstreeChecksumRef utf8) */ + + if (!ostree_repo_list_collection_refs (self, NULL, &all_collection_refs, + OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable, error)) + return FALSE; + + GLNX_HASH_TABLE_FOREACH_V (all_collection_refs, const char*, checksum) + { + g_debug ("Finding objects to keep for commit %s", checksum); + if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable, + cancellable, error)) + return FALSE; + } + + return TRUE; +} + +/** * ostree_repo_prune: * @self: Repo * @flags: Options controlling prune process @@ -355,35 +413,8 @@ ostree_repo_prune (OstreeRepo *self, if (refs_only) { - /* Ignoring collections. */ - g_autoptr(GHashTable) all_refs = NULL; /* (element-type utf8 utf8) */ - - if (!ostree_repo_list_refs (self, NULL, &all_refs, - cancellable, error)) - return FALSE; - - GLNX_HASH_TABLE_FOREACH_V (all_refs, const char*, checksum) - { - g_debug ("Finding objects to keep for commit %s", checksum); - if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable, - cancellable, error)) - return FALSE; - } - - /* Using collections. */ - g_autoptr(GHashTable) all_collection_refs = NULL; /* (element-type OstreeChecksumRef utf8) */ - - if (!ostree_repo_list_collection_refs (self, NULL, &all_collection_refs, - OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable, error)) + if (!ostree_repo_traverse_reachable_refs (self, depth, reachable, cancellable, error)) return FALSE; - - GLNX_HASH_TABLE_FOREACH_V (all_collection_refs, const char*, checksum) - { - g_debug ("Finding objects to keep for commit %s", checksum); - if (!ostree_repo_traverse_commit_union (self, checksum, depth, reachable, - cancellable, error)) - return FALSE; - } } if (!ostree_repo_list_objects (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 8d3a7a6f..d86d241e 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -1203,6 +1203,14 @@ struct _OstreeRepoPruneOptions { typedef struct _OstreeRepoPruneOptions OstreeRepoPruneOptions; _OSTREE_PUBLIC +gboolean +ostree_repo_traverse_reachable_refs (OstreeRepo *self, + guint depth, + GHashTable *reachable, + GCancellable *cancellable, + GError **error); + +_OSTREE_PUBLIC gboolean ostree_repo_prune_from_reachable (OstreeRepo *self, OstreeRepoPruneOptions *options, gint *out_objects_total, |