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
This commit is contained in:
Colin Walters 2018-04-30 14:31:33 +00:00 committed by Atomic Bot
parent ce2995e1dc
commit 371081d123
4 changed files with 69 additions and 28 deletions

View File

@ -413,6 +413,7 @@ ostree_repo_commit_traverse_iter_next
OstreeRepoPruneFlags OstreeRepoPruneFlags
ostree_repo_prune ostree_repo_prune
ostree_repo_prune_static_deltas ostree_repo_prune_static_deltas
ostree_repo_traverse_reachable_refs
ostree_repo_prune_from_reachable ostree_repo_prune_from_reachable
OstreeRepoPullFlags OstreeRepoPullFlags
ostree_repo_pull ostree_repo_pull

View File

@ -19,6 +19,7 @@
/* Add new symbols here. Release commits should copy this section into -released.sym. */ /* Add new symbols here. Release commits should copy this section into -released.sym. */
LIBOSTREE_2018.6 { LIBOSTREE_2018.6 {
ostree_repo_traverse_reachable_refs;
} LIBOSTREE_2018.5; } LIBOSTREE_2018.5;
/* Stub section for the stable release *after* this development one; don't /* Stub section for the stable release *after* this development one; don't

View File

@ -301,6 +301,64 @@ repo_prune_internal (OstreeRepo *self,
return TRUE; return TRUE;
} }
/**
* 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: * ostree_repo_prune:
* @self: Repo * @self: Repo
@ -355,35 +413,8 @@ ostree_repo_prune (OstreeRepo *self,
if (refs_only) if (refs_only)
{ {
/* Ignoring collections. */ if (!ostree_repo_traverse_reachable_refs (self, depth, reachable, cancellable, error))
g_autoptr(GHashTable) all_refs = NULL; /* (element-type utf8 utf8) */
if (!ostree_repo_list_refs (self, NULL, &all_refs,
cancellable, error))
return FALSE; 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;
}
} }
if (!ostree_repo_list_objects (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, if (!ostree_repo_list_objects (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS,

View File

@ -1202,6 +1202,14 @@ struct _OstreeRepoPruneOptions {
typedef struct _OstreeRepoPruneOptions 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 _OSTREE_PUBLIC
gboolean ostree_repo_prune_from_reachable (OstreeRepo *self, gboolean ostree_repo_prune_from_reachable (OstreeRepo *self,
OstreeRepoPruneOptions *options, OstreeRepoPruneOptions *options,