diff options
author | Colin Walters <walters@verbum.org> | 2014-08-20 10:54:27 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2014-08-20 10:54:27 -0400 |
commit | 3a838f7db817e909289f45db090e1f9e126ed66e (patch) | |
tree | f72ae39ec762a46c1fdd389869d0a52a8ac0c06a | |
parent | 7dd74addbbe9a0e4afcf582ad27ffd40feddcd20 (diff) | |
download | ostree-wip/metalinks.tar.gz |
metalink: Drop commit data from summary, add generic a{sv}wip/metalinks
Per discussion on IRC, really all we need in the summary is the ref ->
commit data. We can easily fetch the commits in a separate phase, and
avoiding duplication is good.
Also, to allow future extensibility, add in a generic a{sv}.
-rw-r--r-- | src/libostree/ostree-core.h | 4 | ||||
-rw-r--r-- | src/libostree/ostree-repo-pull.c | 3 | ||||
-rw-r--r-- | src/libostree/ostree-repo.c | 49 | ||||
-rw-r--r-- | src/libostree/ostree-repo.h | 1 | ||||
-rw-r--r-- | src/libotutil/ot-variant-utils.c | 63 | ||||
-rw-r--r-- | src/libotutil/ot-variant-utils.h | 5 | ||||
-rw-r--r-- | src/ostree/ot-builtin-summary.c | 2 |
7 files changed, 10 insertions, 117 deletions
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h index c1b81d75..2f2baa78 100644 --- a/src/libostree/ostree-core.h +++ b/src/libostree/ostree-core.h @@ -120,10 +120,10 @@ typedef enum { /** * OSTREE_SUMMARY_GVARIANT_FORMAT: * - * a(ayay) - Array of (checksum, commit data), sorted by checksum * refs: a(s(aya{sv})) - Map of ref name -> (latest commit, additional metadata), sorted by ref name + * extensions: a{sv} - Additional metadata, none defined at the current time */ -#define OSTREE_SUMMARY_GVARIANT_STRING "(a(ayay)a(s(aya{sv})))" +#define OSTREE_SUMMARY_GVARIANT_STRING "(a(s(aya{sv}))a{sv})" #define OSTREE_SUMMARY_GVARIANT_FORMAT G_VARIANT_TYPE (OSTREE_SUMMARY_GVARIANT_STRING) /** diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 102fe45b..4b1f7263 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -531,8 +531,7 @@ lookup_commit_checksum_from_summary (OtPullData *pull_data, GError **error) { gboolean ret = FALSE; - gs_unref_variant GVariant *commits = g_variant_get_child_value (pull_data->summary, 0); - gs_unref_variant GVariant *refs = g_variant_get_child_value (pull_data->summary, 1); + gs_unref_variant GVariant *refs = g_variant_get_child_value (pull_data->summary, 0); gs_unref_variant GVariant *refdata = NULL; gs_unref_variant GVariant *reftargetdata = NULL; gs_unref_variant GVariant *commit_data = NULL; diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index f642bd51..6dc53250 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -2265,6 +2265,7 @@ out: /** * ostree_repo_regenerate_summary: * @self: Repo + * @additional_metadata: (allow-none): A GVariant of type a{sv}, or %NULL * @cancellable: Cancellable * @error: Error * @@ -2278,15 +2279,14 @@ out: */ gboolean ostree_repo_regenerate_summary (OstreeRepo *self, + GVariant *additional_metadata, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GFile *summary_path = NULL; gs_unref_hashtable GHashTable *refs = NULL; - gs_unref_hashtable GHashTable *commits = NULL; gs_unref_variant_builder GVariantBuilder *refs_builder = NULL; - gs_unref_variant_builder GVariantBuilder *commits_builder = NULL; gs_unref_variant GVariant *summary = NULL; GList *ordered_keys = NULL; GList *iter = NULL; @@ -2294,8 +2294,6 @@ ostree_repo_regenerate_summary (OstreeRepo *self, if (!ostree_repo_list_refs (self, NULL, &refs, cancellable, error)) goto out; - commits = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); - refs_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(s(aya{sv}))")); ordered_keys = g_hash_table_get_keys (refs); @@ -2305,58 +2303,21 @@ ostree_repo_regenerate_summary (OstreeRepo *self, { const char *ref = iter->data; const char *commit = g_hash_table_lookup (refs, ref); - gs_unref_variant GVariant *csum_v = NULL; g_assert (commit); - if (!g_hash_table_lookup (commits, commit)) - { - gs_unref_variant GVariant *commit_content = NULL; - - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, commit, - &commit_content, error)) - goto out; - - g_hash_table_insert (commits, g_strdup (commit), g_variant_ref (commit_content)); - } - - csum_v = g_variant_ref_sink (ostree_checksum_to_bytes_v (commit)); - g_variant_builder_add_value (refs_builder, - g_variant_new ("(s(@ay@a{sv}))", ref, csum_v, + g_variant_new ("(s(@ay@a{sv}))", ref, + ostree_checksum_to_bytes_v (commit), ot_gvariant_new_empty_string_dict ())); } - g_list_free (ordered_keys); - ordered_keys = g_hash_table_get_keys (commits); - ordered_keys = g_list_sort (ordered_keys, (GCompareFunc)strcmp); - - commits_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(ayay)")); - - for (iter = ordered_keys; iter; iter = iter->next) - { - const char *commit = iter->data; - GVariant *commit_content = g_hash_table_lookup (commits, commit); - gs_unref_variant GVariant *csum_v = NULL; - gs_unref_bytes GBytes *commit_data; - gs_unref_variant GVariant *commit_data_v; - - g_assert (commit_content); - - csum_v = g_variant_ref_sink (ostree_checksum_to_bytes_v (commit)); - commit_data = g_variant_get_data_as_bytes (commit_content); - commit_data_v = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), commit_data, TRUE)); - - g_variant_builder_add_value (commits_builder, - g_variant_new ("(@ay@ay)", csum_v, commit_data_v)); - } - { gs_unref_variant_builder GVariantBuilder *summary_builder = g_variant_builder_new (OSTREE_SUMMARY_GVARIANT_FORMAT); - g_variant_builder_add_value (summary_builder, g_variant_builder_end (commits_builder)); g_variant_builder_add_value (summary_builder, g_variant_builder_end (refs_builder)); + g_variant_builder_add_value (summary_builder, additional_metadata ? additional_metadata : ot_gvariant_new_empty_string_dict ()); summary = g_variant_builder_end (summary_builder); g_variant_ref_sink (summary); } diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index d5995f4f..fe57dcdc 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -559,6 +559,7 @@ gboolean ostree_repo_verify_commit (OstreeRepo *self, GError **error); gboolean ostree_repo_regenerate_summary (OstreeRepo *self, + GVariant *additional_metadata, GCancellable *cancellable, GError **error); diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c index 031be2af..aa3dff56 100644 --- a/src/libotutil/ot-variant-utils.c +++ b/src/libotutil/ot-variant-utils.c @@ -346,66 +346,3 @@ ot_variant_bsearch_str (GVariant *array, *out_pos = imid; return FALSE; } - -/** - * ot_variant_bsearch_bytes: - * - * Like ot_variant_bsearch, but with binary data like checksums. - */ -gboolean -ot_variant_bsearch_bytes (GVariant *array, - GBytes *bytes, - int *out_pos) -{ - gsize imax, imin; - gsize imid; - gsize n; - const guint8 *bytes_data; - gsize bytes_len; - - bytes_data = g_bytes_get_data (bytes, &bytes_len); - - n = g_variant_n_children (array); - if (n == 0) - return FALSE; - - imax = n - 1; - imin = 0; - while (imax >= imin) - { - gs_unref_variant GVariant *child = NULL; - gs_unref_variant GVariant *child_first = NULL; - const guint8 *variant_data; - gsize variant_size; - int cmp; - - imid = (imin + imax) / 2; - - child = g_variant_get_child_value (array, imid); - child_first = g_variant_get_child_value (child, 0); - - variant_data = g_variant_get_data (child_first); - variant_size = g_variant_get_size (child_first); - - if (variant_size != bytes_len) - cmp = 1; - else - cmp = memcmp (variant_data, bytes_data, bytes_len); - if (cmp < 0) - imin = imid + 1; - else if (cmp > 0) - { - if (imid == 0) - break; - imax = imid - 1; - } - else - { - *out_pos = imid; - return TRUE; - } - } - - *out_pos = imid; - return FALSE; -} diff --git a/src/libotutil/ot-variant-utils.h b/src/libotutil/ot-variant-utils.h index 28f4096f..422a8037 100644 --- a/src/libotutil/ot-variant-utils.h +++ b/src/libotutil/ot-variant-utils.h @@ -77,10 +77,5 @@ ot_variant_bsearch_str (GVariant *array, const char *str, int *out_pos); -gboolean -ot_variant_bsearch_bytes (GVariant *array, - GBytes *bytes, - int *out_pos); - G_END_DECLS diff --git a/src/ostree/ot-builtin-summary.c b/src/ostree/ot-builtin-summary.c index 667d6fed..2f9cae5b 100644 --- a/src/ostree/ot-builtin-summary.c +++ b/src/ostree/ot-builtin-summary.c @@ -45,7 +45,7 @@ ostree_builtin_summary (int argc, char **argv, OstreeRepo *repo, GCancellable *c if (opt_update) { - if (!ostree_repo_regenerate_summary (repo, cancellable, error)) + if (!ostree_repo_regenerate_summary (repo, NULL, cancellable, error)) goto out; } else |