[libgit2-glib] Add GgitPushOptions



commit 5015430a7b1ed09a0d03878bea38f33311736e82
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Thu Dec 25 13:29:16 2014 +0100

    Add GgitPushOptions

 libgit2-glib/Makefile.am         |    2 +
 libgit2-glib/ggit-push-options.c |  150 ++++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-push-options.h |   71 ++++++++++++++++++
 libgit2-glib/ggit-push.c         |   71 ++++++++++++++++++-
 libgit2-glib/ggit-push.h         |    5 +
 libgit2-glib/ggit-types.h        |    7 ++
 6 files changed, 305 insertions(+), 1 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 3718720..2908a53 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -56,6 +56,7 @@ H_FILES =                                     \
        ggit-oid.h                              \
        ggit-patch.h                            \
        ggit-push.h                             \
+       ggit-push-options.h                     \
        ggit-ref.h                              \
        ggit-ref-spec.h                         \
        ggit-reflog.h                           \
@@ -119,6 +120,7 @@ C_FILES =                                   \
        ggit-oid.c                              \
        ggit-patch.c                            \
        ggit-push.c                             \
+       ggit-push-options.c                     \
        ggit-ref.c                              \
        ggit-ref-spec.c                         \
        ggit-reflog.c                           \
diff --git a/libgit2-glib/ggit-push-options.c b/libgit2-glib/ggit-push-options.c
new file mode 100644
index 0000000..27e24d1
--- /dev/null
+++ b/libgit2-glib/ggit-push-options.c
@@ -0,0 +1,150 @@
+#include "ggit-push-options.h"
+
+#define GGIT_PUSH_OPTIONS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_PUSH_OPTIONS, 
GgitPushOptionsPrivate))
+
+struct _GgitPushOptionsPrivate
+{
+       git_push_options options;
+};
+
+G_DEFINE_TYPE (GgitPushOptions, ggit_push_options, G_TYPE_OBJECT)
+
+enum
+{
+       PROP_0,
+       PROP_PARALLELISM
+};
+
+static void
+ggit_push_options_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+       GgitPushOptions *self = GGIT_PUSH_OPTIONS (object);
+
+       switch (prop_id)
+       {
+       case PROP_PARALLELISM:
+               self->priv->options.pb_parallelism = g_value_get_int (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+ggit_push_options_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+       GgitPushOptions *self = GGIT_PUSH_OPTIONS (object);
+
+       switch (prop_id)
+       {
+       case PROP_PARALLELISM:
+               g_value_set_int (value, self->priv->options.pb_parallelism);
+               break;
+       }
+}
+
+static void
+ggit_push_options_class_init (GgitPushOptionsClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       git_push_options defopts = GIT_PUSH_OPTIONS_INIT;
+
+       object_class->get_property = ggit_push_options_get_property;
+       object_class->set_property = ggit_push_options_set_property;
+
+       g_type_class_add_private (object_class, sizeof (GgitPushOptionsPrivate));
+
+       g_object_class_install_property (object_class,
+                                        PROP_PARALLELISM,
+                                        g_param_spec_int ("parallelism",
+                                                          "Parallelism",
+                                                           "Parallelism",
+                                                           0,
+                                                           G_MAXINT,
+                                                           defopts.pb_parallelism,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT |
+                                                           G_PARAM_STATIC_STRINGS));
+}
+
+static void
+ggit_push_options_init (GgitPushOptions *self)
+{
+       self->priv = GGIT_PUSH_OPTIONS_GET_PRIVATE (self);
+
+       git_push_init_options (&self->priv->options, GIT_PUSH_OPTIONS_VERSION);
+}
+
+/**
+ * ggit_push_options_new:
+ *
+ * Create a new push options object.
+ *
+ * Returns: a #GgitPushOptions.
+ *
+ **/
+GgitPushOptions *
+ggit_push_options_new ()
+{
+       return g_object_new (GGIT_TYPE_PUSH_OPTIONS, NULL);
+}
+
+const git_push_options *
+_ggit_push_options_get_push_options (GgitPushOptions *options)
+{
+       if (options != NULL)
+       {
+               return &options->priv->options;
+       }
+       else
+       {
+               return NULL;
+       }
+}
+
+/**
+ * ggit_push_options_get_parallelism:
+ * @options: a #GgitPushOptions.
+ *
+ * Get the number of parallel threads to use when creating the pack file
+ * to push. The special value 0 indicates that the number of threads will
+ * be automatically detected.
+ *
+ * Returns: the number of parallel threads, or 0 for auto-detect.
+ *
+ **/
+gint
+ggit_push_options_get_parallelism (GgitPushOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_PUSH_OPTIONS (options), 0);
+
+       return options->priv->options.pb_parallelism;
+}
+
+/**
+ * ggit_push_options_set_parallelism:
+ * @options: a #GgitPushOptions.
+ * @parallelism: the number of threads, or 0 for auto-detect.
+ *
+ * Set the number of parallel threads to use when creating the pack file
+ * to push. The special value 0 can be specified for @parallelism indicating that
+ * the number of threads will be automatically detected.
+ *
+ **/
+void
+ggit_push_options_set_parallelism (GgitPushOptions *options,
+                                   gint             parallelism)
+{
+       g_return_if_fail (GGIT_IS_PUSH_OPTIONS (options));
+       g_return_if_fail (parallelism >= 0);
+
+       options->priv->options.pb_parallelism = parallelism;
+       g_object_notify (G_OBJECT (options), "parallelism");
+}
diff --git a/libgit2-glib/ggit-push-options.h b/libgit2-glib/ggit-push-options.h
new file mode 100644
index 0000000..f0cb681
--- /dev/null
+++ b/libgit2-glib/ggit-push-options.h
@@ -0,0 +1,71 @@
+/*
+ * ggit-push-options.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * 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_PUSH_OPTIONS_H__
+#define __GGIT_PUSH_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_PUSH_OPTIONS                 (ggit_push_options_get_type ())
+#define GGIT_PUSH_OPTIONS(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_PUSH_OPTIONS, 
GgitPushOptions))
+#define GGIT_PUSH_OPTIONS_CONST(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_PUSH_OPTIONS, 
GgitPushOptions const))
+#define GGIT_PUSH_OPTIONS_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_PUSH_OPTIONS, 
GgitPushOptionsClass))
+#define GGIT_IS_PUSH_OPTIONS(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_PUSH_OPTIONS))
+#define GGIT_IS_PUSH_OPTIONS_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_PUSH_OPTIONS))
+#define GGIT_PUSH_OPTIONS_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_PUSH_OPTIONS, 
GgitPushOptionsClass))
+
+typedef struct _GgitPushOptionsClass   GgitPushOptionsClass;
+typedef struct _GgitPushOptionsPrivate GgitPushOptionsPrivate;
+
+struct _GgitPushOptions
+{
+       GObject parent;
+
+       GgitPushOptionsPrivate *priv;
+};
+
+struct _GgitPushOptionsClass
+{
+       GObjectClass parent_class;
+};
+
+GType                  ggit_push_options_get_type (void) G_GNUC_CONST;
+
+const git_push_options *
+                      _ggit_push_options_get_push_options (
+                                                          GgitPushOptions *options);
+
+GgitPushOptions       *ggit_push_options_new              (void);
+
+gint                   ggit_push_options_get_parallelism (GgitPushOptions *options);
+void                   ggit_push_options_set_parallelism (GgitPushOptions *options,
+                                                          gint             parallelism);
+
+
+G_END_DECLS
+
+#endif /* __GGIT_PUSH_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-push.c b/libgit2-glib/ggit-push.c
index e1770aa..2a7c247 100644
--- a/libgit2-glib/ggit-push.c
+++ b/libgit2-glib/ggit-push.c
@@ -24,6 +24,7 @@
 #include "ggit-push.h"
 #include "ggit-remote.h"
 #include "ggit-enum-types.h"
+#include "ggit-push-options.h"
 #include "ggit-error.h"
 
 #define GGIT_PUSH_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_PUSH, GgitPushPrivate))
@@ -31,12 +32,14 @@
 struct _GgitPushPrivate
 {
        GgitRemote *remote;
+       GgitPushOptions *options;
 };
 
 enum
 {
        PROP_0,
-       PROP_REMOTE
+       PROP_REMOTE,
+       PROP_OPTIONS
 };
 
 enum
@@ -62,7 +65,9 @@ ggit_push_dispose (GObject *object)
        GgitPushPrivate *priv;
 
        priv = GGIT_PUSH (object)->priv;
+
        g_clear_object (&priv->remote);
+       g_clear_object (&priv->options);
 
        G_OBJECT_CLASS (ggit_push_parent_class)->dispose (object);
 }
@@ -80,6 +85,9 @@ ggit_push_get_property (GObject    *object,
                case PROP_REMOTE:
                        g_value_set_object (value, priv->remote);
                        break;
+               case PROP_OPTIONS:
+                       g_value_set_object (value, priv->options);
+                       break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -99,6 +107,10 @@ ggit_push_set_property (GObject      *object,
                case PROP_REMOTE:
                        priv->remote = g_value_dup_object (value);
                        break;
+               case PROP_OPTIONS:
+                       ggit_push_set_options (GGIT_PUSH (object),
+                                              g_value_get_object (value));
+                       break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -123,6 +135,15 @@ ggit_push_class_init (GgitPushClass *klass)
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY));
 
+       g_object_class_install_property (object_class,
+                                        PROP_OPTIONS,
+                                        g_param_spec_object ("optionse",
+                                                             "Options",
+                                                             "The options associated with this push",
+                                                             GGIT_TYPE_PUSH_OPTIONS,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT));
+
        signals[TRANSFER_PROGRESS] =
                g_signal_new ("transfer-progress",
                              G_TYPE_FROM_CLASS (object_class),
@@ -244,6 +265,54 @@ ggit_push_new (GgitRemote  *remote,
 }
 
 /**
+ * ggit_push_set_options:
+ * @push: a #GgitPush.
+ * @options: (allow-none): the push options or %NULL for default options.
+ *
+ * Set the options used for the push. Providing %NULL for @options will reset
+ * the push options to the default.
+ */
+void
+ggit_push_set_options (GgitPush        *push,
+                       GgitPushOptions *options)
+{
+       g_return_if_fail (GGIT_IS_PUSH (push));
+       g_return_if_fail (options == NULL || GGIT_IS_PUSH_OPTIONS (options));
+
+       g_clear_object (&push->priv->options);
+
+       if (options == NULL)
+       {
+               push->priv->options = ggit_push_options_new ();
+       }
+       else
+       {
+               push->priv->options = g_object_ref (options);
+       }
+
+       git_push_set_options (_ggit_native_get (push),
+                             _ggit_push_options_get_push_options (push->priv->options));
+
+       g_object_notify (G_OBJECT (push), "options");
+}
+
+/**
+ * ggit_push_get_options:
+ * @push: a #GgitPush.
+ *
+ * Get the push options. Changes made to the returned options will be used
+ * for the next push.
+ *
+ * Returns: (transfer none): the push options.
+ */
+GgitPushOptions *
+ggit_push_get_options (GgitPush *push)
+{
+       g_return_val_if_fail (GGIT_IS_PUSH (push), NULL);
+       return push->priv->options;
+}
+
+/**
  * ggit_push_add_refspec:
  * @push: a #GgitPush.
  * @refspec: Refspec string.
diff --git a/libgit2-glib/ggit-push.h b/libgit2-glib/ggit-push.h
index 24ebeda..b2f1257 100644
--- a/libgit2-glib/ggit-push.h
+++ b/libgit2-glib/ggit-push.h
@@ -68,6 +68,11 @@ GType             ggit_push_get_type                       (void) G_GNUC_CONST;
 GgitPush         *ggit_push_new                            (GgitRemote        *remote,
                                                             GError           **error);
 
+void              ggit_push_set_options                    (GgitPush          *push,
+                                                            GgitPushOptions   *options);
+
+GgitPushOptions  *ggit_push_get_options                    (GgitPush          *push);
+
 void              ggit_push_add_refspec                    (GgitPush          *push,
                                                             const gchar       *refspec,
                                                             GError           **error);
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 595d975..561843a 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -292,6 +292,13 @@ typedef struct _GgitPatch GgitPatch;
 typedef struct _GgitPush GgitPush;
 
 /**
+ * GgitPushOptions:
+ *
+ * Represents a git push options.
+ */
+typedef struct _GgitPushOptions GgitPushOptions;
+
+/**
  * GgitRef:
  *
  * Reprensents a git reference.


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