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.
This commit is contained in:
Matthew Barnes 2015-06-07 15:20:14 -04:00 committed by Giuseppe Scrivano
parent 0dbf91484b
commit 6284beb2b6
6 changed files with 107 additions and 0 deletions

View File

@ -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 \

View File

@ -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>

View File

@ -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 }
};

View File

@ -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;
}

View File

@ -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

View File

@ -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}