[ostree] core: Rename local-clone to pull-local
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Rename local-clone to pull-local
- Date: Tue, 1 May 2012 21:45:53 +0000 (UTC)
commit d4321629f4da5721385a94ececfc7f6deb72a18a
Author: Colin Walters <walters verbum org>
Date: Tue May 1 17:43:26 2012 -0400
core: Rename local-clone to pull-local
Also change it to copy selective refs, rather than enumerating
all objects.
Makefile-ostree.am | 2 +-
src/ostree/main.c | 2 +-
src/ostree/ot-builtin-local-clone.c | 289 -----------------------------------
src/ostree/ot-builtin-pull-local.c | 204 ++++++++++++++++++++++++
src/ostree/ot-builtins.h | 2 +-
tests/t0000-basic.sh | 4 +-
tests/t0001-archive.sh | 2 +-
7 files changed, 210 insertions(+), 295 deletions(-)
---
diff --git a/Makefile-ostree.am b/Makefile-ostree.am
index 27ace0d..10171c4 100644
--- a/Makefile-ostree.am
+++ b/Makefile-ostree.am
@@ -29,7 +29,7 @@ ostree_SOURCES = src/ostree/main.c \
src/ostree/ot-builtin-diff.c \
src/ostree/ot-builtin-fsck.c \
src/ostree/ot-builtin-init.c \
- src/ostree/ot-builtin-local-clone.c \
+ src/ostree/ot-builtin-pull-local.c \
src/ostree/ot-builtin-log.c \
src/ostree/ot-builtin-ls.c \
src/ostree/ot-builtin-prune.c \
diff --git a/src/ostree/main.c b/src/ostree/main.c
index aa5daa4..365ae77 100644
--- a/src/ostree/main.c
+++ b/src/ostree/main.c
@@ -37,7 +37,7 @@ static OstreeBuiltin builtins[] = {
{ "diff", ostree_builtin_diff, 0 },
{ "init", ostree_builtin_init, 0 },
{ "commit", ostree_builtin_commit, 0 },
- { "local-clone", ostree_builtin_local_clone, 0 },
+ { "pull-local", ostree_builtin_pull_local, 0 },
{ "log", ostree_builtin_log, 0 },
{ "ls", ostree_builtin_ls, 0 },
{ "prune", ostree_builtin_prune, 0 },
diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c
new file mode 100644
index 0000000..a40eb97
--- /dev/null
+++ b/src/ostree/ot-builtin-pull-local.c
@@ -0,0 +1,204 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters verbum org>
+ *
+ * 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.
+ *
+ * Author: Colin Walters <walters verbum org>
+ */
+
+#include "config.h"
+
+#include "ot-builtins.h"
+#include "ostree.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+
+static GOptionEntry options[] = {
+ { NULL }
+};
+
+typedef struct {
+ OstreeRepo *src_repo;
+ OstreeRepo *dest_repo;
+} OtLocalCloneData;
+
+static gboolean
+import_one_object (OtLocalCloneData *data,
+ const char *checksum,
+ OstreeObjectType objtype,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ ot_lobj GFileInfo *file_info = NULL;
+ ot_lobj GFile *content_path = NULL;
+ ot_lobj GFileInfo *archive_info = NULL;
+ ot_lvariant GVariant *metadata = NULL;
+ ot_lvariant GVariant *xattrs = NULL;
+ ot_lobj GInputStream *input = NULL;
+
+ if (objtype == OSTREE_OBJECT_TYPE_FILE)
+ {
+ if (!ostree_repo_load_file (data->src_repo, checksum,
+ &input, &file_info, &xattrs,
+ cancellable, error))
+ goto out;
+
+ if (!ostree_repo_stage_object_trusted (data->dest_repo, OSTREE_OBJECT_TYPE_FILE,
+ checksum, FALSE, file_info, xattrs, input,
+ cancellable, error))
+ goto out;
+ }
+ else
+ {
+ if (!ostree_repo_load_variant (data->src_repo, objtype, checksum, &metadata,
+ error))
+ goto out;
+
+ input = ot_variant_read (metadata);
+
+ if (!ostree_repo_stage_object_trusted (data->dest_repo, objtype,
+ checksum, FALSE, NULL, NULL, input,
+ cancellable, error))
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+gboolean
+ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GError **error)
+{
+ gboolean ret = FALSE;
+ GCancellable *cancellable = NULL;
+ GOptionContext *context;
+ const char *src_repo_path;
+ int i;
+ GHashTableIter hash_iter;
+ gpointer key, value;
+ ot_lhash GHashTable *objects = NULL;
+ ot_lobj GFile *src_f = NULL;
+ ot_lobj GFile *src_repo_dir = NULL;
+ ot_lobj GFile *dest_repo_dir = NULL;
+ ot_lobj GFile *src_dir = NULL;
+ ot_lobj GFile *dest_dir = NULL;
+ ot_lhash GHashTable *refs_to_clone = NULL;
+ ot_lhash GHashTable *objects_to_copy = NULL;
+ OtLocalCloneData data;
+
+ context = g_option_context_new ("SRC_REPO [REFS...] - Copy data from SRC_REPO");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ memset (&data, 0, sizeof (data));
+
+ if (!g_option_context_parse (context, &argc, &argv, error))
+ goto out;
+
+ data.dest_repo = ostree_repo_new (repo_path);
+ if (!ostree_repo_check (data.dest_repo, error))
+ goto out;
+
+ if (argc < 2)
+ {
+ gchar *help = g_option_context_get_help (context, TRUE, NULL);
+ g_printerr ("%s\n", help);
+ g_free (help);
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "DESTINATION must be specified");
+ goto out;
+ }
+
+ src_repo_path = argv[1];
+ src_f = ot_gfile_new_for_path (src_repo_path);
+
+ data.src_repo = ostree_repo_new (src_f);
+ if (!ostree_repo_check (data.src_repo, error))
+ goto out;
+
+ src_repo_dir = g_object_ref (ostree_repo_get_path (data.src_repo));
+ dest_repo_dir = g_object_ref (ostree_repo_get_path (data.dest_repo));
+
+ if (argc == 2)
+ {
+ if (!ostree_repo_list_all_refs (data.src_repo, &refs_to_clone, cancellable, error))
+ goto out;
+ }
+ else
+ {
+ refs_to_clone = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ for (i = 2; i < argc; i++)
+ {
+ const char *ref = argv[i];
+ char *rev;
+
+ if (!ostree_repo_resolve_rev (data.src_repo, ref, FALSE, &rev, error))
+ goto out;
+
+ /* Transfer ownership of rev */
+ g_hash_table_insert (refs_to_clone, g_strdup (ref), rev);
+ }
+ }
+
+ objects_to_copy = ostree_traverse_new_reachable ();
+
+ g_hash_table_iter_init (&hash_iter, refs_to_clone);
+ while (g_hash_table_iter_next (&hash_iter, &key, &value))
+ {
+ const char *checksum = value;
+
+ if (!ostree_traverse_commit (data.src_repo, checksum, 0, objects_to_copy, cancellable, error))
+ goto out;
+ }
+
+ if (!ostree_repo_prepare_transaction (data.dest_repo, cancellable, error))
+ goto out;
+
+ g_hash_table_iter_init (&hash_iter, objects_to_copy);
+ while (g_hash_table_iter_next (&hash_iter, &key, &value))
+ {
+ GVariant *serialized_key = key;
+ const char *checksum;
+ OstreeObjectType objtype;
+
+ ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
+
+ if (!import_one_object (&data, checksum, objtype, cancellable, error))
+ goto out;
+ }
+
+ if (!ostree_repo_commit_transaction (data.dest_repo, NULL, error))
+ goto out;
+
+ g_hash_table_iter_init (&hash_iter, refs_to_clone);
+ while (g_hash_table_iter_next (&hash_iter, &key, &value))
+ {
+ const char *name = key;
+ const char *checksum = value;
+
+ if (!ostree_repo_write_ref (data.dest_repo, NULL, name, checksum, error))
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ if (context)
+ g_option_context_free (context);
+ return ret;
+}
diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h
index a0e5dd8..4d41124 100644
--- a/src/ostree/ot-builtins.h
+++ b/src/ostree/ot-builtins.h
@@ -34,7 +34,7 @@ gboolean ostree_builtin_checksum (int argc, char **argv, GFile *repo_path, GErro
gboolean ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error);
gboolean ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GError **error);
gboolean ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error);
-gboolean ostree_builtin_local_clone (int argc, char **argv, GFile *repo_path, GError **error);
+gboolean ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GError **error);
gboolean ostree_builtin_log (int argc, char **argv, GFile *repo_path, GError **error);
gboolean ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GError **error);
gboolean ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GError **error);
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
index 03a657c..d59d231 100755
--- a/tests/t0000-basic.sh
+++ b/tests/t0000-basic.sh
@@ -132,8 +132,8 @@ echo "ok metadata content"
cd ${test_tmpdir}
mkdir repo2
ostree --repo=repo2 init
-$OSTREE local-clone repo2
-echo "ok local clone"
+ostree --repo=repo2 pull-local repo
+echo "ok pull-local"
cd ${test_tmpdir}
ostree --repo=repo2 checkout test2 test2-checkout-from-local-clone
diff --git a/tests/t0001-archive.sh b/tests/t0001-archive.sh
index f2084dd..2b2c1d2 100755
--- a/tests/t0001-archive.sh
+++ b/tests/t0001-archive.sh
@@ -39,7 +39,7 @@ echo "ok content"
cd ${test_tmpdir}
mkdir repo2
ostree --repo=repo2 init
-$OSTREE local-clone repo2
+ostree --repo=repo2 pull-local repo
echo "ok local clone"
cd ${test_tmpdir}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]