[libgit2-glib] Bind git_cherry_pick



commit ad6cac735ea97ed00b641a3e55d304fb14a4be99
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Jul 27 10:29:28 2014 +0300

    Bind git_cherry_pick

 libgit2-glib/Makefile.am                |    2 +
 libgit2-glib/ggit-cherry-pick-options.c |  300 +++++++++++++++++++++++++++++++
 libgit2-glib/ggit-cherry-pick-options.h |   78 ++++++++
 libgit2-glib/ggit-repository.c          |   40 ++++
 libgit2-glib/ggit-repository.h          |    5 +
 libgit2-glib/ggit-types.h               |    7 +
 6 files changed, 432 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index f413815..21cf8cc 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -23,6 +23,7 @@ INST_H_FILES =                                        \
        ggit-branch.h                           \
        ggit-branch-enumerator.h                \
        ggit-checkout-options.h                 \
+       ggit-cherry-pick-options.h              \
        ggit-clone-options.h                    \
        ggit-commit.h                           \
        ggit-config.h                           \
@@ -85,6 +86,7 @@ C_FILES =                                     \
        ggit-branch.c                           \
        ggit-branch-enumerator.c                \
        ggit-checkout-options.c                 \
+       ggit-cherry-pick-options.c              \
        ggit-clone-options.c                    \
        ggit-commit.c                           \
        ggit-config.c                           \
