[ostree] ostree: Add a "remote refs" command



commit 6284beb2b6ced7eb2ea1ddd5fc80c39ef52b0507
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Jun 7 15:20:14 2015 -0400

    ostree: Add a "remote refs" command
    
    Works like "ostree refs" but fetches refs from a remote repo.
    
    This depends on the remote repo having a summary file, but any repo
    being served over HTTP *ought* to have one.

 Makefile-ostree.am                  |    1 +
 doc/ostree-remote.xml               |    3 +
 src/ostree/ot-builtin-remote.c      |    1 +
 src/ostree/ot-remote-builtin-refs.c |   96 +++++++++++++++++++++++++++++++++++
 src/ostree/ot-remote-builtins.h     |    1 +
 tests/test-pull-metalink.sh         |    5 ++
 6 files changed, 107 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-ostree.am b/Makefile-ostree.am
index 9ae9870..8fd426f 100644
--- a/Makefile-ostree.am
+++ b/Makefile-ostree.am
@@ -80,6 +80,7 @@ ostree_SOURCES += \
        src/ostree/ot-remote-builtin-gpg-import.c \
        src/ostree/ot-remote-builtin-list.c \
        src/ostree/ot-remote-builtin-show-url.c \
+        src/ostree/ot-remote-builtin-refs.c \
        $(NULL)
 
 ostree_bin_shared_cflags = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree 
-I$(srcdir)/src/ostree \
diff --git a/doc/ostree-remote.xml b/doc/ostree-remote.xml
index 7b643f2..ae9e078 100644
--- a/doc/ostree-remote.xml
+++ b/doc/ostree-remote.xml
@@ -63,6 +63,9 @@ Boston, MA 02111-1307, USA.
             <cmdsynopsis>
                 <command>ostree remote gpg-import</command> <arg choice="opt" rep="repeat">OPTIONS</arg> 
<arg choice="req">NAME</arg> <arg choice="opt" rep="repeat">KEY-ID</arg>
             </cmdsynopsis>
+            <cmdsynopsis>
+                <command>ostree remote refs</command> <arg choice="req">NAME</arg>
+            </cmdsynopsis>
     </refsynopsisdiv>
 
     <refsect1>
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c
index c112063..4ea8d22 100644
--- a/src/ostree/ot-builtin-remote.c
+++ b/src/ostree/ot-builtin-remote.c
@@ -37,6 +37,7 @@ static OstreeRemoteCommand remote_subcommands[] = {
   { "show-url", ot_remote_builtin_show_url },
   { "list", ot_remote_builtin_list },
   { "gpg-import", ot_remote_builtin_gpg_import },
+  { "refs", ot_remote_builtin_refs },
   { NULL, NULL }
 };
 
diff --git a/src/ostree/ot-remote-builtin-refs.c b/src/ostree/ot-remote-builtin-refs.c
new file mode 100644
index 0000000..c3dbbf2
--- /dev/null
+++ b/src/ostree/ot-remote-builtin-refs.c
@@ -0,0 +1,96 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "otutil.h"
+
+#include "ot-main.h"
+#include "ot-remote-builtins.h"
+
+static GOptionEntry option_entries[] = {
+};
+
+gboolean
+ot_remote_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error)
+{
+  GOptionContext *context;
+  glnx_unref_object OstreeRepo *repo = NULL;
+  const char *remote_name;
+  g_autoptr(GBytes) summary_bytes = NULL;
+  gboolean ret = FALSE;
+
+  context = g_option_context_new ("NAME - List remote refs");
+
+  if (!ostree_option_context_parse (context, option_entries, &argc, &argv,
+                                    OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
+    goto out;
+
+  if (argc < 2)
+    {
+      ot_util_usage_error (context, "NAME must be specified", error);
+      goto out;
+    }
+
+  remote_name = argv[1];
+
+  if (!ostree_repo_remote_fetch_summary (repo, remote_name,
+                                         &summary_bytes, NULL,
+                                         cancellable, error))
+    goto out;
+
+  if (summary_bytes == NULL)
+    {
+      g_print ("Remote refs not available; server has no summary file\n");
+    }
+  else
+    {
+      g_autoptr(GVariant) summary = NULL;
+      g_autoptr(GVariant) ref_map = NULL;
+      GVariantIter iter;
+      GVariant *child;
+
+      summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT,
+                                          summary_bytes, FALSE);
+
+      ref_map = g_variant_get_child_value (summary, 0);
+
+      /* Ref map should already be sorted by ref name. */
+      g_variant_iter_init (&iter, ref_map);
+      while ((child = g_variant_iter_next_value (&iter)) != NULL)
+        {
+          const char *ref_name = NULL;
+
+          g_variant_get_child (child, 0, "&s", &ref_name);
+
+          if (ref_name != NULL)
+            g_print ("%s\n", ref_name);
+
+          g_variant_unref (child);
+        }
+    }
+
+  ret = TRUE;
+
+out:
+  g_option_context_free (context);
+
+  return ret;
+}
diff --git a/src/ostree/ot-remote-builtins.h b/src/ostree/ot-remote-builtins.h
index 286ac9a..b7974a4 100644
--- a/src/ostree/ot-remote-builtins.h
+++ b/src/ostree/ot-remote-builtins.h
@@ -29,5 +29,6 @@ gboolean ot_remote_builtin_delete (int argc, char **argv, GCancellable *cancella
 gboolean ot_remote_builtin_gpg_import (int argc, char **argv, GCancellable *cancellable, GError **error);
 gboolean ot_remote_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error);
 gboolean ot_remote_builtin_show_url (int argc, char **argv, GCancellable *cancellable, GError **error);
+gboolean ot_remote_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error);
 
 G_END_DECLS
diff --git a/tests/test-pull-metalink.sh b/tests/test-pull-metalink.sh
index cd9631a..085a72a 100755
--- a/tests/test-pull-metalink.sh
+++ b/tests/test-pull-metalink.sh
@@ -74,6 +74,11 @@ ${CMD_PREFIX} ostree --repo=repo rev-parse origin:main
 ${CMD_PREFIX} ostree --repo=repo fsck
 echo "ok pull via metalink"
 
+# Test fetching the summary through ostree_repo_remote_fetch_summary()
+${CMD_PREFIX} ostree --repo=repo remote refs origin > origin_refs
+assert_file_has_content origin_refs "main"
+echo "ok remote refs via metalink"
+
 cp metalink-data/metalink.xml{,.orig}
 cp ostree-srv/gnomerepo/summary{,.orig}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]