[libgit2-glib] Add git_repository_merge_base



commit f7e1a4f0063faa6916e964c0d7ad72423c53375a
Author: Alan Knowles <alan roojs com>
Date:   Fri Mar 15 11:25:20 2019 +0800

    Add git_repository_merge_base
    
    Finds the ancestry for two commits

 libgit2-glib/ggit-repository.c | 40 ++++++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-repository.h |  5 +++++
 2 files changed, 45 insertions(+)
---
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index fa7af84..d482ea9 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -3901,6 +3901,46 @@ ggit_repository_note_foreach (GgitRepository    *repository,
        return TRUE;
 }
 
+/**
+ * ggit_repository_merge_base:
+ * @repository: a #GgitRepository.
+ * @oid_one: the oid of one of the commits.
+ * @oid_two: the oid of the second of the commits
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Find the merge base between two commits
+ *
+ * Returns: (transfer full) (nullable): a new #GgitOId or %NULL if an error occurred.
+ *
+ */
+GgitOId *
+ggit_repository_merge_base (GgitRepository  *repository,
+                            GgitOId         *oid_one,
+                            GgitOId         *oid_two,
+                            GError         **error)
+{
+       git_oid oid;
+       gint ret;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), NULL);
+       g_return_val_if_fail (oid_one != NULL, NULL);
+       g_return_val_if_fail (oid_two != NULL, NULL);
+       g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+       ret = git_merge_base (&oid,
+                             _ggit_native_get (repository),
+                             _ggit_oid_get_oid (oid_one),
+                             _ggit_oid_get_oid (oid_two));
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return NULL;
+       }
+
+       return _ggit_oid_wrap (&oid);
+}
+
 /**
  * ggit_repository_merge_trees:
  * @repository: a #GgitRepository.
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 06ad116..e344c23 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -491,6 +491,11 @@ gboolean            ggit_repository_path_is_ignored    (GgitRepository
                                                         const gchar             *path,
                                                         GError                 **error);
 
+GgitOId            *ggit_repository_merge_base         (GgitRepository          *repository,
+                                                        GgitOId                 *oid_one,
+                                                        GgitOId                 *oid_two,
+                                                        GError                 **error);
+
 GgitIndex          *ggit_repository_merge_trees        (GgitRepository          *repository,
                                                         GgitTree                *ancestor_tree,
                                                         GgitTree                *our_tree,


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