[libgit2-glib] Added ggit_repository_tag_foreach



commit b34ba62a1ebb4e97cd6ac3c007006cad6401bddc
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Tue Jun 24 18:14:37 2014 +0200

    Added ggit_repository_tag_foreach

 libgit2-glib/ggit-repository.c |   66 ++++++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-repository.h |    5 +++
 libgit2-glib/ggit-types.h      |   15 +++++++++
 3 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 76c4fab..19bb250 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -1449,6 +1449,72 @@ ggit_repository_delete_tag (GgitRepository  *repository,
        }
 }
 
+typedef struct
+{
+       gpointer user_data;
+
+       GgitTagCallback callback;
+} TagCallbackWrapperData;
+
+static gint
+tag_callback_wrapper (const gchar *name,
+                      git_oid     *tag_oid,
+                      gpointer     user_data)
+{
+       TagCallbackWrapperData *wrapper_data = (TagCallbackWrapperData *)user_data;
+       GgitOId *oid;
+       gint ret;
+
+       oid = _ggit_oid_wrap (tag_oid);
+
+       ret = wrapper_data->callback (name, oid, wrapper_data->user_data);
+       ggit_oid_free (oid);
+
+       return ret;
+}
+
+/**
+ * ggit_repository_tag_foreach:
+ * @repository: a #GgitRepository.
+ * @callback: (scope call): a #GgitTagCallback.
+ * @user_data: callback user data.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Get all the tags in the repository and run the provided callback on each. If
+ * the callback returns something other than 0, the iteration will stop and
+ * @error will be set.
+ *
+ * Returns: %TRUE if there was no error, %FALSE otherwise
+ **/
+gboolean
+ggit_repository_tag_foreach (GgitRepository   *repository,
+                             GgitTagCallback   callback,
+                             gpointer          user_data,
+                             GError          **error)
+{
+       TagCallbackWrapperData wrapper_data;
+       gint ret;
+
+       g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+       g_return_val_if_fail (callback != NULL, FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       wrapper_data.user_data = user_data;
+       wrapper_data.callback = callback;
+
+       ret = git_tag_foreach (_ggit_native_get (repository),
+                              tag_callback_wrapper,
+                              &wrapper_data);
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 /**
  * ggit_repository_create_branch:
  * @repository: a #GgitRepository.
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 48a87d1..e4cb0c9 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -185,6 +185,11 @@ gboolean            ggit_repository_delete_tag        (GgitRepository        *re
                                                        const gchar           *name,
                                                        GError               **error);
 
+gboolean            ggit_repository_tag_foreach       (GgitRepository        *repository,
+                                                       GgitTagCallback        callback,
+                                                       gpointer               user_data,
+                                                       GError               **error);
+
 GgitTreeBuilder    *ggit_repository_create_tree_builder_from_tree (
                                                        GgitRepository        *repository,
                                                        GgitTree              *tree,
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 572d676..4f2a4b3 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -1150,6 +1150,21 @@ typedef gint (* GgitSubmoduleCallback) (GgitSubmodule *submodule,
                                         gpointer       user_data);
 
 /**
+ * GgitTagCallback:
+ * @name: the tag name.
+ * @tag_oid: the tag oid.
+ * @user_data: (closure): user-suplied data.
+ *
+ * When iterating over all the tags, callback that will be
+ * issued per entry. See ggit_repository_tag_foreach().
+ *
+ * Returns: 0 to go continue or a #GgitError in case there was an error.
+ */
+typedef gint (* GgitTagCallback) (const gchar *name,
+                                  GgitOId     *tag_oid,
+                                  gpointer    *user_data);
+
+/**
  * GgitTransferProgressCallback:
  * @stats: a #GgitTransferProgress.
  * @user_data: (closure): user-supplied data.


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