[libgit2-glib] Add checkout API



commit 52384f1ee95697703e14c9b6d08d2481342302f3
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Tue Jun 24 23:56:31 2014 +0200

    Add checkout API

 libgit2-glib/Makefile.am             |    2 +
 libgit2-glib/ggit-checkout-options.c |  849 ++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-checkout-options.h |  141 ++++++
 libgit2-glib/ggit-repository.c       |  122 +++++
 libgit2-glib/ggit-repository.h       |   15 +
 libgit2-glib/ggit-types.h            |   33 ++
 6 files changed, 1162 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 42cef7f..23a479b 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -24,6 +24,7 @@ INST_H_FILES =                                \
        ggit-blob-output-stream.h       \
        ggit-branch.h                   \
        ggit-branch-enumerator.h        \
+       ggit-checkout-options.h         \
        ggit-clone-options.h            \
        ggit-commit.h                   \
        ggit-config.h                   \
@@ -82,6 +83,7 @@ C_FILES =                             \
        ggit-blob-output-stream.c       \
        ggit-branch.c                   \
        ggit-branch-enumerator.c        \
+       ggit-checkout-options.c         \
        ggit-clone-options.c            \
        ggit-commit.c                   \
        ggit-config.c                   \
diff --git a/libgit2-glib/ggit-checkout-options.c b/libgit2-glib/ggit-checkout-options.c
new file mode 100644
index 0000000..af44cb7
--- /dev/null
+++ b/libgit2-glib/ggit-checkout-options.c
@@ -0,0 +1,849 @@
+#include "ggit-checkout-options.h"
+#include "ggit-enum-types.h"
+#include "ggit-tree.h"
+#include "ggit-diff-file.h"
+
+#define GGIT_CHECKOUT_OPTIONS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), 
GGIT_TYPE_CHECKOUT_OPTIONS, GgitCheckoutOptionsPrivate))
+
+struct _GgitCheckoutOptionsPrivate
+{
+       git_checkout_options options;
+
+       gchar **paths;
+       GgitTree *baseline;
+
+       gchar *target_directory;
+       gchar *ancestor_label;
+       gchar *our_label;
+       gchar *their_label;
+};
+
+G_DEFINE_TYPE (GgitCheckoutOptions, ggit_checkout_options, G_TYPE_OBJECT)
+
+enum
+{
+       PROP_0,
+       PROP_STRATEGY,
+       PROP_DISABLE_FILTERS,
+       PROP_DIR_MODE,
+       PROP_FILE_MODE,
+       PROP_FILE_OPEN_FLAGS,
+       PROP_NOTIFY_FLAGS,
+       PROP_BASELINE,
+       PROP_TARGET_DIRECTORY,
+       PROP_ANCESTOR_LABEL,
+       PROP_OUR_LABEL,
+       PROP_THEIR_LABEL
+};
+
+static void
+ggit_checkout_options_finalize (GObject *object)
+{
+       GgitCheckoutOptions *options;
+
+       options = GGIT_CHECKOUT_OPTIONS (object);
+
+       g_strfreev (options->priv->paths);
+       g_clear_object (&options->priv->baseline);
+
+       g_free (options->priv->target_directory);
+       g_free (options->priv->ancestor_label);
+       g_free (options->priv->our_label);
+       g_free (options->priv->their_label);
+
+       G_OBJECT_CLASS (ggit_checkout_options_parent_class)->finalize (object);
+}
+
+static void
+ggit_checkout_options_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+       GgitCheckoutOptions *self = GGIT_CHECKOUT_OPTIONS (object);
+
+       switch (prop_id)
+       {
+       case PROP_STRATEGY:
+               self->priv->options.checkout_strategy = g_value_get_flags (value);
+               break;
+       case PROP_DISABLE_FILTERS:
+               self->priv->options.disable_filters = g_value_get_boolean (value);
+               break;
+       case PROP_DIR_MODE:
+               self->priv->options.dir_mode = g_value_get_uint (value);
+               break;
+       case PROP_FILE_MODE:
+               self->priv->options.file_mode = g_value_get_uint (value);
+               break;
+       case PROP_FILE_OPEN_FLAGS:
+               self->priv->options.file_open_flags = g_value_get_int (value);
+               break;
+       case PROP_NOTIFY_FLAGS:
+               self->priv->options.notify_flags = g_value_get_flags (value);
+               break;
+       case PROP_BASELINE:
+               ggit_checkout_options_set_baseline (self,
+                                                   g_value_get_object (value));
+               break;
+       case PROP_TARGET_DIRECTORY:
+               ggit_checkout_options_set_target_directory (self,
+                                                           g_value_get_string (value));
+               break;
+       case PROP_ANCESTOR_LABEL:
+               ggit_checkout_options_set_ancestor_label (self,
+                                                         g_value_get_string (value));
+               break;
+       case PROP_OUR_LABEL:
+               ggit_checkout_options_set_our_label (self,
+                                                    g_value_get_string (value));
+               break;
+       case PROP_THEIR_LABEL:
+               ggit_checkout_options_set_their_label (self,
+                                                      g_value_get_string (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+ggit_checkout_options_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+       GgitCheckoutOptions *self = GGIT_CHECKOUT_OPTIONS (object);
+
+       switch (prop_id)
+       {
+       case PROP_STRATEGY:
+               g_value_set_flags (value, self->priv->options.checkout_strategy);
+               break;
+       case PROP_DISABLE_FILTERS:
+               g_value_set_boolean (value, self->priv->options.disable_filters);
+               break;
+       case PROP_DIR_MODE:
+               g_value_set_uint (value, self->priv->options.dir_mode);
+               break;
+       case PROP_FILE_MODE:
+               g_value_set_uint (value, self->priv->options.file_mode);
+               break;
+       case PROP_FILE_OPEN_FLAGS:
+               g_value_set_int (value, self->priv->options.file_open_flags);
+               break;
+       case PROP_NOTIFY_FLAGS:
+               g_value_set_flags (value, self->priv->options.notify_flags);
+               break;
+       case PROP_BASELINE:
+               g_value_set_object (value, self->priv->baseline);
+               break;
+       case PROP_TARGET_DIRECTORY:
+               g_value_set_string (value, self->priv->target_directory);
+               break;
+       case PROP_ANCESTOR_LABEL:
+               g_value_set_string (value, self->priv->ancestor_label);
+               break;
+       case PROP_OUR_LABEL:
+               g_value_set_string (value, self->priv->our_label);
+               break;
+       case PROP_THEIR_LABEL:
+               g_value_set_string (value, self->priv->their_label);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+progress_callback_wrapper (const gchar *path,
+                           gsize        completed_steps,
+                           gsize        total_steps,
+                           gpointer     payload)
+{
+       GgitCheckoutOptions *options = payload;
+
+       GGIT_CHECKOUT_OPTIONS_GET_CLASS (options)->progress (options,
+                                                            path,
+                                                            completed_steps,
+                                                            total_steps);
+}
+
+static gint
+notify_callback_wrapper (git_checkout_notify_t  flags,
+                         const gchar           *path,
+                         const git_diff_file   *baseline,
+                         const git_diff_file   *target,
+                         const git_diff_file   *workdir,
+                         gpointer               payload)
+{
+       GgitCheckoutOptions *options = payload;
+       GgitDiffFile *gbaseline;
+       GgitDiffFile *gtarget;
+       GgitDiffFile *gworkdir;
+       GgitCheckoutNotifyFlags gflags;
+       gint ret;
+
+       gbaseline = _ggit_diff_file_wrap (baseline);
+       gtarget = _ggit_diff_file_wrap (target);
+       gworkdir = _ggit_diff_file_wrap (workdir);
+
+       gflags = (GgitCheckoutNotifyFlags)flags;
+
+       ret = GGIT_CHECKOUT_OPTIONS_GET_CLASS (options)->notify (options,
+                                                                gflags,
+                                                                path,
+                                                                gbaseline,
+                                                                gtarget,
+                                                                gworkdir);
+
+       ggit_diff_file_unref (gbaseline);
+       ggit_diff_file_unref (gtarget);
+       ggit_diff_file_unref (gworkdir);
+
+       return ret;
+}
+
+static void
+ggit_checkout_options_constructed (GObject *object)
+{
+       GgitCheckoutOptions *options;
+
+       options = GGIT_CHECKOUT_OPTIONS (object);
+
+       if (GGIT_CHECKOUT_OPTIONS_GET_CLASS (object)->progress != NULL)
+       {
+               options->priv->options.progress_cb = progress_callback_wrapper;
+               options->priv->options.progress_payload = options;
+       }
+
+       if (GGIT_CHECKOUT_OPTIONS_GET_CLASS (object)->notify != NULL)
+       {
+               options->priv->options.notify_cb = notify_callback_wrapper;
+               options->priv->options.notify_payload = options;
+       }
+}
+
+static void
+ggit_checkout_options_class_init (GgitCheckoutOptionsClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       git_checkout_options defaultopts = GIT_CHECKOUT_OPTIONS_INIT;
+
+       object_class->finalize = ggit_checkout_options_finalize;
+
+       object_class->get_property = ggit_checkout_options_get_property;
+       object_class->set_property = ggit_checkout_options_set_property;
+
+       object_class->constructed = ggit_checkout_options_constructed;
+
+       g_type_class_add_private (object_class, sizeof (GgitCheckoutOptionsPrivate));
+
+       
+
+       g_object_class_install_property (object_class,
+                                        PROP_STRATEGY,
+                                        g_param_spec_flags ("strategy",
+                                                            "Strategy",
+                                                            "Strategy",
+                                                            GGIT_TYPE_CHECKOUT_STRATEGY,
+                                                            defaultopts.checkout_strategy,
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_DISABLE_FILTERS,
+                                        g_param_spec_boolean ("disable-filters",
+                                                              "Disable Filters",
+                                                              "Disable filters",
+                                                              defaultopts.disable_filters,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_DIR_MODE,
+                                        g_param_spec_uint ("dir-mode",
+                                                           "Dir Mode",
+                                                           "Dir mode",
+                                                           0,
+                                                           G_MAXUINT,
+                                                           defaultopts.dir_mode,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_FILE_MODE,
+                                        g_param_spec_uint ("file-mode",
+                                                           "File Mode",
+                                                           "File mode",
+                                                           0,
+                                                           G_MAXUINT,
+                                                           defaultopts.file_mode,
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_FILE_OPEN_FLAGS,
+                                        g_param_spec_int ("file-open-flags",
+                                                          "File Open Flags",
+                                                          "File open flags",
+                                                          G_MININT,
+                                                          G_MAXINT,
+                                                          defaultopts.file_open_flags,
+                                                          G_PARAM_READWRITE |
+                                                          G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_NOTIFY_FLAGS,
+                                        g_param_spec_flags ("notify-flags",
+                                                            "Notify Flags",
+                                                            "Notify flags",
+                                                            GGIT_TYPE_CHECKOUT_NOTIFY_FLAGS,
+                                                            defaultopts.notify_flags,
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_BASELINE,
+                                        g_param_spec_object ("baseline",
+                                                             "Baseline",
+                                                             "Baseline",
+                                                             GGIT_TYPE_TREE,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_TARGET_DIRECTORY,
+                                        g_param_spec_string ("target-directory",
+                                                             "Target Directory",
+                                                             "Target directory",
+                                                             defaultopts.target_directory,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_ANCESTOR_LABEL,
+                                        g_param_spec_string ("ancestor-label",
+                                                             "Ancestor Label",
+                                                             "Ancestor label",
+                                                             defaultopts.ancestor_label,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_OUR_LABEL,
+                                        g_param_spec_string ("our-label",
+                                                             "Our Label",
+                                                             "Our label",
+                                                             defaultopts.our_label,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (object_class,
+                                        PROP_THEIR_LABEL,
+                                        g_param_spec_string ("their-label",
+                                                             "Their Label",
+                                                             "Their label",
+                                                             defaultopts.their_label,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+}
+
+static void
+ggit_checkout_options_init (GgitCheckoutOptions *self)
+{
+       self->priv = GGIT_CHECKOUT_OPTIONS_GET_PRIVATE (self);
+
+       git_checkout_init_options (&self->priv->options, GIT_CHECKOUT_OPTIONS_VERSION);
+}
+
+/**
+ * ggit_checkout_options_new:
+ *
+ * Create a new checkout options object.
+ *
+ * Returns: a #GgitCheckoutOptions.
+ *
+ **/
+GgitCheckoutOptions *
+ggit_checkout_options_new ()
+{
+       return g_object_new (GGIT_TYPE_CHECKOUT_OPTIONS, NULL);
+}
+
+const git_checkout_options *
+_ggit_checkout_options_get_checkout_options (GgitCheckoutOptions *options)
+{
+       if (options != NULL)
+       {
+               return &options->priv->options;
+       }
+       else
+       {
+               return NULL;
+       }
+}
+
+/**
+ * ggit_checkout_options_get_strategy:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout strategy.
+ *
+ * Returns: a #GgitCheckoutStrategy.
+ *
+ **/
+GgitCheckoutStrategy
+ggit_checkout_options_get_strategy (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
+
+       return (GgitCheckoutStrategy)options->priv->options.checkout_strategy;
+}
+
+/**
+ * ggit_checkout_options_set_strategy:
+ * @options: a #GgitCheckoutOptions.
+ * @strategy: a #GgitCheckoutStrategy.
+ *
+ * Set the checkout strategy.
+ *
+ **/
+void
+ggit_checkout_options_set_strategy (GgitCheckoutOptions  *options,
+                                    GgitCheckoutStrategy  strategy)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       options->priv->options.checkout_strategy = strategy;
+       g_object_notify (G_OBJECT (options), "strategy");
+}
+
+/**
+ * ggit_checkout_options_get_disable_filters:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get whether filters are disabled.
+ *
+ * Returns: %TRUE if filters are disabled, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_checkout_options_get_disable_filters (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), FALSE);
+
+       return (gboolean)options->priv->options.disable_filters;
+}
+
+/**
+ * ggit_checkout_options_set_disable_filters:
+ * @options: a #GgitCheckoutOptions.
+ * @disable: disable filters.
+ *
+ * Set whether to disable filters.
+ *
+ **/
+void
+ggit_checkout_options_set_disable_filters (GgitCheckoutOptions *options,
+                                           gboolean             disable)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       options->priv->options.disable_filters = (gboolean)disable;
+       g_object_notify (G_OBJECT (options), "disable-filters");
+}
+
+/**
+ * ggit_checkout_options_get_dir_mode:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the default checkout directory mode.
+ *
+ * Returns: the default directory mode.
+ *
+ **/
+guint
+ggit_checkout_options_get_dir_mode (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
+
+       return (guint)options->priv->options.dir_mode;
+}
+
+/**
+ * ggit_checkout_options_set_dir_mode:
+ * @options: a #GgitCheckoutOptions.
+ * @dir_mode: the dir mode.
+ *
+ * Set the default checkout directory mode.
+ *
+ **/
+void
+ggit_checkout_options_set_dir_mode (GgitCheckoutOptions *options,
+                                    guint                dir_mode)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       options->priv->options.dir_mode = dir_mode;
+       g_object_notify (G_OBJECT (options), "dir-mode");
+}
+
+/**
+ * ggit_checkout_options_get_file_mode:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the default checkout file mode.
+ *
+ * Returns: the default checkout file mode.
+ *
+ **/
+guint
+ggit_checkout_options_get_file_mode (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
+
+       return (guint)options->priv->options.file_mode;
+}
+
+/**
+ * ggit_checkout_options_set_file_mode:
+ * @options: a #GgitCheckoutOptions.
+ * @file_mode: the file mode.
+ *
+ * Set the default checkout file mode.
+ *
+ **/
+void
+ggit_checkout_options_set_file_mode (GgitCheckoutOptions *options,
+                                     guint                file_mode)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       options->priv->options.file_mode = file_mode;
+       g_object_notify (G_OBJECT (options), "file-mode");
+}
+
+/**
+ * ggit_checkout_options_get_file_open_flags:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout file open flags. These flags are platform specific,
+ * e.g. on Unix these would include O_CREAT, O_TRUNC, etc.
+ *
+ * Returns: the checkout file open flags.
+ *
+ **/
+gint
+ggit_checkout_options_get_file_open_flags (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
+
+       return options->priv->options.file_open_flags;
+}
+
+/**
+ * ggit_checkout_options_set_file_open_flags:
+ * @options: a #GgitCheckoutOptions.
+ * @flags: the file open flags.
+ *
+ * Set the checkout file open flags. These flags are platform dependent,
+ * e.g. on Unix use O_CREAT, O_TRUNC, etc.
+ *
+ **/
+void
+ggit_checkout_options_set_file_open_flags (GgitCheckoutOptions *options,
+                                           gint                 flags)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       options->priv->options.file_open_flags = flags;
+       g_object_notify (G_OBJECT (options), "file-open-flags");
+}
+
+/**
+ * ggit_checkout_options_get_nofify_flags:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout notify flags.
+ *
+ * Returns: a #GgitCheckoutNotifyFlags.
+ *
+ **/
+GgitCheckoutNotifyFlags
+ggit_checkout_options_get_nofify_flags (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
+
+       return (GgitCheckoutNotifyFlags)options->priv->options.notify_flags;
+}
+
+/**
+ * ggit_checkout_options_set_notify_flags:
+ * @options: a #GgitCheckoutOptions.
+ * @flags: a #GgitCheckoutNotifyFlags.
+ *
+ * Set the checkout notify flags.
+ *
+ **/
+void
+ggit_checkout_options_set_notify_flags (GgitCheckoutOptions     *options,
+                                        GgitCheckoutNotifyFlags  flags)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       options->priv->options.notify_flags = flags;
+       g_object_notify (G_OBJECT (options), "notify-flags");
+}
+
+/**
+ * ggit_checkout_options_get_paths:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the list of file paths to checkout.
+ *
+ * Returns: (array zero-terminated=1) (allow-none): a %NULL terminated list of file paths, or %NULL.
+ *
+ **/
+const gchar * const *
+ggit_checkout_options_get_paths (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
+
+       return (const gchar * const *)options->priv->paths;
+}
+
+/**
+ * ggit_checkout_options_set_paths:
+ * @options: a #GgitCheckoutOptions.
+ * @paths: (array zero-terminated=1) (allow-none): a %NULL terminated list of paths.
+ *
+ * Set the list of file paths to checkout. If @paths is %NULL, then all files
+ * will be checked out.
+ *
+ **/
+void
+ggit_checkout_options_set_paths (GgitCheckoutOptions *options,
+                                 const gchar * const *paths)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       g_strfreev (options->priv->paths);
+
+       options->priv->paths = g_strdupv ((gchar **)paths);
+       options->priv->options.paths.strings = options->priv->paths;
+       options->priv->options.paths.count = g_strv_length (options->priv->paths);
+
+       g_object_notify (G_OBJECT (options), "paths");
+}
+
+/**
+ * ggit_checkout_options_get_baseline:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the baseline, i.e. the expected content of workdir. Defaults to HEAD.
+ *
+ * Returns: (transfer none): a #GgitTree.
+ *
+ **/
+GgitTree *
+ggit_checkout_options_get_baseline (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
+
+       return options->priv->baseline;
+}
+
+/**
+ * ggit_checkout_options_set_baseline:
+ * @options: a #GgitCheckoutOptions.
+ * @tree: (allow-none): a #GgitTree.
+ *
+ * Set the baseline, i.e. the expected content of workdir. If @tree is set
+ * to %NULL, the default (HEAD) will be used as the baseline.
+ *
+ **/
+void
+ggit_checkout_options_set_baseline (GgitCheckoutOptions *options,
+                                    GgitTree            *tree)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+       g_return_if_fail (tree == NULL || GGIT_IS_TREE (tree));
+
+       if (options->priv->baseline)
+       {
+               g_object_unref (options->priv->baseline);
+       }
+
+       if (tree)
+       {
+               options->priv->baseline = g_object_ref (tree);
+               options->priv->options.baseline = _ggit_native_get (tree);
+       }
+       else
+       {
+               options->priv->baseline = NULL;
+               options->priv->options.baseline = NULL;
+       }
+
+       g_object_notify (G_OBJECT (options), "baseline");
+}
+
+/**
+ * ggit_checkout_options_get_target_directory:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout target directory.
+ *
+ * Returns: (allow-none): the checkout target directory.
+ *
+ **/
+const gchar *
+ggit_checkout_options_get_target_directory (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
+
+       return options->priv->target_directory;
+}
+
+/**
+ * ggit_checkout_options_set_target_directory:
+ * @options: a #GgitCheckoutOptions.
+ * @directory: (allow-none): the target directory.
+ *
+ * Set the checkout target directory.
+ *
+ **/
+void
+ggit_checkout_options_set_target_directory (GgitCheckoutOptions *options,
+                                            const gchar         *directory)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       g_free (options->priv->target_directory);
+       options->priv->target_directory = g_strdup (directory);
+
+       options->priv->options.target_directory = options->priv->target_directory;
+
+       g_object_notify (G_OBJECT (options), "target-directory");
+}
+
+/**
+ * ggit_checkout_options_get_ancestor_label:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout ancestor label.
+ *
+ * Returns: (allow-none): the checkout ancestor label.
+ *
+ **/
+const gchar *
+ggit_checkout_options_get_ancestor_label (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
+
+       return options->priv->ancestor_label;
+}
+
+/**
+ * ggit_checkout_options_set_ancestor_label:
+ * @options: a #GgitCheckoutOptions.
+ * @label: (allow-none): the ancestor label.
+ *
+ * Set the checkout ancestor label.
+ *
+ **/
+void
+ggit_checkout_options_set_ancestor_label (GgitCheckoutOptions *options,
+                                          const gchar         *label)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       g_free (options->priv->ancestor_label);
+       options->priv->ancestor_label = g_strdup (label);
+
+       options->priv->options.ancestor_label = options->priv->ancestor_label;
+
+       g_object_notify (G_OBJECT (options), "ancestor-label");
+}
+
+/**
+ * ggit_checkout_options_get_our_label:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout our label.
+ *
+ * Returns: (allow-none): the checkout our label.
+ *
+ **/
+const gchar *
+ggit_checkout_options_get_our_label (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
+
+       return options->priv->our_label;
+}
+
+/**
+ * ggit_checkout_options_set_our_label:
+ * @options: a #GgitCheckoutOptions.
+ * @label: (allow-none): the our label.
+ *
+ * Set the checkout our label.
+ *
+ **/
+void
+ggit_checkout_options_set_our_label (GgitCheckoutOptions *options,
+                                     const gchar         *label)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       g_free (options->priv->our_label);
+       options->priv->our_label = g_strdup (label);
+
+       options->priv->options.our_label = options->priv->our_label;
+
+       g_object_notify (G_OBJECT (options), "our-label");
+}
+
+/**
+ * ggit_checkout_options_get_their_label:
+ * @options: a #GgitCheckoutOptions.
+ *
+ * Get the checkout their label.
+ *
+ * Returns: (allow-none): the checkout their label.
+ *
+ **/
+const gchar *
+ggit_checkout_options_get_their_label (GgitCheckoutOptions *options)
+{
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
+
+       return options->priv->their_label;
+}
+
+/**
+ * ggit_checkout_options_set_their_label:
+ * @options: a #GgitCheckoutOptions.
+ * @label: (allow-none): the their label.
+ *
+ * Set the checkout their label.
+ *
+ **/
+void
+ggit_checkout_options_set_their_label (GgitCheckoutOptions *options,
+                                       const gchar         *label)
+{
+       g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
+
+       g_free (options->priv->their_label);
+       options->priv->their_label = g_strdup (label);
+
+       options->priv->options.their_label = options->priv->their_label;
+
+       g_object_notify (G_OBJECT (options), "their-label");
+}
+
diff --git a/libgit2-glib/ggit-checkout-options.h b/libgit2-glib/ggit-checkout-options.h
new file mode 100644
index 0000000..a1cd1a7
--- /dev/null
+++ b/libgit2-glib/ggit-checkout-options.h
@@ -0,0 +1,141 @@
+/*
+ * ggit-checkout-options.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - 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_CHECKOUT_OPTIONS_H__
+#define __GGIT_CHECKOUT_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_CHECKOUT_OPTIONS             (ggit_checkout_options_get_type ())
+#define GGIT_CHECKOUT_OPTIONS(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GGIT_TYPE_CHECKOUT_OPTIONS, GgitCheckoutOptions))
+#define GGIT_CHECKOUT_OPTIONS_CONST(obj)       (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GGIT_TYPE_CHECKOUT_OPTIONS, GgitCheckoutOptions const))
+#define GGIT_CHECKOUT_OPTIONS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GGIT_TYPE_CHECKOUT_OPTIONS, GgitCheckoutOptionsClass))
+#define GGIT_IS_CHECKOUT_OPTIONS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GGIT_TYPE_CHECKOUT_OPTIONS))
+#define GGIT_IS_CHECKOUT_OPTIONS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GGIT_TYPE_CHECKOUT_OPTIONS))
+#define GGIT_CHECKOUT_OPTIONS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GGIT_TYPE_CHECKOUT_OPTIONS, GgitCheckoutOptionsClass))
+
+typedef struct _GgitCheckoutOptions            GgitCheckoutOptions;
+typedef struct _GgitCheckoutOptionsClass       GgitCheckoutOptionsClass;
+typedef struct _GgitCheckoutOptionsPrivate     GgitCheckoutOptionsPrivate;
+
+struct _GgitCheckoutOptions
+{
+       GObject parent;
+
+       GgitCheckoutOptionsPrivate *priv;
+};
+
+struct _GgitCheckoutOptionsClass
+{
+       GObjectClass parent_class;
+
+       gint (*notify)   (GgitCheckoutOptions     *options,
+                         GgitCheckoutNotifyFlags  why,
+                         const gchar             *path,
+                         GgitDiffFile            *baseline,
+                         GgitDiffFile            *target,
+                         GgitDiffFile            *workdir);
+
+       void (*progress) (GgitCheckoutOptions     *options,
+                         const gchar             *path,
+                         gsize                    completed_steps,
+                         gsize                    total_steps);
+};
+
+GType                  ggit_checkout_options_get_type (void) G_GNUC_CONST;
+
+const git_checkout_options *
+                      _ggit_checkout_options_get_checkout_options (
+                                                          GgitCheckoutOptions *options);
+
+GgitCheckoutOptions  *ggit_checkout_options_new          (void);
+
+GgitCheckoutStrategy  ggit_checkout_options_get_strategy  (GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_strategy  (GgitCheckoutOptions  *options,
+                                                           GgitCheckoutStrategy  strategy);
+
+gboolean              ggit_checkout_options_get_disable_filters (
+                                                           GgitCheckoutOptions  *options);
+
+void                  ggit_checkout_options_set_disable_filters (
+                                                           GgitCheckoutOptions  *options,
+                                                           gboolean              disable);
+
+guint                 ggit_checkout_options_get_dir_mode  (GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_dir_mode  (GgitCheckoutOptions  *options,
+                                                           guint                 dir_mode);
+
+guint                 ggit_checkout_options_get_file_mode (GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_file_mode (GgitCheckoutOptions  *options,
+                                                           guint                 file_mode);
+
+gint                  ggit_checkout_options_get_file_open_flags (
+                                                           GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_file_open_flags (
+                                                           GgitCheckoutOptions  *options,
+                                                           gint                 flags);
+
+GgitCheckoutNotifyFlags
+                      ggit_checkout_options_get_nofify_flags (
+                                                           GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_notify_flags (
+                                                           GgitCheckoutOptions  *options,
+                                                           GgitCheckoutNotifyFlags flags);
+
+const gchar * const  *ggit_checkout_options_get_paths     (GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_paths     (GgitCheckoutOptions  *options,
+                                                           const gchar * const  *paths);
+
+GgitTree             *ggit_checkout_options_get_baseline  (GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_baseline  (GgitCheckoutOptions  *options,
+                                                           GgitTree             *tree);
+
+const gchar          *ggit_checkout_options_get_target_directory (
+                                                           GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_target_directory (
+                                                           GgitCheckoutOptions  *options,
+                                                           const gchar          *directory);
+
+const gchar          *ggit_checkout_options_get_ancestor_label (
+                                                           GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_ancestor_label (
+                                                           GgitCheckoutOptions  *options,
+                                                           const gchar          *label);
+
+const gchar          *ggit_checkout_options_get_our_label (GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_our_label (GgitCheckoutOptions  *options,
+                                                           const gchar          *label);
+
+const gchar          *ggit_checkout_options_get_their_label (
+                                                           GgitCheckoutOptions  *options);
+void                  ggit_checkout_options_set_their_label (
+                                                           GgitCheckoutOptions  *options,
+                                                           const gchar          *label);
+
+G_END_DECLS
+
+#endif /* __GGIT_CHECKOUT_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 0442015..93e1650 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -2699,4 +2699,126 @@ ggit_repository_get_attribute (GgitRepository           *repository,
        return value;
 }
 
+/**
+ * ggit_repository_checkout_head:
+ * @repository: a #GgitRepository.
+ * @options: (allow-none): a #GgitCheckoutOptions or %NULL.
+ * @error: a #GError for error reporting or %NULL.
+ *
+ * Update files in the working tree to reflect the contents of current HEAD. If
+ * @options is %NULL, then the default checkout options will be used.
+ *
+ * If the checkout was not successfull, then @error will be set.
+ *
+ * Returns: %TRUE if the checkout was successfull, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_repository_checkout_head (GgitRepository       *repository,
+                               GgitCheckoutOptions  *options,
+                               GError              **error)
+{
+       gint ret;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       ret = git_checkout_head (_ggit_native_get (repository),
+                                _ggit_checkout_options_get_checkout_options (options));
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+/**
+ * ggit_repository_checkout_index:
+ * @repository: a #GgitRepository.
+ * @index: (allow-none): a #GgitIndex or %NULL.
+ * @options: (allow-none): a #GgitCheckoutOptions or %NULL.
+ * @error: a #GError for error reporting or %NULL.
+ *
+ * Update files in the working tree to reflect the contents of the index. If
+ * @index is %NULL, then the current index of the repository will be used. If
+ * @options is %NULL, then the default checkout options will be used.
+ *
+ * If the checkout was not successfull, then @error will be set.
+ *
+ * Returns: %TRUE if the checkout was successfull, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_repository_checkout_index (GgitRepository       *repository,
+                                GgitIndex            *index,
+                                GgitCheckoutOptions  *options,
+                                GError              **error)
+{
+       gint ret;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (index == NULL || GGIT_IS_INDEX (index), FALSE);
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       ret = git_checkout_index (_ggit_native_get (repository),
+                                 index != NULL ? _ggit_index_get_index (index) : NULL,
+                                _ggit_checkout_options_get_checkout_options (options));
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+/**
+ * ggit_repository_checkout_tree:
+ * @repository: a #GgitRepository.
+ * @tree: (allow-none): a #GgitObject or %NULL.
+ * @options: (allow-none): a #GgitCheckoutOptions or %NULL.
+ * @error: a #GError for error reporting or %NULL.
+ *
+ * Update files in the working tree to reflect the contents of the specified
+ * commit, tag or tree object. If @tree is %NULL, then the current HEAD of the
+ * repository will be used. If @options is %NULL, then the default checkout
+ * options will be used.
+ *
+ * If the checkout was not successfull, then @error will be set.
+ *
+ * Returns: %TRUE if the checkout was successfull, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_repository_checkout_tree (GgitRepository       *repository,
+                               GgitObject           *tree,
+                               GgitCheckoutOptions  *options,
+                               GError              **error)
+{
+       gint ret;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (tree == NULL || GGIT_IS_OBJECT (tree), FALSE);
+       g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       ret = git_checkout_tree (_ggit_native_get (repository),
+                                tree != NULL ? _ggit_native_get (tree) : NULL,
+                                _ggit_checkout_options_get_checkout_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 3b3bab0..6a6bf86 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -33,6 +33,7 @@
 #include <libgit2-glib/ggit-tree.h>
 #include <libgit2-glib/ggit-branch.h>
 #include <libgit2-glib/ggit-blob-output-stream.h>
+#include <libgit2-glib/ggit-checkout-options.h>
 
 G_BEGIN_DECLS
 
@@ -350,6 +351,20 @@ const gchar        *ggit_repository_get_attribute     (GgitRepository
                                                        GgitAttributeCheckFlags   flags,
                                                        GError                  **error);
 
+gboolean            ggit_repository_checkout_head     (GgitRepository           *repository,
+                                                       GgitCheckoutOptions      *options,
+                                                       GError                  **error);
+
+gboolean            ggit_repository_checkout_index    (GgitRepository           *repository,
+                                                       GgitIndex                *index,
+                                                       GgitCheckoutOptions      *options,
+                                                       GError                  **error);
+
+gboolean            ggit_repository_checkout_tree     (GgitRepository           *repository,
+                                                       GgitObject               *tree,
+                                                       GgitCheckoutOptions      *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 4f2a4b3..a5ca9ac 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -955,6 +955,39 @@ typedef enum
        GGIT_PACKBUILDER_STAGE_DELTAFICATION  = 1
 } GgitPackbuilderStage;
 
+typedef enum
+{
+       GGIT_CHECKOUT_NONE                    = 0,
+       GGIT_CHECKOUT_SAFE                    = (1u << 0),
+       GGIT_CHECKOUT_SAFE_CREATE             = (1u << 1),
+       GGIT_CHECKOUT_FORCE                   = (1u << 2),
+       GGIT_CHECKOUT_ALLOW_CONFLICTS         = (1u << 4),
+       GGIT_CHECKOUT_REMOVE_UNTRACKED        = (1u << 5),
+       GGIT_CHECKOUT_REMOVE_IGNORED          = (1u << 6),
+       GGIT_CHECKOUT_UPDATE_ONLY             = (1u << 7),
+       GGIT_CHECKOUT_DONT_UPDATE_INDEX       = (1u << 8),
+       GGIT_CHECKOUT_NO_REFRESH              = (1u << 9),
+       GGIT_CHECKOUT_SKIP_UNMERGED           = (1u << 10),
+       GGIT_CHECKOUT_USE_OURS                = (1u << 11),
+       GGIT_CHECKOUT_USE_THEIRS              = (1u << 12),
+       GGIT_CHECKOUT_DISABLE_PATHSPEC_MATCH  = (1u << 13),
+       GGIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = (1u << 18),
+       GGIT_CHECKOUT_DONT_OVERWRITE_IGNORED  = (1u << 19),
+       GGIT_CHECKOUT_CONFLICT_STYLE_MERGE    = (1u << 20),
+       GGIT_CHECKOUT_CONFLICT_STYLE_DIFF3    = (1u << 21)
+} GgitCheckoutStrategy;
+
+typedef enum {
+       GGIT_CHECKOUT_NOTIFY_NONE      = 0,
+       GGIT_CHECKOUT_NOTIFY_CONFLICT  = (1u << 0),
+       GGIT_CHECKOUT_NOTIFY_DIRTY     = (1u << 1),
+       GGIT_CHECKOUT_NOTIFY_UPDATED   = (1u << 2),
+       GGIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3),
+       GGIT_CHECKOUT_NOTIFY_IGNORED   = (1u << 4),
+
+       GGIT_CHECKOUT_NOTIFY_ALL       = 0x0FFFFu
+} GgitCheckoutNotifyFlags;
+
 /**
  * GgitConfigCallback:
  * @entry: a #GgitConfigEntry.



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