[libgit2-glib] Add lookup functions for blob, commit, tag, and tree



commit 3399daa68cdf1b8c9d8ef7b43578f7274630741d
Author: Brian C. Lane <bcl redhat com>
Date:   Thu Aug 3 11:45:01 2017 -0700

    Add lookup functions for blob, commit, tag, and tree

 libgit2-glib/ggit-repository.c |  146 ++++++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-repository.h |   18 +++++
 2 files changed, 164 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index c295c67..f310844 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -43,6 +43,8 @@
 #include "ggit-index-entry.h"
 #include "ggit-annotated-commit.h"
 #include "ggit-rebase-options.h"
+#include "ggit-blob.h"
+#include "ggit-tag.h"
 
 
 typedef struct _GgitRepositoryPrivate
@@ -1937,6 +1939,150 @@ ggit_repository_lookup_branch (GgitRepository *repository,
 }
 
 /**
+ * ggit_repository_lookup_blob:
+ * @repository: a #GgitRepository.
+ * @oid: a #GgitOId.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Lookups a branch by its name in a repository.
+ *
+ * Returns: (transfer full) (allow-none): a #GgitBlog pointer.
+ */
+GgitBlob *
+ggit_repository_lookup_blob (GgitRepository *repository,
+                             GgitOId        *oid,
+                             GError         **error)
+{
+       gint ret;
+       git_blob *blob;
+       const git_oid *id;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       id = (const git_oid *)_ggit_oid_get_oid (oid);
+       ret = git_blob_lookup (&blob,
+                              _ggit_native_get (repository),
+                              id);
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return NULL;
+       }
+
+       return _ggit_blob_wrap (blob, TRUE);
+}
+
+/**
+ * ggit_repository_lookup_commit:
+ * @repository: a #GgitRepository.
+ * @oid: a #GgitOId.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Lookups a branch by its name in a repository.
+ *
+ * Returns: (transfer full) (allow-none): a #GgitCommit pointer.
+ */
+GgitCommit *
+ggit_repository_lookup_commit (GgitRepository *repository,
+                               GgitOId        *oid,
+                               GError         **error)
+{
+       gint ret;
+       git_commit *commit;
+       const git_oid *id;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       id = (const git_oid *)_ggit_oid_get_oid (oid);
+       ret = git_commit_lookup (&commit,
+                                _ggit_native_get (repository),
+                                id);
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return NULL;
+       }
+
+       return _ggit_commit_wrap (commit, TRUE);
+}
+
+/**
+ * ggit_repository_lookup_tag:
+ * @repository: a #GgitRepository.
+ * @oid: a #GgitOId.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Lookups a branch by its name in a repository.
+ *
+ * Returns: (transfer full) (allow-none): a #GgitTag pointer.
+ */
+GgitTag *
+ggit_repository_lookup_tag (GgitRepository *repository,
+                            GgitOId        *oid,
+                            GError         **error)
+{
+       gint ret;
+       git_tag *tag;
+       const git_oid *id;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       id = (const git_oid *)_ggit_oid_get_oid (oid);
+       ret = git_tag_lookup (&tag,
+                             _ggit_native_get (repository),
+                             id);
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return NULL;
+       }
+
+       return _ggit_tag_wrap (tag, TRUE);
+}
+
+/**
+ * ggit_repository_lookup_tree:
+ * @repository: a #GgitRepository.
+ * @oid: a #GgitOId.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Lookups a branch by its name in a repository.
+ *
+ * Returns: (transfer full) (allow-none): a #GgitTree pointer.
+ */
+GgitTree *
+ggit_repository_lookup_tree (GgitRepository *repository,
+                             GgitOId        *oid,
+                             GError         **error)
+{
+       gint ret;
+       git_tree *tree;
+       const git_oid *id;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       id = (const git_oid *)_ggit_oid_get_oid (oid);
+       ret = git_tree_lookup (&tree,
+                              _ggit_native_get (repository),
+                              id);
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return NULL;
+       }
+
+       return _ggit_tree_wrap (tree, TRUE);
+}
+
+/**
  * ggit_repository_lookup_remote:
  * @repository: a #GgitRepository.
  * @name: the remote's name.
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 9cdb09c..06ad116 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -41,6 +41,8 @@
 #include <libgit2-glib/ggit-tree-builder.h>
 #include <libgit2-glib/ggit-remote.h>
 #include <libgit2-glib/ggit-rebase.h>
+#include <libgit2-glib/ggit-blob.h>
+#include <libgit2-glib/ggit-tag.h>
 
 G_BEGIN_DECLS
 
@@ -240,6 +242,22 @@ GgitBranch         *ggit_repository_lookup_branch     (GgitRepository        *re
                                                        GgitBranchType         branch_type,
                                                        GError               **error);
 
+GgitBlob           *ggit_repository_lookup_blob       (GgitRepository        *repository,
+                                                       GgitOId               *oid,
+                                                             GError         **error);
+
+GgitCommit         *ggit_repository_lookup_commit     (GgitRepository        *repository,
+                                                       GgitOId               *oid,
+                                                       GError               **error);
+
+GgitTag            *ggit_repository_lookup_tag        (GgitRepository        *repository,
+                                                       GgitOId               *oid,
+                                                       GError               **error);
+
+GgitTree           *ggit_repository_lookup_tree       (GgitRepository        *repository,
+                                                       GgitOId               *oid,
+                                                       GError               **error);
+
 GgitRemote         *ggit_repository_lookup_remote     (GgitRepository        *repository,
                                                        const gchar           *name,
                                                        GError               **error);


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