[libgit2-glib] Port clone options to use a fetch options instead of remote callbacks



commit 164841fcfd6ee4d62c627692369b72208b33ad37
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Jun 30 19:34:28 2015 +0200

    Port clone options to use a fetch options instead of remote callbacks

 libgit2-glib/Makefile.am          |    2 +
 libgit2-glib/ggit-clone-options.c |   44 +++++-----
 libgit2-glib/ggit-clone-options.h |    8 +-
 libgit2-glib/ggit-fetch-options.c |  162 +++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-fetch-options.h |   53 ++++++++++++
 libgit2-glib/ggit-types.h         |    7 ++
 6 files changed, 250 insertions(+), 26 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 344cb11..093cfe8 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -43,6 +43,7 @@ H_FILES =                                     \
        ggit-diff-options.h                     \
        ggit-diff-similarity-metric.h           \
        ggit-error.h                            \
+       ggit-fetch-options.h                    \
        ggit-index.h                            \
        ggit-index-entry.h                      \
        ggit-index-entry-resolve-undo.h         \
@@ -107,6 +108,7 @@ C_FILES =                                   \
        ggit-diff-options.c                     \
        ggit-diff-similarity-metric.c           \
        ggit-error.c                            \
+       ggit-fetch-options.c                    \
        ggit-index.c                            \
        ggit-index-entry.c                      \
        ggit-index-entry-resolve-undo.c         \
diff --git a/libgit2-glib/ggit-clone-options.c b/libgit2-glib/ggit-clone-options.c
index 4b40b8e..133f7a3 100644
--- a/libgit2-glib/ggit-clone-options.c
+++ b/libgit2-glib/ggit-clone-options.c
@@ -27,7 +27,7 @@
 struct _GgitCloneOptions
 {
        git_clone_options clone_options;
-       GgitRemoteCallbacks *remote_callbacks;
+       GgitFetchOptions *fetch_options;
 };
 
 G_DEFINE_BOXED_TYPE (GgitCloneOptions, ggit_clone_options,
@@ -71,10 +71,10 @@ ggit_clone_options_copy (GgitCloneOptions *clone_options)
        gnew_clone_options.bare = gclone_options->bare;
        gnew_clone_options.checkout_branch = g_strdup (gclone_options->checkout_branch);
 
-       if (clone_options->remote_callbacks)
+       if (clone_options->fetch_options)
        {
-               new_clone_options->remote_callbacks = g_object_ref (clone_options->remote_callbacks);
-               gnew_clone_options.remote_callbacks = *_ggit_remote_callbacks_get_native 
(new_clone_options->remote_callbacks);
+               new_clone_options->fetch_options = g_object_ref (clone_options->fetch_options);
+               gnew_clone_options.fetch_opts = *_ggit_fetch_options_get_fetch_options 
(new_clone_options->fetch_options);
        }
 
        new_clone_options->clone_options = gnew_clone_options;
@@ -98,7 +98,7 @@ ggit_clone_options_free (GgitCloneOptions *clone_options)
        gclone_options = &clone_options->clone_options;
        g_free ((gchar *)gclone_options->checkout_branch);
 
-       g_clear_object (&clone_options->remote_callbacks);
+       ggit_fetch_options_free (clone_options->fetch_options);
 
        g_slice_free (GgitCloneOptions, clone_options);
 }
@@ -188,44 +188,44 @@ ggit_clone_options_set_checkout_branch (GgitCloneOptions *options,
 }
 
 /**
- * ggit_clone_options_get_remote_callbacks:
+ * ggit_clone_options_get_fetch_options:
  * @options: a #GgitCloneOptions.
  *
- * Get the remote callbacks object or %NULL if not set.
+ * Get the fetch options object or %NULL if not set.
  *
- * Returns: (transfer none): the remote callbacks or %NULL.
+ * Returns: (transfer none): the fetch options or %NULL.
  */
-GgitRemoteCallbacks *
-ggit_clone_options_get_remote_callbacks (GgitCloneOptions *options)
+GgitFetchOptions *
+ggit_clone_options_get_fetch_options (GgitCloneOptions *options)
 {
        g_return_val_if_fail (options != NULL, NULL);
-       return options->remote_callbacks;
+       return options->fetch_options;
 }
 
 /**
- * ggit_clone_options_set_remote_callbacks:
+ * ggit_clone_options_set_fetch_options:
  * @options: a #GgitCloneOptions.
- * @callbacks: (allow-none): a #GgitRemoteCallbacks or %NULL.
+ * @fetch_options: (allow-none): a #GgitFetchOptions or %NULL.
  *
- * Set the remote callbacks object.
+ * Set the fetch options object.
  */
 void