diff --git a/libgit2-glib/ggit-cherry-pick-options.c b/libgit2-glib/ggit-cherry-pick-options.c
new file mode 100644
index 0000000..40309e8
--- /dev/null
+++ b/libgit2-glib/ggit-cherry-pick-options.c
@@ -0,0 +1,300 @@
+#include "ggit-cherry-pick-options.h"
+#include "ggit-enum-types.h"
+#include "ggit-checkout-options.h"
+#include "ggit-merge-options.h"
+
+#define GGIT_CHERRY_PICK_OPTIONS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), 
GGIT_TYPE_CHERRY_PICK_OPTIONS, GgitCherryPickOptionsPrivate))
+
+struct _GgitCherryPickOptionsPrivate
+{
+       git_cherry_pick_options options;
+
+       GgitCheckoutOptions *checkout_options;
+       GgitMergeOptions *merge_options;
+};
+
+G_DEFINE_TYPE (GgitCherryPickOptions, ggit_cherry_pick_options, G_TYPE_OBJECT)
+
+enum
+{
+       PROP_0,
+       PROP_MAINLINE,
+       PROP_CHECKOUT_OPTIONS,
+       PROP_MERGE_OPTIONS
+};
+
+static void
+ggit_cherry_pick_options_finalize (GObject *object)
+{
+       GgitCherryPickOptions *options;
+
+       options = GGIT_CHERRY_PICK_OPTIONS (object);
+
+       g_clear_object (&options->priv->checkout_options);
+       g_clear_object (&options->priv->merge_options);
+
+       G_OBJECT_CLASS (ggit_cherry_pick_options_parent_class)->finalize (object);
+}
+
+static void
+ggit_cherry_pick_options_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+       GgitCherryPickOptions *self = GGIT_CHERRY_PICK_OPTIONS (object);
+
+       switch (prop_id)
+       {
+       case PROP_MAINLINE:
+               self->priv->options.mainline = g_value_get_int (value);
+               break;
+       case PROP_CHECKOUT_OPTIONS:
+               ggit_cherry_pick_options_set_checkout_options (self,
+                                                              g_value_get_object (value));
+               break;
+       case PROP_MERGE_OPTIONS:
+               ggit_cherry_pick_options_set_merge_options (self,
+                                                           g_value_get_object (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+ggit_cherry_pick_options_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+       GgitCherryPickOptions *self = GGIT_CHERRY_PICK_OPTIONS (object);
+
+       switch (prop_id)
+       {
+       case PROP_MAINLINE:
+               g_value_set_int (value, self->priv->options.mainline);
+               break;
+       case PROP_CHECKOUT_OPTIONS:
+               g_value_set_object (value, self->priv->checkout_options);
+               break;
+       case PROP_MERGE_OPTIONS:
+               g_value_set_object (value, self->priv->merge_options);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+ggit_cherry_pick_options_class_init (GgitCherryPickOptionsClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       git_cherry_pick_options defopts = GIT_CHERRY_PICK_OPTIONS_INIT;
+
+       object_class->finalize = ggit_cherry_pick_options_finalize;
+
+       object_class->get_property = ggit_cherry_pick_options_get_property;
+       object_class->set_property = ggit_cherry_pick_options_set_property;
+
+       g_type_class_add_private (object_class, sizeof (GgitCherryPickOptionsPrivate));
+
+       g_object_class_install_property (object_class,
+                                        PROP_MAINLINE,
+                                        g_param_spec_int ("mainline",
+                                                          "Mainline",
+                                                          "Mainline",
+                                                          0,
+                                                          G_MAXINT,
+                                                          defopts.mainline,
+                                                          G_PARAM_READWRITE |
+                                                          G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_CHECKOUT_OPTIONS,
+                                        g_param_spec_object ("checkout-options",
+                                                             "Checkout Options",
+                                                             "Checkout options",
+                                                             GGIT_TYPE_CHECKOUT_OPTIONS,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+
+}
+
+static void
+ggit_cherry_pick_options_init (GgitCherryPickOptions *self)
+{
+       self->priv = GGIT_CHERRY_PICK_OPTIONS_GET_PRIVATE (self);
+
+       git_cherry_pick_init_options (&self->priv->options, GIT_CHERRY_PICK_OPTIONS_VERSION);
+}
+
+/**
+ * ggit_cherry_pick_options_new:
+ *
+ * Create a new cherry-pick options object.
+ *
+ * Returns: a #GgitCherryPickOptions.
+ *
+ **/
+GgitCherryPickOptions *
+ggit_cherry_pick_options_new ()
+{
+       return g_object_new (GGIT_TYPE_CHERRY_PICK_OPTIONS, NULL);
+}
+
+const git_cherry_pick_options *
+_ggit_cherry_pick_options_get_cherry_pick_options (GgitCherryPickOptions *options)
+{
+       if (options != NULL)
+       {
+               // Make sure to synchronize the wrapped checkout options with the internal checkout options
+               if (options->priv->checkout_options)
+               {
+                       options->priv->options.checkout_opts =
+                               *_ggit_checkout_options_get_checkout_options 
(options->priv->checkout_options);
+               }
+
+               return &options->priv->options;
+       }
+       else
+       {
+               return NULL;
+       }
+}
+
+/**
+ * ggit_cherry_pick_options_get_mainline:
+ * @options: a #GgitCherryPickOptions.
+ *
+ * Get the mainline parent to use when cherry-picking a merge commit.
+ *
+ * Returns: the mainline parent.
+ *
+ **/
+gint
+ggit_cherry_pick_options_get_mainline (GgitCherryPickOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHERRY_PICK_OPTIONS (options), 0);
+
+       return options->priv->options.mainline;
+}
+
+/**
+ * ggit_cherry_pick_options_set_mainline:
+ * @options: a #GgitCherryPickOptions.
+ * @mainline: the mainline parent.
+ *
+ * Set the mainline parent to use when cherry-picking a merge commit.
+ *
+ **/
+void
+ggit_cherry_pick_options_set_mainline (GgitCherryPickOptions *options,
+                                       gint                   mainline)
+{
+       g_return_if_fail (GGIT_IS_CHERRY_PICK_OPTIONS (options));
+
+       options->priv->options.mainline = mainline;
+       g_object_notify (G_OBJECT (options), "mainline");
+}
+
+/**
+ * ggit_cherry_pick_options_get_checkout_options:
+ * @options: a #GgitCherryPickOptions.
+ *
+ * Get the checkout options.
+ *
+ * Returns: (transfer none): a #GgitCheckoutOptions.
+ *
+ **/
+GgitCheckoutOptions *
+ggit_cherry_pick_options_get_checkout_options (GgitCherryPickOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHERRY_PICK_OPTIONS (options), NULL);
+
+       return options->priv->checkout_options;
+}
+
+/**
+ * ggit_cherry_pick_options_set_checkout_options:
+ * @options: a #GgitCherryPickOptions.
+ * @checkout_options: (allow-none): a #GgitCheckoutOptions.
+ *
+ * Set the checkout options.
+ *
+ **/
+void
+ggit_cherry_pick_options_set_checkout_options (GgitCherryPickOptions *options,
+                                               GgitCheckoutOptions   *checkout_options)
+{
+       g_return_if_fail (GGIT_IS_CHERRY_PICK_OPTIONS (options));
+       g_return_if_fail (checkout_options == NULL || GGIT_IS_CHECKOUT_OPTIONS (checkout_options));
+
+       if (options->priv->checkout_options)
+       {
+               g_object_unref (options->priv->checkout_options);
+               options->priv->checkout_options = NULL;
+
+               git_checkout_init_options (&options->priv->options.checkout_opts, 
GIT_CHECKOUT_OPTIONS_VERSION);
+       }
+
+       if (checkout_options)
+       {
+               options->priv->checkout_options = g_object_ref (checkout_options);
+               options->priv->options.checkout_opts = *_ggit_checkout_options_get_checkout_options 
(options->priv->checkout_options);
+       }
+
+       g_object_notify (G_OBJECT (options), "checkout-options");
+}
+
+/**
+ * ggit_cherry_pick_options_get_merge_options:
+ * @options: a #GgitCherryPickOptions.
+ *
+ * Get the merge options.
+ *
+ * Returns: (transfer full): a #GgitMergeOptions.
+ *
+ **/
+GgitMergeOptions *
+ggit_cherry_pick_options_get_merge_options (GgitCherryPickOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHERRY_PICK_OPTIONS (options), NULL);
+
+       return options->priv->merge_options;
+
+}
+
+/**
+ * ggit_cherry_pick_options_set_merge_options:
+ * @options: a #GgitCherryPickOptions.
+ * @merge_options: (allow-none): a #GgitMergeOptions.
+ *
+ * Set the merge options.
+ *
+ **/
+void
+ggit_cherry_pick_options_set_merge_options (GgitCherryPickOptions *options,
+                                            GgitMergeOptions      *merge_options)
+{
+       g_return_if_fail (GGIT_IS_CHERRY_PICK_OPTIONS (options));
+
+       if (options->priv->merge_options)
+       {
+               ggit_merge_options_free (options->priv->merge_options);
+               options->priv->merge_options = NULL;
+
+               git_merge_init_options (&options->priv->options.merge_opts, GIT_MERGE_OPTIONS_VERSION);
+       }
+
+       if (merge_options)
+       {
+               options->priv->merge_options = ggit_merge_options_copy (merge_options);
+               options->priv->options.merge_opts = *_ggit_merge_options_get_merge_options 
(options->priv->merge_options);
+       }
+
+       g_object_notify (G_OBJECT (options), "merge-options");
+}
+
diff --git a/libgit2-glib/ggit-cherry-pick-options.h b/libgit2-glib/ggit-cherry-pick-options.h
new file mode 100644
index 0000000..f1fa2c8
--- /dev/null
+++ b/libgit2-glib/ggit-cherry-pick-options.h
@@ -0,0 +1,78 @@
+/*
+ * ggit-cherry-pick-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_CHERRY_PICK_OPTIONS_H__
+#define __GGIT_CHERRY_PICK_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_CHERRY_PICK_OPTIONS          (ggit_cherry_pick_options_get_type ())
+#define GGIT_CHERRY_PICK_OPTIONS(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GGIT_TYPE_CHERRY_PICK_OPTIONS, GgitCherryPickOptions))
+#define GGIT_CHERRY_PICK_OPTIONS_CONST(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GGIT_TYPE_CHERRY_PICK_OPTIONS, GgitCherryPickOptions const))
+#define GGIT_CHERRY_PICK_OPTIONS_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST ((klass), 
GGIT_TYPE_CHERRY_PICK_OPTIONS, GgitCherryPickOptionsClass))
+#define GGIT_IS_CHERRY_PICK_OPTIONS(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GGIT_TYPE_CHERRY_PICK_OPTIONS))
+#define GGIT_IS_CHERRY_PICK_OPTIONS_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GGIT_TYPE_CHERRY_PICK_OPTIONS))
+#define GGIT_CHERRY_PICK_OPTIONS_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GGIT_TYPE_CHERRY_PICK_OPTIONS, GgitCherryPickOptionsClass))
+
+typedef struct _GgitCherryPickOptionsClass     GgitCherryPickOptionsClass;
+typedef struct _GgitCherryPickOptionsPrivate   GgitCherryPickOptionsPrivate;
+
+struct _GgitCherryPickOptions
+{
+       GObject parent;
+
+       GgitCherryPickOptionsPrivate *priv;
+};
+
+struct _GgitCherryPickOptionsClass
+{
+       GObjectClass parent_class;
+};
+
+GType                  ggit_cherry_pick_options_get_type (void) G_GNUC_CONST;
+
+const git_cherry_pick_options *
+                      _ggit_cherry_pick_options_get_cherry_pick_options (
+                                                              GgitCherryPickOptions  *options);
+
+GgitCherryPickOptions *ggit_cherry_pick_options_new          (void);
+
+gint                   ggit_cherry_pick_options_get_mainline (GgitCherryPickOptions *options);
+void                   ggit_cherry_pick_options_set_mainline (GgitCherryPickOptions *options,
+                                                              gint                   mainline);
+
+GgitCheckoutOptions   *ggit_cherry_pick_options_get_checkout_options (GgitCherryPickOptions *options);
+void                   ggit_cherry_pick_options_set_checkout_options (GgitCherryPickOptions *options,
+                                                                      GgitCheckoutOptions   
*checkout_options);
+
+GgitMergeOptions      *ggit_cherry_pick_options_get_merge_options (GgitCherryPickOptions *options);
+void                   ggit_cherry_pick_options_set_merge_options (GgitCherryPickOptions *options,
+                                                                   GgitMergeOptions      *merge_options);
+
+G_END_DECLS
+
+#endif /* __GGIT_CHERRY_PICK_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 2dfc161..5835433 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -38,6 +38,7 @@
 #include "ggit-blame-options.h"
 #include "ggit-commit.h"
 #include "ggit-revert-options.h"
+#include "ggit-cherry-pick-options.h"
 
 #define GGIT_REPOSITORY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_REPOSITORY, 
GgitRepositoryPrivate))
 
@@ -2904,4 +2905,43 @@ ggit_repository_revert (GgitRepository     *repository,
        return TRUE;
 }
 
+/**
+ * ggit_repository_cherry_pick:
+ * @repository: a #GgitRepository.
+ * @commit: a #GgitCommit.
+ * @options: a #GgitCherryPickOptions.
+ * @error: a #GError for error reporting or %NULL.
+ *
+ * Cherry pick the specified commit, making changes in the index and the working
+ * directory.
+ *
+ * Returns: %TRUE if the commit was cherry-picked successfully, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_repository_cherry_pick (GgitRepository         *repository,
+                             GgitCommit             *commit,
+                             GgitCherryPickOptions  *options,
+                             GError                **error)
+{
+       gint ret;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (GGIT_IS_COMMIT (commit), FALSE);
+       g_return_val_if_fail (options == NULL || GGIT_IS_CHERRY_PICK_OPTIONS (options), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       ret = git_cherry_pick (_ggit_native_get (repository),
+                              _ggit_native_get (commit),
+                              _ggit_cherry_pick_options_get_cherry_pick_options (options));
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 /* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 7efbc37..6974568 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -375,6 +375,11 @@ gboolean            ggit_repository_revert            (GgitRepository
                                                        GgitRevertOptions        *options,
                                                        GError                  **error);
 
+gboolean            ggit_repository_cherry_pick       (GgitRepository           *repository,
+                                                       GgitCommit               *commit,
+                                                       GgitCherryPickOptions    *options,
+                                                       GError                  **error);
+
 G_END_DECLS
 
 #endif /* __GGIT_REPOSITORY_H__ */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index cc0d5e3..85e4872 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -419,6 +419,13 @@ typedef struct _GgitBlameOptions GgitBlameOptions;
 typedef struct _GgitCheckoutOptions GgitCheckoutOptions;
 
 /**
+ * GgitCherryPickOptions:
+ *
+ * Represents the options used when doign a cherry-pick.
+ */
+typedef struct _GgitCherryPickOptions GgitCherryPickOptions;
+
+/**
  * GgitRevertOptions:
  *
  * Represents the options used when reverting.


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