bin/status: Inline metadata parsing for versions
authorColin Walters <walters@verbum.org>
Fri, 20 Oct 2017 14:19:00 +0000 (10:19 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 23 Oct 2017 14:19:41 +0000 (14:19 +0000)
Pull out the commit metadata explicitly; still just rendering the version, but
this is prep for rendering other metadata keys.

Closes: #1296
Approved by: jlebon

src/ostree/ot-admin-builtin-status.c

index d3e524f3616093f27a3e79f1d09b26b5b7ef067f..8d180a6a47ea173bf33efd990055601d3537c0b7 100644 (file)
@@ -37,18 +37,6 @@ static GOptionEntry options[] = {
   { NULL }
 };
 
-static char *
-version_of_commit (OstreeRepo *repo, const char *checksum)
-{
-  g_autoptr(GVariant) variant = NULL;
-  /* Shouldn't fail, but if it does, we ignore it */
-  if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum,
-                                 &variant, NULL))
-    return NULL;
-
-  return ot_admin_checksum_version (variant);
-}
-
 static gboolean
 deployment_get_gpg_verify (OstreeDeployment *deployment,
                            OstreeRepo *repo)
@@ -114,7 +102,20 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat
         {
           OstreeDeployment *deployment = deployments->pdata[i];
           const char *ref = ostree_deployment_get_csum (deployment);
-          g_autofree char *version = version_of_commit (repo, ref);
+
+          /* Load the backing commit; shouldn't normally fail, but if it does,
+           * we stumble on.
+           */
+          g_autoptr(GVariant) commit = NULL;
+          (void)ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, ref,
+                                          &commit, NULL);
+          g_autoptr(GVariant) commit_metadata = NULL;
+          if (commit)
+            commit_metadata = g_variant_get_child_value (commit, 0);
+
+          const char *version = NULL;
+          if (commit_metadata)
+            (void) g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version);
 
           GKeyFile *origin = ostree_deployment_get_origin (deployment);