mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-11 09:18:20 +03:00
repo: Tweak traversal API
It's convenient for bindings if we have a version that doesn't mutate the hash table, because they pass temporary hash tables as input.
This commit is contained in:
parent
af1c9b8721
commit
2708124190
@ -152,7 +152,7 @@ ostree_repo_prune (OstreeRepo *self,
|
||||
{
|
||||
const char *checksum = value;
|
||||
|
||||
if (!ostree_repo_traverse_commit (self, checksum, depth, data.reachable,
|
||||
if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
@ -176,8 +176,8 @@ ostree_repo_prune (OstreeRepo *self,
|
||||
if (objtype != OSTREE_OBJECT_TYPE_COMMIT)
|
||||
continue;
|
||||
|
||||
if (!ostree_repo_traverse_commit (self, checksum, depth, data.reachable,
|
||||
cancellable, error))
|
||||
if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ GHashTable *
|
||||
ostree_repo_traverse_new_reachable (void)
|
||||
{
|
||||
return g_hash_table_new_full (ostree_hash_object_name, g_variant_equal,
|
||||
(GDestroyNotify)g_variant_unref, NULL);
|
||||
NULL, (GDestroyNotify)g_variant_unref);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -125,33 +125,28 @@ traverse_dirtree_internal (OstreeRepo *repo,
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_traverse_dirtree (OstreeRepo *repo,
|
||||
const char *dirtree_checksum,
|
||||
GHashTable *inout_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
return traverse_dirtree_internal (repo, dirtree_checksum, 0,
|
||||
inout_reachable, cancellable, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_traverse_commit:
|
||||
* ostree_repo_traverse_commit_union: (skip)
|
||||
* @repo: Repo
|
||||
* @commit_checksum: ASCII SHA256 checksum
|
||||
* @maxdepth: Traverse this many parent commits, -1 for unlimited
|
||||
* @inout_reachable: Set of reachable objects
|
||||
* @cancellable: Cancellable
|
||||
* @error: Error
|
||||
*
|
||||
* Add to @inout_reachable all objects reachable from
|
||||
* @commit_checksum, traversing @maxdepth parent commits.
|
||||
* Update the set @inout_reachable containing all objects reachable
|
||||
* from @commit_checksum, traversing @maxdepth parent commits.
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_traverse_commit (OstreeRepo *repo,
|
||||
const char *commit_checksum,
|
||||
int maxdepth,
|
||||
GHashTable *inout_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_traverse_commit_union (OstreeRepo *repo,
|
||||
const char *commit_checksum,
|
||||
int maxdepth,
|
||||
GHashTable *inout_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
gs_free char*tmp_checksum = NULL;
|
||||
gs_free char *tmp_checksum = NULL;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
@ -205,7 +200,7 @@ ostree_repo_traverse_commit (OstreeRepo *repo,
|
||||
}
|
||||
|
||||
tmp_checksum = ostree_checksum_from_bytes_v (content_csum_bytes);
|
||||
if (!ostree_repo_traverse_dirtree (repo, tmp_checksum, inout_reachable, cancellable, error))
|
||||
if (!traverse_dirtree_internal (repo, tmp_checksum, 0, inout_reachable, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (maxdepth == -1 || maxdepth > 0)
|
||||
@ -228,3 +223,37 @@ ostree_repo_traverse_commit (OstreeRepo *repo,
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_repo_traverse_commit:
|
||||
* @repo: Repo
|
||||
* @commit_checksum: ASCII SHA256 checksum
|
||||
* @maxdepth: Traverse this many parent commits, -1 for unlimited
|
||||
* @out_reachable: (out) (element-type GVariant GVariant): Set of reachable objects
|
||||
* @cancellable: Cancellable
|
||||
* @error: Error
|
||||
*
|
||||
* Create a new set @out_reachable containing all objects reachable
|
||||
* from @commit_checksum, traversing @maxdepth parent commits.
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_traverse_commit (OstreeRepo *repo,
|
||||
const char *commit_checksum,
|
||||
int maxdepth,
|
||||
GHashTable **out_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret;
|
||||
gs_unref_hashtable GHashTable *ret_reachable =
|
||||
ostree_repo_traverse_new_reachable ();
|
||||
|
||||
if (!ostree_repo_traverse_commit_union (repo, commit_checksum, maxdepth,
|
||||
ret_reachable, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
gs_transfer_out_value (out_reachable, &ret_reachable);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
@ -414,19 +414,20 @@ gboolean ostree_repo_list_objects (OstreeRepo *self,
|
||||
|
||||
GHashTable *ostree_repo_traverse_new_reachable (void);
|
||||
|
||||
gboolean ostree_repo_traverse_dirtree (OstreeRepo *repo,
|
||||
const char *commit_checksum,
|
||||
GHashTable *inout_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_traverse_commit (OstreeRepo *repo,
|
||||
const char *commit_checksum,
|
||||
int maxdepth,
|
||||
GHashTable *inout_reachable,
|
||||
GHashTable **out_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_traverse_commit_union (OstreeRepo *repo,
|
||||
const char *commit_checksum,
|
||||
int maxdepth,
|
||||
GHashTable *inout_reachable,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
/**
|
||||
* OstreeRepoPruneFlags:
|
||||
* @OSTREE_REPO_PRUNE_FLAGS_NONE: No special options for pruning
|
||||
|
@ -178,8 +178,8 @@ ostree_builtin_diff (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
|
||||
|
||||
if (opt_stats)
|
||||
{
|
||||
gs_unref_hashtable GHashTable *reachable_a = ostree_repo_traverse_new_reachable ();
|
||||
gs_unref_hashtable GHashTable *reachable_b = ostree_repo_traverse_new_reachable ();
|
||||
gs_unref_hashtable GHashTable *reachable_a = NULL;
|
||||
gs_unref_hashtable GHashTable *reachable_b = NULL;
|
||||
gs_unref_hashtable GHashTable *reachable_intersection = NULL;
|
||||
gs_free char *rev_a = NULL;
|
||||
gs_free char *rev_b = NULL;
|
||||
@ -193,9 +193,9 @@ ostree_builtin_diff (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
|
||||
if (!ostree_repo_resolve_rev (repo, target, FALSE, &rev_b, error))
|
||||
goto out;
|
||||
|
||||
if (!ostree_repo_traverse_commit (repo, rev_a, -1, reachable_a, cancellable, error))
|
||||
if (!ostree_repo_traverse_commit (repo, rev_a, -1, &reachable_a, cancellable, error))
|
||||
goto out;
|
||||
if (!ostree_repo_traverse_commit (repo, rev_b, -1, reachable_b, cancellable, error))
|
||||
if (!ostree_repo_traverse_commit (repo, rev_b, -1, &reachable_b, cancellable, error))
|
||||
goto out;
|
||||
|
||||
a_size = g_hash_table_size (reachable_a);
|
||||
|
@ -200,8 +200,8 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
|
||||
|
||||
g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT);
|
||||
|
||||
if (!ostree_repo_traverse_commit (repo, checksum, 0, reachable_objects,
|
||||
cancellable, error))
|
||||
if (!ostree_repo_traverse_commit_union (repo, checksum, 0, reachable_objects,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -256,8 +256,8 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
|
||||
{
|
||||
const char *checksum = value;
|
||||
|
||||
if (!ostree_repo_traverse_commit (data->src_repo, checksum, 0, source_objects,
|
||||
cancellable, error))
|
||||
if (!ostree_repo_traverse_commit_union (data->src_repo, checksum, 0, source_objects,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -268,9 +268,10 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
|
||||
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
||||
{
|
||||
const char *checksum = key;
|
||||
gs_unref_hashtable GHashTable *tmp_source_objects = NULL;
|
||||
|
||||
if (!ostree_repo_traverse_commit (data->src_repo, checksum, 0, source_objects,
|
||||
cancellable, error))
|
||||
if (!ostree_repo_traverse_commit_union (data->src_repo, checksum, 0, source_objects,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user