-ggit_clone_options_set_remote_callbacks (GgitCloneOptions    *options,
-                                         GgitRemoteCallbacks *callbacks)
+ggit_clone_options_set_fetch_options (GgitCloneOptions *options,
+                                      GgitFetchOptions *fetch_options)
 {
        g_return_if_fail (options != NULL);
 
-       g_clear_object (&options->remote_callbacks);
+       g_clear_object (&options->fetch_options);
 
-       if (callbacks != NULL)
+       if (fetch_options != NULL)
        {
-               options->remote_callbacks = g_object_ref (callbacks);
-               options->clone_options.remote_callbacks = *_ggit_remote_callbacks_get_native (callbacks);
+               options->fetch_options = g_object_ref (fetch_options);
+               options->clone_options.fetch_opts = *_ggit_fetch_options_get_fetch_options (fetch_options);
        }
        else
        {
-               git_remote_callbacks i = GIT_REMOTE_CALLBACKS_INIT;
-               options->clone_options.remote_callbacks = i;
+               git_fetch_options i = GIT_FETCH_OPTIONS_INIT;
+               options->clone_options.fetch_opts = i;
        }
 }
 
diff --git a/libgit2-glib/ggit-clone-options.h b/libgit2-glib/ggit-clone-options.h
index 4e1e988..9711611 100644
--- a/libgit2-glib/ggit-clone-options.h
+++ b/libgit2-glib/ggit-clone-options.h
@@ -26,7 +26,7 @@
 #include <git2.h>
 
 #include <libgit2-glib/ggit-types.h>
-#include <libgit2-glib/ggit-remote-callbacks.h>
+#include <libgit2-glib/ggit-fetch-options.h>
 
 G_BEGIN_DECLS
 
