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.
This commit is contained in:
Dan Nicholson committed 2022-02-04 14:28:11 -07:00
1 parent a588295d3a
commit 6fbf759279
6 files changed
+16 -1

No files matched your search

+2
View File
@@ -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)
+1
View File
@@ -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),
+6 -1
View File
@@ -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),