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:
Colin Walters 2013-10-09 12:05:56 -04:00
parent af1c9b8721
commit 2708124190
6 changed files with 74 additions and 43 deletions

View File

@ -152,7 +152,7 @@ ostree_repo_prune (OstreeRepo *self,
{ {
const char *checksum = value; 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)) cancellable, error))
goto out; goto out;
} }
@ -176,7 +176,7 @@ ostree_repo_prune (OstreeRepo *self,
if (objtype != OSTREE_OBJECT_TYPE_COMMIT) if (objtype != OSTREE_OBJECT_TYPE_COMMIT)
continue; continue;
if (!ostree_repo_traverse_commit (self, checksum, depth, data.reachable, if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
cancellable, error)) cancellable, error))
goto out; goto out;
} }

View File

@ -38,7 +38,7 @@ GHashTable *
ostree_repo_traverse_new_reachable (void) ostree_repo_traverse_new_reachable (void)
{ {
return g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, 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 static gboolean
@ -125,25 +125,20 @@ traverse_dirtree_internal (OstreeRepo *repo,
return ret; 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 * Update the set @inout_reachable containing all objects reachable
* @commit_checksum, traversing @maxdepth parent commits. * from @commit_checksum, traversing @maxdepth parent commits.
*/ */
gboolean gboolean
ostree_repo_traverse_commit (OstreeRepo *repo, ostree_repo_traverse_commit_union (OstreeRepo *repo,
const char *commit_checksum, const char *commit_checksum,
int maxdepth, int maxdepth,
GHashTable *inout_reachable, GHashTable *inout_reachable,
@ -151,7 +146,7 @@ ostree_repo_traverse_commit (OstreeRepo *repo,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
gs_free char*tmp_checksum = NULL; gs_free char *tmp_checksum = NULL;
while (TRUE) while (TRUE)
{ {
@ -205,7 +200,7 @@ ostree_repo_traverse_commit (OstreeRepo *repo,
} }
tmp_checksum = ostree_checksum_from_bytes_v (content_csum_bytes); 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; goto out;
if (maxdepth == -1 || maxdepth > 0) if (maxdepth == -1 || maxdepth > 0)
@ -228,3 +223,37 @@ ostree_repo_traverse_commit (OstreeRepo *repo,
out: out:
return ret; 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;
}

View File

@ -414,13 +414,14 @@ gboolean ostree_repo_list_objects (OstreeRepo *self,
GHashTable *ostree_repo_traverse_new_reachable (void); GHashTable *ostree_repo_traverse_new_reachable (void);
gboolean ostree_repo_traverse_dirtree (OstreeRepo *repo, gboolean ostree_repo_traverse_commit (OstreeRepo *repo,
const char *commit_checksum, const char *commit_checksum,
GHashTable *inout_reachable, int maxdepth,
GHashTable **out_reachable,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean ostree_repo_traverse_commit (OstreeRepo *repo, gboolean ostree_repo_traverse_commit_union (OstreeRepo *repo,
const char *commit_checksum, const char *commit_checksum,
int maxdepth, int maxdepth,
GHashTable *inout_reachable, GHashTable *inout_reachable,

View File

@ -178,8 +178,8 @@ ostree_builtin_diff (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
if (opt_stats) if (opt_stats)
{ {
gs_unref_hashtable GHashTable *reachable_a = ostree_repo_traverse_new_reachable (); gs_unref_hashtable GHashTable *reachable_a = NULL;
gs_unref_hashtable GHashTable *reachable_b = ostree_repo_traverse_new_reachable (); gs_unref_hashtable GHashTable *reachable_b = NULL;
gs_unref_hashtable GHashTable *reachable_intersection = NULL; gs_unref_hashtable GHashTable *reachable_intersection = NULL;
gs_free char *rev_a = NULL; gs_free char *rev_a = NULL;
gs_free char *rev_b = 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)) if (!ostree_repo_resolve_rev (repo, target, FALSE, &rev_b, error))
goto out; 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; 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; goto out;
a_size = g_hash_table_size (reachable_a); a_size = g_hash_table_size (reachable_a);

View File

@ -200,7 +200,7 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT); g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT);
if (!ostree_repo_traverse_commit (repo, checksum, 0, reachable_objects, if (!ostree_repo_traverse_commit_union (repo, checksum, 0, reachable_objects,
cancellable, error)) cancellable, error))
goto out; goto out;
} }

View File

@ -256,7 +256,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
{ {
const char *checksum = value; const char *checksum = value;
if (!ostree_repo_traverse_commit (data->src_repo, checksum, 0, source_objects, if (!ostree_repo_traverse_commit_union (data->src_repo, checksum, 0, source_objects,
cancellable, error)) cancellable, error))
goto out; goto out;
} }
@ -268,8 +268,9 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
while (g_hash_table_iter_next (&hash_iter, &key, &value)) while (g_hash_table_iter_next (&hash_iter, &key, &value))
{ {
const char *checksum = key; const char *checksum = key;
gs_unref_hashtable GHashTable *tmp_source_objects = NULL;
if (!ostree_repo_traverse_commit (data->src_repo, checksum, 0, source_objects, if (!ostree_repo_traverse_commit_union (data->src_repo, checksum, 0, source_objects,
cancellable, error)) cancellable, error))
goto out; goto out;
} }