@@ -52,9 +52,9 @@ const gchar               *ggit_clone_options_get_checkout_branch (GgitCloneOpti
 void                       ggit_clone_options_set_checkout_branch (GgitCloneOptions        *options,
                                                                    const gchar             *checkout_branch);
 
-GgitRemoteCallbacks       *ggit_clone_options_get_remote_callbacks (GgitCloneOptions       *options);
-void                       ggit_clone_options_set_remote_callbacks (GgitCloneOptions       *options,
-                                                                    GgitRemoteCallbacks    *callbacks);
+GgitFetchOptions          *ggit_clone_options_get_fetch_options   (GgitCloneOptions       *options);
+void                       ggit_clone_options_set_fetch_options   (GgitCloneOptions       *options,
+                                                                   GgitFetchOptions       *fetch_options);
 
 G_END_DECLS
 
diff --git a/libgit2-glib/ggit-fetch-options.c b/libgit2-glib/ggit-fetch-options.c
new file mode 100644
index 0000000..5c6af04
--- /dev/null
+++ b/libgit2-glib/ggit-fetch-options.c
@@ -0,0 +1,162 @@
+/*
+ * ggit-fetch-options.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2015 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib 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.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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 libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <git2.h>
+
+#include "ggit-fetch-options.h"
+#include "ggit-transfer-progress.h"
+#include "ggit-native.h"
+
+struct _GgitFetchOptions
+{
+       git_fetch_options fetch_options;
+       GgitRemoteCallbacks *remote_callbacks;
+};
+
+G_DEFINE_BOXED_TYPE (GgitFetchOptions, ggit_fetch_options,
+                     ggit_fetch_options_copy, ggit_fetch_options_free)
+
+const git_fetch_options *
+_ggit_fetch_options_get_fetch_options (GgitFetchOptions *fetch_options)
+{
+       /* NULL is common for fetch_options as it specifies to use the default
+        * so handle a NULL fetch_options here instead of in every caller.
+        */
+       if (fetch_options == NULL)
+       {
+               return NULL;
+       }
+
+       return (const git_fetch_options *)&fetch_options->fetch_options;
+}
+
+/**
+ * ggit_fetch_options_copy:
+ * @fetch_options: a #GgitFetchOptions.
+ *
+ * Copies @fetch_options into a newly allocated #GgitFetchOptions.
+ *
+ * Returns: (transfer full): a newly allocated #GgitFetchOptions.
+ */
+GgitFetchOptions *
+ggit_fetch_options_copy (GgitFetchOptions *fetch_options)
+{
+       GgitFetchOptions *new_fetch_options;
+       git_fetch_options *gfetch_options;
+       git_fetch_options gnew_fetch_options = GIT_FETCH_OPTIONS_INIT;
+
+       g_return_val_if_fail (fetch_options != NULL, NULL);
+
+       gfetch_options = &fetch_options->fetch_options;
+
+       new_fetch_options = g_slice_new0 (GgitFetchOptions);
+
+       gnew_fetch_options.prune = gfetch_options->prune;
+       gnew_fetch_options.update_fetchhead = gfetch_options->update_fetchhead;
+       gnew_fetch_options.download_tags = gfetch_options->download_tags;
+
+       if (fetch_options->remote_callbacks)
+       {
+               new_fetch_options->remote_callbacks = g_object_ref (fetch_options->remote_callbacks);
+               gnew_fetch_options.callbacks = *_ggit_remote_callbacks_get_native 
(new_fetch_options->remote_callbacks);
+       }
+
+       new_fetch_options->fetch_options = gnew_fetch_options;
+
+       return new_fetch_options;
+}
+
+/**
+ * ggit_fetch_options_free:
+ * @fetch_options: a #GgitFetchOptions.
+ *
+ * Frees @fetch_options.
+ */
+void
+ggit_fetch_options_free (GgitFetchOptions *fetch_options)
+{
+       g_return_if_fail (fetch_options != NULL);
+
+       g_clear_object (&fetch_options->remote_callbacks);
+       g_slice_free (GgitFetchOptions, fetch_options);
+}
+
+/**
+ * ggit_fetch_options_new:
+ *
+ * Creates a new #GgitFetchOptions.
+ *
+ * Returns: a newly allocated #GgitFetchOptions.
+ */
+GgitFetchOptions *
+ggit_fetch_options_new (void)
+{
+       GgitFetchOptions *fetch_options;
+       git_fetch_options gfetch_options = GIT_FETCH_OPTIONS_INIT;
+
+       fetch_options = g_slice_new0 (GgitFetchOptions);
+       fetch_options->fetch_options = gfetch_options;
+
+       return fetch_options;
+}
+
+/**
+ * ggit_fetch_options_get_fetch_options:
+ * @options: a #GgitFetchOptions.
+ *
+ * Get the remote callbacks object or %NULL if not set.
+ *
+ * Returns: (transfer none): the remote callbacks or %NULL.
+ */
+GgitRemoteCallbacks *
+ggit_fetch_options_get_remote_callbacks (GgitFetchOptions *options)
+{
+       g_return_val_if_fail (options != NULL, NULL);
+       return options->remote_callbacks;
+}
+
+/**
+ * ggit_fetch_options_set_fetch_options:
+ * @options: a #GgitFetchOptions.
+ * @fetch_options: (allow-none): a #GgitFetchOptions or %NULL.
+ *
+ * Set the fetch options object.
+ */
+void
+ggit_fetch_options_set_remote_callbacks (GgitFetchOptions    *options,
+                                         GgitRemoteCallbacks *callbacks)
+{
+       g_return_if_fail (options != NULL);
+
+       g_clear_object (&options->remote_callbacks);
+
+       if (callbacks != NULL)
+       {
+               options->remote_callbacks = g_object_ref (callbacks);
+               options->fetch_options.callbacks = *_ggit_remote_callbacks_get_native (callbacks);
+       }
+       else
+       {
+               git_remote_callbacks i = GIT_REMOTE_CALLBACKS_INIT;
+               options->fetch_options.callbacks = i;
+       }
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-fetch-options.h b/libgit2-glib/ggit-fetch-options.h
new file mode 100644
index 0000000..93b6d3c
--- /dev/null
+++ b/libgit2-glib/ggit-fetch-options.h
@@ -0,0 +1,53 @@
+/*
+ * ggit-fetch-options.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2015 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib 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.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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 libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GGIT_FETCH_OPTIONS_H__
+#define __GGIT_FETCH_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include <libgit2-glib/ggit-types.h>
+#include <libgit2-glib/ggit-remote-callbacks.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_FETCH_OPTIONS       (ggit_fetch_options_get_type ())
+#define GGIT_FETCH_OPTIONS(obj)       ((GgitFetchOptions *)obj)
+
+GType                      ggit_fetch_options_get_type            (void) G_GNUC_CONST;
+
+const git_fetch_options  *_ggit_fetch_options_get_fetch_options   (GgitFetchOptions        *fetch_options);
+
+GgitFetchOptions          *ggit_fetch_options_copy                (GgitFetchOptions        *fetch_options);
+void                       ggit_fetch_options_free                (GgitFetchOptions        *fetch_options);
+
+GgitFetchOptions          *ggit_fetch_options_new                 (void);
+
+GgitRemoteCallbacks       *ggit_fetch_options_get_remote_callbacks (GgitFetchOptions       *options);
+void                       ggit_fetch_options_set_remote_callbacks (GgitFetchOptions       *options,
+                                                                    GgitRemoteCallbacks    *callbacks);
+
+G_END_DECLS
+
+#endif /* __GGIT_FETCH_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 222527f..8a317b3 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -194,6 +194,13 @@ typedef struct _GgitBlame GgitBlame;
 typedef struct _GgitBlameHunk GgitBlameHunk;
 
 /**
+ * GgitFetchOptions:
+ *
+ * Represents a git fetch options.
+ */
+typedef struct _GgitFetchOptions GgitFetchOptions;
+
+/**
  * GgitIndex:
  *
  * Represents an index object.


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