diff options
author | Dan Nicholson <dbn@endlessos.org> | 2023-01-29 09:23:13 -0700 |
---|---|---|
committer | Dan Nicholson <dbn@endlessos.org> | 2023-02-07 22:59:30 -0700 |
commit | 90dd45fb27594be7fec346987506d08f22a2a37a (patch) | |
tree | e44525b5cff067f81614a047d9aff364c78c9fc5 | |
parent | 6b0f42ae376ff7e953241fc98d6f3735225f0d3e (diff) | |
download | ostree-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.
-rw-r--r-- | bash/ostree | 1 | ||||
-rw-r--r-- | man/ostree-refs.xml | 9 | ||||
-rw-r--r-- | src/ostree/ot-builtin-refs.c | 18 | ||||
-rwxr-xr-x | tests/test-refs.sh | 8 |
4 files changed, 35 insertions, 1 deletions
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 @@ -99,6 +99,15 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>. </varlistentry> <varlistentry> + <term><option>--revision</option>, <option>-r</option></term> + + <listitem><para> + When listing refs, also print their revisions. The revisions + will be separated by a tab character. + </para></listitem> + </varlistentry> + + <varlistentry> <term><option>--alias</option>, <option>-A</option></term> <listitem><para> 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$" |