[libgit2-glib] Added ggit_repository_revert
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added ggit_repository_revert
- Date: Wed, 25 Jun 2014 08:21:32 +0000 (UTC)
commit d549c3e9bdfa2dfa8458410396849f8e2e7243e5
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Wed Jun 25 10:21:14 2014 +0200
Added ggit_repository_revert
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-repository.c | 38 ++++++++++
libgit2-glib/ggit-repository.h | 5 ++
libgit2-glib/ggit-revert-options.c | 137 ++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-revert-options.h | 52 ++++++++++++++
libgit2-glib/ggit-types.h | 7 ++
6 files changed, 241 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 23a479b..c9c7861 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -60,6 +60,7 @@ INST_H_FILES = \
ggit-remote.h \
ggit-remote-callbacks.h \
ggit-repository.h \
+ ggit-revert-options.h \
ggit-revision-walker.h \
ggit-signature.h \
ggit-status-options.h \
@@ -120,6 +121,7 @@ C_FILES = \
ggit-remote.c \
ggit-remote-callbacks.c \
ggit-repository.c \
+ ggit-revert-options.c \
ggit-revision-walker.c \
ggit-signature.c \
ggit-status-options.c \
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 93e1650..c38ef0f 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -36,6 +36,8 @@
#include "ggit-branch-enumerator.h"
#include "ggit-blame.h"
#include "ggit-blame-options.h"
+#include "ggit-commit.h"
+#include "ggit-revert-options.h"
#define GGIT_REPOSITORY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_REPOSITORY,
GgitRepositoryPrivate))
@@ -2820,5 +2822,41 @@ ggit_repository_checkout_tree (GgitRepository *repository,
return TRUE;
}
+/**
+ * ggit_repository_revert:
+ * @repository: a #GgitRepository.
+ * @commit: a #GgitCommit.
+ * @options: a #GgitRevertOptions.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Revert the given @commit on top of the current working directory.
+ *
+ * Returns: %TRUE if the revert was successfull, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_repository_revert (GgitRepository *repository,
+ GgitCommit *commit,
+ GgitRevertOptions *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 (error == NULL || *error == NULL, FALSE);
+
+ ret = git_revert (_ggit_native_get (repository),
+ _ggit_native_get (commit),
+ options ? _ggit_revert_options_get_revert_options (options) : NULL);
+
+ 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 6a6bf86..4db326c 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -365,6 +365,11 @@ gboolean ggit_repository_checkout_tree (GgitRepository
GgitCheckoutOptions *options,
GError **error);
+gboolean ggit_repository_revert (GgitRepository *repository,
+ GgitCommit *commit,
+ GgitRevertOptions *options,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_REPOSITORY_H__ */
diff --git a/libgit2-glib/ggit-revert-options.c b/libgit2-glib/ggit-revert-options.c
new file mode 100644
index 0000000..9559a62
--- /dev/null
+++ b/libgit2-glib/ggit-revert-options.c
@@ -0,0 +1,137 @@
+/*
+ * ggit-revert-options.c
+ * 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/>.
+ */
+
+#include "ggit-revert-options.h"
+#include "ggit-merge-options.h"
+#include "ggit-checkout-options.h"
+
+struct _GgitRevertOptions
+{
+ git_revert_options revert_options;
+
+ GgitMergeOptions *merge_options;
+ GgitCheckoutOptions *checkout_options;
+};
+
+G_DEFINE_BOXED_TYPE (GgitRevertOptions, ggit_revert_options,
+ ggit_revert_options_copy, ggit_revert_options_free)
+
+const git_revert_options *
+_ggit_revert_options_get_revert_options (GgitRevertOptions *revert_options)
+{
+ /* NULL is common for revert_options as it specifies to use the default
+ * so handle a NULL revert_options here instead of in every caller.
+ */
+ if (revert_options == NULL)
+ {
+ return NULL;
+ }
+
+ return (const git_revert_options *)&revert_options->revert_options;
+}
+
+/**
+ * ggit_revert_options_copy:
+ * @revert_options: a #GgitRevertOptions.
+ *
+ * Copies @revert_options into a newly allocated #GgitRevertOptions.
+ *
+ * Returns: (transfer full): a newly allocated #GgitRevertOptions.
+ */
+GgitRevertOptions *
+ggit_revert_options_copy (GgitRevertOptions *revert_options)
+{
+ g_return_val_if_fail (revert_options != NULL, NULL);
+
+ return ggit_revert_options_new (revert_options->revert_options.mainline,
+ revert_options->merge_options,
+ revert_options->checkout_options);
+}
+
+/**
+ * ggit_revert_options_free:
+ * @revert_options: a #GgitRevertOptions.
+ *
+ * Frees @revert_options.
+ */
+void
+ggit_revert_options_free (GgitRevertOptions *revert_options)
+{
+ g_return_if_fail (revert_options != NULL);
+
+ if (revert_options->merge_options)
+ {
+ ggit_merge_options_free (revert_options->merge_options);
+ }
+
+ g_clear_object (&revert_options->checkout_options);
+
+ g_slice_free (GgitRevertOptions, revert_options);
+}
+
+/**
+ * ggit_revert_options_new:
+ * @mainline: the mainline.
+ * @merge_options: (allow-none): a #GgitMergeOptions.
+ * @checkout_options: (allow-none): a #GgitCheckoutOptions.
+ *
+ * Create a new #GgitRevertOptions. Note that the passed in @merge_options and
+ * @checkout_options are copied by this function, and alterations in either
+ * after this call are therefore not reflected in the revert options.
+ *
+ * The @mainline indicates which parent to use for the revert when reverting
+ * a merge commit.
+ *
+ * Returns: (transfer full): a #GgitRevertOptions.
+ *
+ **/
+GgitRevertOptions *
+ggit_revert_options_new (guint mainline,
+ GgitMergeOptions *merge_options,
+ GgitCheckoutOptions *checkout_options)
+{
+ GgitRevertOptions *ret;
+
+ g_return_val_if_fail (checkout_options == NULL || GGIT_IS_CHECKOUT_OPTIONS (checkout_options), NULL);
+
+ ret = g_slice_new0 (GgitRevertOptions);
+
+ git_revert_init_options (&ret->revert_options, GIT_REVERT_OPTIONS_VERSION);
+
+ if (merge_options)
+ {
+ ret->merge_options = ggit_merge_options_copy (merge_options);
+ ret->revert_options.merge_opts =
+ *_ggit_merge_options_get_merge_options (ret->merge_options);
+
+ }
+
+ if (checkout_options)
+ {
+ ret->checkout_options = g_object_ref (checkout_options);
+ ret->revert_options.checkout_opts =
+ *_ggit_checkout_options_get_checkout_options (ret->checkout_options);
+ }
+
+ ret->revert_options.mainline = mainline;
+ return ret;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-revert-options.h b/libgit2-glib/ggit-revert-options.h
new file mode 100644
index 0000000..8fa938d
--- /dev/null
+++ b/libgit2-glib/ggit-revert-options.h
@@ -0,0 +1,52 @@
+/*
+ * ggit-revert-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_REVERT_OPTIONS_H__
+#define __GGIT_REVERT_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_REVERT_OPTIONS (ggit_revert_options_get_type ())
+#define GGIT_REVERT_OPTIONS(obj) ((GgitRevertOptions *)obj)
+
+GType ggit_revert_options_get_type (void) G_GNUC_CONST;
+
+const git_revert_options *
+ _ggit_revert_options_get_revert_options (
+ GgitRevertOptions *revert_options);
+
+GgitRevertOptions *ggit_revert_options_copy (GgitRevertOptions *revert_options);
+void ggit_revert_options_free (GgitRevertOptions *revert_options);
+
+GgitRevertOptions *ggit_revert_options_new (guint mainline,
+ GgitMergeOptions *merge_options,
+ GgitCheckoutOptions *checkout_options);
+
+G_END_DECLS
+
+#endif /* __GGIT_REVERT_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index d5e0d29..254a161 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -391,6 +391,13 @@ typedef struct _GgitBlameOptions GgitBlameOptions;
typedef struct _GgitCheckoutOptions GgitCheckoutOptions;
/**
+ * GgitRevertOptions:
+ *
+ * Represents the options used when reverting.
+ */
+typedef struct _GgitRevertOptions GgitRevertOptions;
+
+/**
* GgitBranchType:
* @GGIT_BRANCH_LOCAL: specifies a local branch.
* @GGIT_BRANCH_REMOTE: specifies a remote branch.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]