[ostree] repo: Tweak traversal API
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] repo: Tweak traversal API
- Date: Wed, 9 Oct 2013 16:49:32 +0000 (UTC)
commit 270812419004ab5a9fffa4598c4accf13aec7234
Author: Colin Walters <walters verbum org>
Date: Wed Oct 9 12:05:56 2013 -0400
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.
src/libostree/ostree-repo-prune.c | 6 +-
src/libostree/ostree-repo-traverse.c | 75 +++++++++++++++++++++++----------
src/libostree/ostree-repo.h | 15 ++++---
src/ostree/ot-builtin-diff.c | 8 ++--
src/ostree/ot-builtin-fsck.c | 4 +-
src/ostree/ot-builtin-pull-local.c | 9 ++--
6 files changed, 74 insertions(+), 43 deletions(-)
---
diff --git a/src/libostree/ostree-repo-prune.c b/src/libostree/ostree-repo-prune.c
index 4f1db66..6479aa2 100644
--- a/src/libostree/ostree-repo-prune.c
+++ b/src/libostree/ostree-repo-prune.c
@@ -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;
}
}
diff --git a/src/libostree/ostree-repo-traverse.c b/src/libostree/ostree-repo-traverse.c
index 6549328..758c233 100644
--- a/src/libostree/ostree-repo-traverse.c
+++ b/src/libostree/ostree-repo-traverse.c
@@ -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;
+}
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 147893d..8bd9488 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -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
diff --git a/src/ostree/ot-builtin-diff.c b/src/ostree/ot-builtin-diff.c
index 9680c3b..9c26e70 100644
--- a/src/ostree/ot-builtin-diff.c
+++ b/src/ostree/ot-builtin-diff.c
@@ -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);
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index 5f53e72..afd1b54 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -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;
}
diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c
index 6058b0e..0feeddf 100644
--- a/src/ostree/ot-builtin-pull-local.c
+++ b/src/ostree/ot-builtin-pull-local.c
@@ -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;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]