[libgit2-glib] Add ggit_repository_merge
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Add ggit_repository_merge
- Date: Tue, 23 Apr 2019 18:29:28 +0000 (UTC)
commit a86eaca585d10dc909ba4b6f2646d81fea93767b
Author: Alan Knowles <alan roojs com>
Date: Fri Mar 15 17:06:43 2019 +0800
Add ggit_repository_merge
libgit2-glib/ggit-annotated-commit.c | 35 +++++++++++++++++++++++++
libgit2-glib/ggit-annotated-commit.h | 6 +++++
libgit2-glib/ggit-repository.c | 50 ++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-repository.h | 7 +++++
4 files changed, 98 insertions(+)
---
diff --git a/libgit2-glib/ggit-annotated-commit.c b/libgit2-glib/ggit-annotated-commit.c
index 14ee4ea..ab8f777 100644
--- a/libgit2-glib/ggit-annotated-commit.c
+++ b/libgit2-glib/ggit-annotated-commit.c
@@ -109,4 +109,39 @@ ggit_annotated_commit_get_id (GgitAnnotatedCommit *annotated_commit)
return _ggit_oid_wrap ((git_oid *)oid);
}
+
+/**
+ * ggit_annotated_commit_new_from_ref:
+ * @repository: the repository
+ * @repository: the reference to use to lookup the git_annotated_commit
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Create a GgitAnnotatedCommit from the given reference
+ *
+ * Returns: (transfer full): a #GgitAnnotatedCommit.
+ *
+ */
+GgitAnnotatedCommit *
+ggit_annotated_commit_new_from_ref (GgitRepository *repository,
+ GgitRef *ref,
+ GError **error)
+{
+ gint ret;
+ git_annotated_commit *commit;
+
+ g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), NULL);
+ g_return_val_if_fail (ref != NULL, NULL);
+
+ ret = git_annotated_commit_from_ref(&commit,
+ _ggit_native_get (repository),
+ _ggit_native_get (ref));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+ return _ggit_annotated_commit_wrap (commit);
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-annotated-commit.h b/libgit2-glib/ggit-annotated-commit.h
index ecceced..bf2225b 100644
--- a/libgit2-glib/ggit-annotated-commit.h
+++ b/libgit2-glib/ggit-annotated-commit.h
@@ -26,6 +26,8 @@
#include <git2.h>
#include "ggit-types.h"
+#include "ggit-repository.h"
+#include "ggit-error.h"
G_BEGIN_DECLS
@@ -43,6 +45,10 @@ void ggit_annotated_commit_unref (
GgitOId *ggit_annotated_commit_get_id (GgitAnnotatedCommit
*annotated_commit);
+GgitAnnotatedCommit *ggit_annotated_commit_new_from_ref (GgitRepository
*repository,
+ GgitRef *ref,
+ GError
**error);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitAnnotatedCommit, ggit_annotated_commit_unref)
G_END_DECLS
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index d482ea9..42490f4 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -3901,6 +3901,56 @@ ggit_repository_note_foreach (GgitRepository *repository,
return TRUE;
}
+/**
+ * ggit_repository_merge:
+ * @repository: a #GgitRepository.
+ * @their_heads: (array length=their_heads_length): the heads to merge into
+ * @their_heads_length: the length of their_heads
+ * @merge_opts: merge options
+ * @checkout_opts: checkout options
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Merges the given commit(s) into HEAD, writing the results into the working directory.
+ * Any changes are staged for commit and any conflicts are written to the index.
+ *
+ * Callers should inspect the repository's index after this completes, resolve any conflicts and prepare a
commit.
+ */
+void
+ggit_repository_merge (GgitRepository *repository,
+ GgitAnnotatedCommit **their_heads,
+ gsize *their_heads_length,
+ GgitMergeOptions *merge_opts,
+ GgitCheckoutOptions *checkout_opts,
+ GError **error)
+{
+ gint ret, i;
+ git_annotated_commit **their_heads_native;
+
+ g_return_if_fail (GGIT_IS_REPOSITORY (repository));
+ g_return_if_fail (their_heads != NULL);
+ g_return_if_fail (their_heads_length > 0);
+ g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (checkout_opts));
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ their_heads_native = g_new0 (git_annotated_commit *, their_heads_length);
+
+ for (i = 0; i < their_heads_length; ++i)
+ {
+ their_heads_native[i] = _ggit_annotated_commit_get_annotated_commit (their_heads[i]);
+ }
+
+ ret = git_merge (_ggit_native_get (repository),
+ their_heads_native,
+ their_heads_length,
+ _ggit_merge_options_get_merge_options(merge_opts),
+ _ggit_checkout_options_get_checkout_options(checkout_opts));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
/**
* ggit_repository_merge_base:
* @repository: a #GgitRepository.
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index e344c23..89a8612 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -491,6 +491,13 @@ gboolean ggit_repository_path_is_ignored (GgitRepository
const gchar *path,
GError **error);
+void ggit_repository_merge (GgitRepository *repository,
+ GgitAnnotatedCommit **their_heads,
+ gsize *their_heads_length,
+ GgitMergeOptions *merge_opts,
+ GgitCheckoutOptions *checkout_opts,
+ GError **error);
+
GgitOId *ggit_repository_merge_base (GgitRepository *repository,
GgitOId *oid_one,
GgitOId *oid_two,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]