From 7ce6777028953457c1f4125c48e6dc99a37949fc Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 7 Jun 2017 12:03:57 +0100 Subject: [PATCH] ostree/dump: Improve formatting for well-known commit metadata keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This follows on from commit a946c3d4, which added formatting for well-known summary metadata keys. This commit adds it for commits. Currently, the only well-known commit metadata key is ostree.commit.timestamp. Formatting this correctly is especially important, since it’s a big-endian uint64, which is completely unusable for mere mortals when presented as a number rather than a date. Non-formatted output can still be retrieved using the OSTREE_DUMP_RAW flag, and the non-formatted key name is always printed for clarity. Signed-off-by: Philip Withnall Closes: #911 Approved by: cgwalters --- src/ostree/ot-dump.c | 44 ++++++++++++++++++++++++++------------ tests/test-summary-view.sh | 1 + 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/ostree/ot-dump.c b/src/ostree/ot-dump.c index b24003c7..e6b8859b 100644 --- a/src/ostree/ot-dump.c +++ b/src/ostree/ot-dump.c @@ -71,6 +71,18 @@ format_timestamp (guint64 timestamp, return str; } +static gchar * +uint64_secs_to_iso8601 (guint64 secs) +{ + g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); + g_autoptr(GDateTime) local = (dt != NULL) ? g_date_time_to_local (dt) : NULL; + + if (local != NULL) + return g_date_time_format (local, "%FT%T%:::z"); + else + return g_strdup ("invalid"); +} + static void dump_indented_lines (const gchar *data) { @@ -196,23 +208,27 @@ dump_summary_ref (const char *ref_name, while (g_variant_iter_loop (metadata, "{sv}", &key, &value)) { - g_autofree char *string = g_variant_print (value, FALSE); - g_print (" %s: %s\n", key, string); + g_autofree gchar *value_str = NULL; + const gchar *pretty_key = NULL; + + if (g_strcmp0 (key, OSTREE_COMMIT_TIMESTAMP) == 0) + { + pretty_key = "Timestamp"; + value_str = uint64_secs_to_iso8601 (GUINT64_FROM_BE (g_variant_get_uint64 (value))); + } + else + { + value_str = g_variant_print (value, FALSE); + } + + /* Print out. */ + if (pretty_key != NULL) + g_print (" %s (%s): %s\n", pretty_key, key, value_str); + else + g_print (" %s: %s\n", key, value_str); } } -static gchar * -uint64_secs_to_iso8601 (guint64 secs) -{ - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); - g_autoptr(GDateTime) local = (dt != NULL) ? g_date_time_to_local (dt) : NULL; - - if (local != NULL) - return g_date_time_format (local, "%FT%T%:::z"); - else - return g_strdup ("invalid"); -} - void ot_dump_summary_bytes (GBytes *summary_bytes, OstreeDumpFlags flags) diff --git a/tests/test-summary-view.sh b/tests/test-summary-view.sh index 6dcfd088..5b52b691 100755 --- a/tests/test-summary-view.sh +++ b/tests/test-summary-view.sh @@ -52,6 +52,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 "Static Deltas (ostree.static-deltas): {}" +assert_file_has_content_literal summary.txt "Timestamp (ostree.commit.timestamp): " echo "ok view summary" # Check the summary can be viewed raw too.