From: Dan Nicholson Date: Sun, 29 Jan 2023 16:23:13 +0000 (-0700) Subject: bin/refs: Add option to print revisions X-Git-Tag: archive/raspbian/2023.7-3+rpi1~1^2~9^2~3^2~2^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=90dd45fb27594be7fec346987506d08f22a2a37a;p=ostree.git 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. --- diff --git a/bash/ostree b/bash/ostree index 5958176f..ea915b4b 100644 --- a/bash/ostree +++ b/bash/ostree @@ -953,6 +953,7 @@ _ostree_pull() { _ostree_refs() { local boolean_options=" $main_boolean_options + --revision -r --alias -A --collections -c --delete diff --git a/man/ostree-refs.xml b/man/ostree-refs.xml index 97d69fd7..b54039a3 100644 --- a/man/ostree-refs.xml +++ b/man/ostree-refs.xml @@ -98,6 +98,15 @@ License along with this library. If not, see . + + , + + + When listing refs, also print their revisions. The revisions + will be separated by a tab character. + + + , 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); diff --git a/tests/test-refs.sh b/tests/test-refs.sh index 1ddb3a21..53b36f6b 100755 --- a/tests/test-refs.sh +++ b/tests/test-refs.sh @@ -55,6 +55,14 @@ assert_file_has_content refs foo ${CMD_PREFIX} ostree --repo=repo refs foo | wc -l > refscount.foo assert_file_has_content refscount.foo "^5$" +rm -f expected-refs-revs +for ref in foo/test-{1..5}; do + rev=$(${CMD_PREFIX} ostree --repo=repo rev-parse $ref) + echo -e "${ref}\t${rev}" >> expected-refs-revs +done +${CMD_PREFIX} ostree --repo=repo refs --list --revision foo > refs-revs +assert_files_equal refs-revs expected-refs-revs + ${CMD_PREFIX} ostree --repo=repo refs --delete 2>/dev/null || true ${CMD_PREFIX} ostree --repo=repo refs | wc -l > refscount.delete1 assert_file_has_content refscount.delete1 "^10$"