[libgit2-glib] Bind ggit_repository_references_foreach



commit fa96be63be40e059dceb4e7ffa327e8c93e077b4
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Wed Aug 12 08:51:36 2015 +0200

    Bind ggit_repository_references_foreach

 libgit2-glib/ggit-ref.c        |    6 ----
 libgit2-glib/ggit-repository.c |   62 +++++++++++++++++++++++++++++++++++++++-
 libgit2-glib/ggit-repository.h |    5 +++
 libgit2-glib/ggit-types.h      |   20 +++++++++++++
 4 files changed, 86 insertions(+), 7 deletions(-)
---
diff --git a/libgit2-glib/ggit-ref.c b/libgit2-glib/ggit-ref.c
index cc4ccfa..a4cdfd6 100644
--- a/libgit2-glib/ggit-ref.c
+++ b/libgit2-glib/ggit-ref.c
@@ -31,12 +31,6 @@
 
 /* FIXME: we should have a ref superclass and direct and symbolic subclasses */
 
-/**
- * GgitRef:
- *
- * Reprensents a git reference.
- */
-
 G_DEFINE_TYPE (GgitRef, ggit_ref, GGIT_TYPE_NATIVE)
 
 static void
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 3bbbf75..e1dfffe 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -1246,6 +1246,66 @@ ggit_repository_file_status_foreach (GgitRepository     *repository,
        return TRUE;
 }
 
+typedef struct
+{
+       GgitReferencesCallback callback;
+       gpointer user_data;
+} ReferenceForeachInfo;
+
+static gint
+references_foreach_wrapper (git_reference *reference,
+                            gpointer       payload)
+{
+       ReferenceForeachInfo *info = (ReferenceForeachInfo *)payload;
+
+       return info->callback(_ggit_ref_wrap (reference, TRUE), info->user_data);
+}
+
+/**
+ * ggit_repository_references_foreach:
+ * @repository: a #GgitRepository.
+ * @callback: (scope call): a #GgitReferencesCallback.
+ * @user_data: callback user data.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Gathers references and run a callback for each one.
+ *
+ * To the callback is passed the reference and the data pointer
+ * passed to this function. 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_references_foreach (GgitRepository          *repository,
+                                    GgitReferencesCallback   callback,
+                                    gpointer                 user_data,
+                                    GError                 **error)
+{
+       gint ret;
+       ReferenceForeachInfo info;
+
+       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);
+
+       info.callback = callback;
+       info.user_data = user_data;
+
+       ret = git_reference_foreach (_ggit_native_get (repository),
+                                    references_foreach_wrapper,
+                                    &info);
+
+       if (ret != GIT_OK)
+       {
+               _ggit_error_set (error, ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 /**
  * ggit_repository_references_foreach_name:
  * @repository: a #GgitRepository.
@@ -1253,7 +1313,7 @@ ggit_repository_file_status_foreach (GgitRepository     *repository,
  * @user_data: callback user data.
  * @error: a #GError for error reporting, or %NULL.
  *
- * Gathers references and run a callback for each one.
+ * Gathers reference names and run a callback for each one.
  *
  * To the callback is passed the name of the reference and the data pointer
  * passed to this function. If the callback returns something other than
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index e38459d..610eca8 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -300,6 +300,11 @@ gboolean            ggit_repository_file_status_foreach
                                                       gpointer                user_data,
                                                       GError                **error);
 
+gboolean            ggit_repository_references_foreach (GgitRepository             *repository,
+                                                        GgitReferencesCallback      callback,
+                                                        gpointer                    user_data,
+                                                        GError                    **error);
+
 gboolean            ggit_repository_references_foreach_name (GgitRepository             *repository,
                                                              GgitReferencesNameCallback  callback,
                                                              gpointer                    user_data,
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 9061e1f..b01a988 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -173,6 +173,13 @@ typedef struct _GgitOId GgitOId;
 typedef struct _GgitPatch GgitPatch;
 
 /**
+ * GgitRef:
+ *
+ * Reprensents a git reference.
+ */
+typedef struct _GgitRef GgitRef;
+
+/**
  * GgitRefSpec:
  *
  * Reprensents a git reference specification.
@@ -1119,6 +1126,19 @@ typedef gint (* GgitReferencesNameCallback) (const gchar *name,
                                              gpointer     user_data);
 
 /**
+ * GgitReferencesCallback:
+ * @reference: (transfer full): the reference.
+ * @user_data: (closure): user-supplied data.
+ *
+ * The type of the callback functions for retrieving the references
+ * in a #GgitRepository. See ggit_repository_references_foreach().
+ *
+ * Returns: 0 to go for the next references or a #GgitError in case there was an error.
+ */
+typedef gint (* GgitReferencesCallback) (GgitRef  *reference,
+                                         gpointer  user_data);
+
+/**
  * GgitRemoteListCallback:
  * @name: the name of the reference.
  * @oid: the reference's oid.


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