From 6fbf759279ca9908e0c7ceb2a3af75b1180fa8a1 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Fri, 4 Feb 2022 14:11:06 -0700 Subject: [PATCH] lib/repo: Add commit version metadata to summary metadata The commit metadata `version` key is well established but getting it for a remote commit is cumbersome since the commit object needs to be fetched and loaded. Including it in the summary additional metadata allows a much more convenient view of what each of the remote refs represents. --- man/ostree-summary.xml | 1 + src/libostree/ostree-core.h | 2 ++ src/libostree/ostree-repo-private.h | 1 + src/libostree/ostree-repo.c | 7 ++++++- src/ostree/ot-dump.c | 5 +++++ tests/test-summary-view.sh | 1 + 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/man/ostree-summary.xml b/man/ostree-summary.xml index 4c9652cc..e853e8cd 100644 --- a/man/ostree-summary.xml +++ b/man/ostree-summary.xml @@ -183,6 +183,7 @@ License along with this library. If not, see . Latest Commit (4.2 MB): 9828ab80f357459b4ab50f0629beab2ae3b67318fc3d161d10a89fae353afa90 Timestamp (ostree.commit.timestamp): 2017-11-21T01:41:10-08 + Version (ostree.commit.version): 1.2.3 Last-Modified (ostree.summary.last-modified): 2018-01-12T22:06:38-08 diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h index 36e61290..48a75f92 100644 --- a/src/libostree/ostree-core.h +++ b/src/libostree/ostree-core.h @@ -164,6 +164,8 @@ typedef enum { * The currently defined keys for the `a{sv}` of additional metadata for each commit are: * - key: `ostree.commit.timestamp`, value: `t`, timestamp (seconds since the * Unix epoch in UTC, big-endian) when the commit was committed + * - key: `ostree.commit.version`, value: `s`, the `version` value from the + * commit's metadata if it was defined. Since: 2022.2 */ #define OSTREE_SUMMARY_GVARIANT_STRING "(a(s(taya{sv}))a{sv})" #define OSTREE_SUMMARY_GVARIANT_FORMAT G_VARIANT_TYPE (OSTREE_SUMMARY_GVARIANT_STRING) diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index 6d8f0193..988c2179 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -63,6 +63,7 @@ G_BEGIN_DECLS /* Well-known keys for the additional metadata field in a commit in a ref entry * in a summary file. */ #define OSTREE_COMMIT_TIMESTAMP "ostree.commit.timestamp" +#define OSTREE_COMMIT_VERSION "ostree.commit.version" typedef enum { OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0), diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 64a8fea9..6c541029 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -6067,10 +6067,11 @@ summary_add_ref_entry (OstreeRepo *self, g_autoptr(GVariant) commit_obj = NULL; if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, &commit_obj, error)) return FALSE; + g_autoptr(GVariant) orig_metadata = g_variant_get_child_value (commit_obj, 0); g_variant_dict_init (&commit_metadata_builder, NULL); - /* Forward the commit’s timestamp if it’s valid. */ + /* Forward the commit’s timestamp and version if they're valid. */ guint64 commit_timestamp = ostree_commit_get_timestamp (commit_obj); g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (commit_timestamp); @@ -6078,6 +6079,10 @@ summary_add_ref_entry (OstreeRepo *self, g_variant_dict_insert_value (&commit_metadata_builder, OSTREE_COMMIT_TIMESTAMP, g_variant_new_uint64 (GUINT64_TO_BE (commit_timestamp))); + const char *version = NULL; + if (g_variant_lookup (orig_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version)) + g_variant_dict_insert (&commit_metadata_builder, OSTREE_COMMIT_VERSION, "s", version); + g_variant_builder_add_value (refs_builder, g_variant_new ("(s(t@ay@a{sv}))", ref, (guint64) g_variant_get_size (commit_obj), diff --git a/src/ostree/ot-dump.c b/src/ostree/ot-dump.c index b874db0f..509eb792 100644 --- a/src/ostree/ot-dump.c +++ b/src/ostree/ot-dump.c @@ -249,6 +249,11 @@ dump_summary_ref (const char *collection_id, pretty_key = "Timestamp"; value_str = uint64_secs_to_iso8601 (GUINT64_FROM_BE (g_variant_get_uint64 (value))); } + else if (g_strcmp0 (key, OSTREE_COMMIT_VERSION) == 0) + { + pretty_key = "Version"; + value_str = g_strdup (g_variant_get_string (value, NULL)); + } else { value_str = g_variant_print (value, FALSE); diff --git a/tests/test-summary-view.sh b/tests/test-summary-view.sh index 088628d8..9dfc74f4 100755 --- a/tests/test-summary-view.sh +++ b/tests/test-summary-view.sh @@ -56,6 +56,7 @@ assert_file_has_content_literal summary.txt "* main" assert_file_has_content_literal summary.txt "* other" assert_file_has_content_literal summary.txt "ostree.summary.last-modified" assert_file_has_content_literal summary.txt "Timestamp (ostree.commit.timestamp): " +assert_file_has_content_literal summary.txt "Version (ostree.commit.version): 3.2" echo "ok view summary" # Check the summary can be viewed raw too.