[ostree] refs: allow to specify multiple refs as args
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] refs: allow to specify multiple refs as args
- Date: Wed, 2 Mar 2016 19:53:31 +0000 (UTC)
commit a4be237a2eb8a3c1171081a81c808c5c8f1e24f5
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Mon Feb 29 11:14:59 2016 +0100
refs: allow to specify multiple refs as args
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
man/ostree-refs.xml | 2 +-
src/ostree/ot-builtin-refs.c | 70 ++++++++++++++++++++++++++---------------
2 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/man/ostree-refs.xml b/man/ostree-refs.xml
index e97cb1c..6d75d36 100644
--- a/man/ostree-refs.xml
+++ b/man/ostree-refs.xml
@@ -57,7 +57,7 @@ Boston, MA 02111-1307, USA.
<refsect1>
<title>Description</title>
<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>
</refsect1>
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c
index 575f664..dabb285 100644
--- a/src/ostree/ot-builtin-refs.c
+++ b/src/ostree/ot-builtin-refs.c
@@ -33,39 +33,18 @@ static GOptionEntry options[] = {
{ NULL }
};
-gboolean
-ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error)
+static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, 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;
GHashTableIter hashiter;
gpointer hashkey, hashvalue;
-
- 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;
+ gboolean ret = FALSE;
if (!opt_delete)
{
+ if (!ostree_repo_list_refs (repo, refspec_prefix, &refs, cancellable, error))
+ goto out;
+
g_hash_table_iter_init (&hashiter, refs);
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
{
@@ -75,6 +54,10 @@ ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **
}
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);
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;
}
}
+ 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;
out:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]