summaryrefslogtreecommitdiff
path: root/src/ostree/ot-builtin-refs.c
diff options
context:
space:
mode:
authorDan Nicholson <dbn@endlessos.org>2023-01-29 09:23:13 -0700
committerDan Nicholson <dbn@endlessos.org>2023-02-07 22:59:30 -0700
commit90dd45fb27594be7fec346987506d08f22a2a37a (patch)
treee44525b5cff067f81614a047d9aff364c78c9fc5 /src/ostree/ot-builtin-refs.c
parent6b0f42ae376ff7e953241fc98d6f3735225f0d3e (diff)
downloadostree-90dd45fb27594be7fec346987506d08f22a2a37a.tar.gz
bin/refs: Add option to print revisions
Allow printing the revision along with the ref. This is very convenient for looping over the refs in a shell as well as for quickly seeing which refs are pointed to the same commit.
Diffstat (limited to 'src/ostree/ot-builtin-refs.c')
-rw-r--r--src/ostree/ot-builtin-refs.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c
index 0233b8f8..c49d7507 100644
--- a/src/ostree/ot-builtin-refs.c
+++ b/src/ostree/ot-builtin-refs.c
@@ -27,6 +27,7 @@
static gboolean opt_delete;
static gboolean opt_list;
+static gboolean opt_revision;
static gboolean opt_alias;
static char *opt_create;
static gboolean opt_collections;
@@ -40,6 +41,7 @@ static gboolean opt_force;
static GOptionEntry options[] = {
{ "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", NULL },
{ "list", 0, 0, G_OPTION_ARG_NONE, &opt_list, "Do not remove the prefix from the refs", NULL },
+ { "revision", 'r', 0, G_OPTION_ARG_NONE, &opt_revision, "Show revisions in listing", NULL },
{ "alias", 'A', 0, G_OPTION_ARG_NONE, &opt_alias, "If used with --create, create an alias, otherwise just list aliases", NULL },
{ "create", 0, 0, G_OPTION_ARG_STRING, &opt_create, "Create a new ref for an existing commit", "NEWREF" },
{ "collections", 'c', 0, G_OPTION_ARG_NONE, &opt_collections, "Enable listing collection IDs for refs", NULL },
@@ -82,7 +84,16 @@ do_ref_with_collections (OstreeRepo *repo,
for (GList *iter = ordered_keys; iter != NULL; iter = iter->next)
{
OstreeCollectionRef *ref = iter->data;
- g_print ("(%s, %s)\n", ref->collection_id, ref->ref_name);
+
+ if (opt_revision)
+ {
+ const char *rev = g_hash_table_lookup (refs, ref);
+ g_print ("(%s, %s)\t%s\n", ref->collection_id, ref->ref_name, rev);
+ }
+ else
+ {
+ g_print ("(%s, %s)\n", ref->collection_id, ref->ref_name);
+ }
}
}
else if (opt_create)
@@ -203,6 +214,11 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
const char *alias = g_hash_table_lookup (refs, ref);
g_print ("%s -> %s\n", ref, alias);
}
+ else if (opt_revision)
+ {
+ const char *rev = g_hash_table_lookup (refs, ref);
+ g_print ("%s\t%s\n", ref, rev);
+ }
else
{
g_print ("%s\n", ref);