[libgit2-glib] Fix submodule_foreach



commit 8e98e3e4a4e1df8723440efe16e995c25cc38e5a
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Oct 30 16:41:25 2012 +0100

    Fix submodule_foreach

 libgit2-glib/ggit-repository.c |   35 ++++++++++++++++++++++++++++++-----
 libgit2-glib/ggit-types.h      |    6 ++++--
 2 files changed, 34 insertions(+), 7 deletions(-)
---
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 39f58c9..c958ac2 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -1537,7 +1537,30 @@ ggit_repository_lookup_submodule (GgitRepository  *repository,
 	return gsubmodule;
 }
 
-#if 0
+typedef struct
+{
+	gpointer user_data;
+
+	GgitSubmoduleCallback callback;
+} SubmoduleCallbackWrapperData;
+
+static gint
+submodule_wrapper_callback (git_submodule *submodule,
+                            const gchar   *name,
+                            gpointer       user_data)
+{
+	SubmoduleCallbackWrapperData *wrapper_data = (SubmoduleCallbackWrapperData *)user_data;
+	GgitSubmodule *gsubmodule;
+	gint ret;
+
+	gsubmodule = _ggit_submodule_new (submodule);
+
+	ret = wrapper_data->callback (gsubmodule, name, wrapper_data->user_data);
+
+	ggit_submodule_unref (gsubmodule);
+
+	return ret;
+}
 
 /**
  * ggit_repository_submodule_foreach:
@@ -1560,15 +1583,19 @@ ggit_repository_submodule_foreach (GgitRepository        *repository,
                                    gpointer               user_data,
                                    GError               **error)
 {
+	SubmoduleCallbackWrapperData 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_submodule_foreach (_ggit_native_get (repository),
-	                             callback,
-	                             user_data);
+	                             submodule_wrapper_callback,
+	                             &wrapper_data);
 
 	if (ret != GIT_OK)
 	{
@@ -1579,8 +1606,6 @@ ggit_repository_submodule_foreach (GgitRepository        *repository,
 	return TRUE;
 }
 
-#endif
-
 /**
  * ggit_repository_reset:
  * @repository: a #GgitRepository.
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index eb0532b..09bde64 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -774,6 +774,7 @@ typedef gint (* GgitStatusCallback) (const gchar     *path,
 
 /**
  * GgitSubmoduleCallback:
+ * @submodule: a #GgitSubmodule.
  * @name: the name of the submodule.
  * @data: (closure): user-supplied data.
  *
@@ -782,8 +783,9 @@ typedef gint (* GgitStatusCallback) (const gchar     *path,
  *
  * Returns: 0 to go for the next submodule or a #GgitError in case there was an error.
  */
-typedef gint (* GgitSubmoduleCallback) (const gchar *name,
-                                        gpointer     data);
+typedef gint (* GgitSubmoduleCallback) (GgitSubmodule *submodule,
+                                        const gchar   *name,
+                                        gpointer       data);
 
 /**
  * GgitTreeWalkCallback:



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