refs: Add argument --list to print the full ref name

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2016-03-02 10:48:52 +01:00 committed by Colin Walters
parent 3e3621b7b6
commit 6d73a620e1
3 changed files with 24 additions and 7 deletions

View File

@ -65,6 +65,16 @@ Boston, MA 02111-1307, USA.
<title>Options</title> <title>Options</title>
<variablelist> <variablelist>
<varlistentry>
<term><option>--list</option></term>
<listitem><para> For historical reasons, <literal>refs</literal>
without this option will strip the specified prefix
from the output. Normally, one wants to see the full
ref, so providing this option ensures the refs are
printed in full, rather than
truncated. </para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--delete</option></term> <term><option>--delete</option></term>

View File

@ -27,9 +27,11 @@
#include "ostree.h" #include "ostree.h"
static gboolean opt_delete; static gboolean opt_delete;
static gboolean opt_list;
static GOptionEntry options[] = { static GOptionEntry options[] = {
{ "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", NULL }, { "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 },
{ NULL } { NULL }
}; };
@ -40,11 +42,17 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
gpointer hashkey, hashvalue; gpointer hashkey, hashvalue;
gboolean ret = FALSE; gboolean ret = FALSE;
if (opt_delete || opt_list)
{
if (!ostree_repo_list_refs_ext (repo, refspec_prefix, &refs, OSTREE_REPO_LIST_REFS_EXT_NONE,
cancellable, error))
goto out;
}
else if (!ostree_repo_list_refs (repo, refspec_prefix, &refs, cancellable, error))
goto out;
if (!opt_delete) if (!opt_delete)
{ {
if (!ostree_repo_list_refs (repo, refspec_prefix, &refs, cancellable, error))
goto out;
g_hash_table_iter_init (&hashiter, refs); g_hash_table_iter_init (&hashiter, refs);
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue)) while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
{ {
@ -54,10 +62,6 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
} }
else else
{ {
if (!ostree_repo_list_refs_ext (repo, refspec_prefix, &refs, OSTREE_REPO_LIST_REFS_EXT_NONE,
cancellable, error))
goto out;
g_hash_table_iter_init (&hashiter, refs); g_hash_table_iter_init (&hashiter, refs);
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue)) while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
{ {

View File

@ -45,6 +45,9 @@ assert_file_has_content refscount "^10$"
${CMD_PREFIX} ostree --repo=repo refs foo > refs ${CMD_PREFIX} ostree --repo=repo refs foo > refs
assert_not_file_has_content refs foo assert_not_file_has_content refs foo
${CMD_PREFIX} ostree --repo=repo refs --list foo > refs
assert_file_has_content refs foo
${CMD_PREFIX} ostree --repo=repo refs foo | wc -l > refscount.foo ${CMD_PREFIX} ostree --repo=repo refs foo | wc -l > refscount.foo
assert_file_has_content refscount.foo "^5$" assert_file_has_content refscount.foo "^5$"