refs: allow to specify multiple refs as args
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
898c7b6577
commit
a4be237a2e
|
|
@ -57,7 +57,7 @@ Boston, MA 02111-1307, USA.
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Description</title>
|
<title>Description</title>
|
||||||
<para>
|
<para>
|
||||||
Lists all refs available on the host. If pecified, PREFIX assigns the refspec prefix; default prefix is null, which lists all refs.
|
Lists all refs available on the host. If specified, PREFIX assigns the refspec prefix; default prefix is null, which lists all refs.
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,39 +33,18 @@ static GOptionEntry options[] = {
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
gboolean
|
static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellable *cancellable, GError **error)
|
||||||
ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error)
|
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
GOptionContext *context;
|
|
||||||
glnx_unref_object OstreeRepo *repo = NULL;
|
|
||||||
const char *refspec_prefix = NULL;
|
|
||||||
g_autoptr(GHashTable) refs = NULL;
|
g_autoptr(GHashTable) refs = NULL;
|
||||||
GHashTableIter hashiter;
|
GHashTableIter hashiter;
|
||||||
gpointer hashkey, hashvalue;
|
gpointer hashkey, hashvalue;
|
||||||
|
gboolean ret = FALSE;
|
||||||
context = g_option_context_new ("[PREFIX] - List refs");
|
|
||||||
|
|
||||||
if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (argc >= 2)
|
|
||||||
refspec_prefix = argv[1];
|
|
||||||
|
|
||||||
/* Require a prefix when deleting to help avoid accidents. */
|
|
||||||
if (opt_delete && refspec_prefix == NULL)
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"PREFIX is required when deleting refs");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
||||||
{
|
{
|
||||||
|
|
@ -75,6 +54,10 @@ ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **
|
||||||
}
|
}
|
||||||
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))
|
||||||
{
|
{
|
||||||
|
|
@ -90,6 +73,41 @@ ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
GOptionContext *context;
|
||||||
|
glnx_unref_object OstreeRepo *repo = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
context = g_option_context_new ("[PREFIX] - List refs");
|
||||||
|
|
||||||
|
if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (argc >= 2)
|
||||||
|
{
|
||||||
|
for (i = 1; i < argc; i++)
|
||||||
|
if (!do_ref (repo, argv[i], cancellable, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Require a prefix when deleting to help avoid accidents. */
|
||||||
|
if (opt_delete)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"At least one PREFIX is required when deleting refs");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
ret = do_ref (repo, NULL, cancellable, error);
|
||||||
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue