[ostree] libostree: Add ostree_repo_pull_with_options()



commit 64dec0add8dc1e990d48c671ef7d436bbe87552d
Author: Colin Walters <walters verbum org>
Date:   Thu Oct 23 22:01:33 2014 -0400

    libostree: Add ostree_repo_pull_with_options()
    
    We potentially need a lot of argument types for pull.  Rather than
    have a C function with tons of arguments, let's use a GVariant a{sv}
    as a handy extensible (and immutable) bag of properties.
    
    This is prepratory work for adding an option to pull to traverse
    history.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737844

 src/libostree/ostree-repo-pull.c |   51 ++++++++++++++++++++++++++++-----
 src/libostree/ostree-repo.c      |   58 ++++++++++++++++++++++++++++++++++++++
 src/libostree/ostree-repo.h      |    7 ++++
 3 files changed, 108 insertions(+), 8 deletions(-)
---
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index 78237d9..82018b3 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -1198,11 +1198,7 @@ ostree_repo_pull (OstreeRepo               *self,
   return ostree_repo_pull_one_dir (self, remote_name, NULL, refs_to_fetch, flags, progress, cancellable, 
error);
 }
 
-/**
- * ostree_repo_pull_one_dir:
- *
- * Like ostree_repo_pull(), but supports pulling only a subpath.
- */
+/* Documented in ostree-repo.c */
 gboolean
 ostree_repo_pull_one_dir (OstreeRepo               *self,
                           const char               *remote_name,
@@ -1213,6 +1209,31 @@ ostree_repo_pull_one_dir (OstreeRepo               *self,
                           GCancellable             *cancellable,
                           GError                  **error)
 {
+  GVariantBuilder builder;
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+  if (dir_to_pull)
+    g_variant_builder_add (&builder, "{s v}", "subdir",
+                           g_variant_new_variant (g_variant_new_string (dir_to_pull)));
+  g_variant_builder_add (&builder, "{s v}", "flags",
+                         g_variant_new_variant (g_variant_new_int32 (flags)));
+  if (refs_to_fetch)
+    g_variant_builder_add (&builder, "{s v}", "refs",
+                           g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch, 
-1)));
+
+  return ostree_repo_pull_with_options (self, remote_name, g_variant_builder_end (&builder),
+                                        progress, cancellable, error);
+}
+
+/* Documented in ostree-repo.c */
+gboolean
+ostree_repo_pull_with_options (OstreeRepo             *self,
+                               const char             *remote_name,
+                               GVariant               *options,
+                               OstreeAsyncProgress    *progress,
+                               GCancellable           *cancellable,
+                               GError                **error)
+{
   gboolean ret = FALSE;
   GHashTableIter hash_iter;
   gpointer key, value;
@@ -1232,13 +1253,28 @@ ostree_repo_pull_one_dir (OstreeRepo               *self,
   GKeyFile *config = NULL;
   GKeyFile *remote_config = NULL;
   char **configured_branches = NULL;
-  gboolean is_mirror = (flags & OSTREE_REPO_PULL_FLAGS_MIRROR) > 0;
   guint64 bytes_transferred;
   guint64 end_time;
+  OstreeRepoPullFlags flags;
+  const char *dir_to_pull = NULL;
+  char **refs_to_fetch = NULL;
+  gboolean is_mirror;
+
+  if (options)
+    {
+      int flags_i;
+      (void) g_variant_lookup (options, "refs", "^a&s", &refs_to_fetch);
+      (void) g_variant_lookup (options, "flags", "i", &flags_i);
+      /* Reduce risk of issues if enum happens to be 64 bit for some reason */
+      flags = flags_i;
+      (void) g_variant_lookup (options, "subdir", "&s", &dir_to_pull);
+    }
 
   if (dir_to_pull)
     g_return_val_if_fail (dir_to_pull[0] == '/', FALSE);
 
+  is_mirror = (flags & OSTREE_REPO_PULL_FLAGS_MIRROR) > 0;
+
   pull_data->async_error = error;
   pull_data->main_context = g_main_context_ref_thread_default ();
   pull_data->loop = g_main_loop_new (pull_data->main_context, FALSE);
@@ -1651,8 +1687,7 @@ ostree_repo_pull_one_dir (OstreeRepo               *self,
 
   ret = TRUE;
  out:
-  if (pull_data->main_context)
-    g_main_context_unref (pull_data->main_context);
+  g_main_context_unref (pull_data->main_context);
   if (pull_data->loop)
     g_main_loop_unref (pull_data->loop);
   g_strfreev (configured_branches);
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 9861755..5ffb8d9 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -2163,6 +2163,64 @@ ostree_repo_pull (OstreeRepo               *self,
                        "This version of ostree was built without libsoup, and cannot fetch over HTTP");
   return FALSE;
 }
+
+/**
+ * ostree_repo_pull_one_dir:
+ * @self: Repo
+ * @remote_name: Name of remote
+ * @dir_to_pull: Subdirectory path
+ * @refs_to_fetch: (array zero-terminated=1) (element-type utf8) (allow-none): Optional list of refs; if 
%NULL, fetch all configured refs
+ * @flags: Options controlling fetch behavior
+ * @progress: (allow-none): Progress
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * This is similar to ostree_repo_pull(), but only fetches a single
+ * subpath.
+ */
+gboolean
+ostree_repo_pull_one_dir (OstreeRepo               *self,
+                          const char               *remote_name,
+                          char                    **refs_to_fetch,
+                          OstreeRepoPullFlags       flags,
+                          OstreeAsyncProgress      *progress,
+                          GCancellable             *cancellable,
+                          GError                  **error)
+{
+  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                       "This version of ostree was built without libsoup, and cannot fetch over HTTP");
+  return FALSE;
+}
+
+/**
+ * ostree_repo_pull_with_options:
+ * @self: Repo
+ * @remote_name: Name of remote
+ * @options: A GVariant a{sv} with an extensible set of flags.
+ * @progress: (allow-none): Progress
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Like ostree_repo_pull(), but supports an extensible set of flags.
+ * The following are currently defined:
+ *
+ *   * subdir (s): Pull just this subdirectory
+ *   * flags (i): An instance of #OstreeRepoPullFlags
+ *   * refs: (as): Array of string refs
+ */
+gboolean
+ostree_repo_pull_with_options (OstreeRepo             *self,
+                               const char             *remote_name,
+                               GVariant               *options,
+                               OstreeAsyncProgress    *progress,
+                               GCancellable           *cancellable,
+                               GError                **error)
+{
+  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                       "This version of ostree was built without libsoup, and cannot fetch over HTTP");
+  return FALSE;
+}
+
 #endif
 
 /**
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index d924904..9c774cb 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -560,6 +560,13 @@ ostree_repo_pull_one_dir (OstreeRepo               *self,
                           GCancellable             *cancellable,
                           GError                  **error);
 
+gboolean ostree_repo_pull_with_options (OstreeRepo             *self,
+                                        const char             *remote_name,
+                                        GVariant               *options,
+                                        OstreeAsyncProgress    *progress,
+                                        GCancellable           *cancellable,
+                                        GError                **error);
+
 gboolean ostree_repo_sign_commit (OstreeRepo     *self,
                                   const gchar    *commit_checksum,
                                   const gchar    *key_id,


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