[libgit2-glib] Added bindings for git_tree_walk
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added bindings for git_tree_walk
- Date: Tue, 17 Jul 2012 12:43:21 +0000 (UTC)
commit 5afef9334e36ace8ebf6310bf364054cf84dd5fe
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Tue Jul 17 14:42:50 2012 +0200
Added bindings for git_tree_walk
libgit2-glib/ggit-tree.c | 68 +++++++++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-tree.h | 6 ++++
libgit2-glib/ggit-types.h | 27 ++++++++++++++++++
3 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/ggit-tree.c b/libgit2-glib/ggit-tree.c
index a9e96b7..483d8cc 100644
--- a/libgit2-glib/ggit-tree.c
+++ b/libgit2-glib/ggit-tree.c
@@ -18,8 +18,11 @@
* along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <git2/errors.h>
+
#include "ggit-tree.h"
#include "ggit-oid.h"
+#include "ggit-error.h"
G_DEFINE_TYPE (GgitTree, ggit_tree, GGIT_TYPE_OBJECT)
@@ -152,4 +155,69 @@ ggit_tree_get_by_file (GgitTree *tree,
return entry;
}
+typedef struct
+{
+ GgitTreeWalkCallback callback;
+ gpointer user_data;
+} WalkInfo;
+
+static int
+walk_callback_wrapper (const char *root,
+ const git_tree_entry *entry,
+ gpointer payload)
+{
+ gint ret;
+ GgitTreeEntry *wentry;
+ WalkInfo *info = (WalkInfo *)payload;
+
+ wentry = _ggit_tree_entry_new (entry);
+
+ ret = info->callback(root, wentry, info->user_data);
+
+ ggit_tree_entry_unref (wentry);
+
+ return ret;
+}
+
+/**
+ * ggit_tree_walk:
+ * @tree: a #GgitTree.
+ * @callback: (scope call): the callback to call for each entry
+ * @mode: the walking order
+ * @user_data: (closure): user data for the callback.
+ * @error: a #GError.
+ *
+ * Walk all the entries of a tree object recursively (resolving and walking
+ * subtrees of the tree as needed). The @error will be set to the error returned
+ * by @callback (if any).
+ *
+ **/
+void
+ggit_tree_walk (GgitTree *tree,
+ GgitTreeWalkCallback callback,
+ GgitTreeWalkMode mode,
+ gpointer user_data,
+ GError **error)
+{
+ gint ret;
+ WalkInfo info = {0,};
+
+ g_return_if_fail (GGIT_IS_TREE (tree));
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ info.callback = callback;
+ info.user_data = user_data;
+
+ ret = git_tree_walk (_ggit_native_get (tree),
+ (git_treewalk_cb)walk_callback_wrapper,
+ mode,
+ &info);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-tree.h b/libgit2-glib/ggit-tree.h
index 01ebaef..9fa9dd9 100644
--- a/libgit2-glib/ggit-tree.h
+++ b/libgit2-glib/ggit-tree.h
@@ -72,6 +72,12 @@ guint ggit_tree_size (GgitTree *tree);
GgitTreeEntry *ggit_tree_get_by_file (GgitTree *tree,
GFile *file);
+void ggit_tree_walk (GgitTree *tree,
+ GgitTreeWalkCallback callback,
+ GgitTreeWalkMode mode,
+ gpointer user_data,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_TREE_H__ */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 7aa23b5..e03f06f 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -513,6 +513,17 @@ typedef enum {
GGIT_SUBMODULE_UPDATE_MERGE = 2
} GgitSubmoduleUpdate;
+/**
+ * GgitTreeWalkMode:
+ * @GGIT_TREE_WALK_MODE_PRE: walk tree in pre-order
+ * @GGIT_TREE_WALK_MODE_POST: walk tree in post-order
+ *
+ * Describes in which order a tree walk should be performed.
+ */
+typedef enum {
+ GGIT_TREE_WALK_MODE_PRE = 0,
+ GGIT_TREE_WALK_MODE_POST = 1,
+} GgitTreeWalkMode;
/**
@@ -675,6 +686,22 @@ typedef gint (* GgitStatusCallback) (const gchar *path,
typedef gint (* GgitSubmoduleCallback) (const gchar *name,
gpointer data);
+/**
+ * GgitTreeWalkCallback:
+ * @root: the current (relative) root of the entry
+ * @entry: the tree entry
+ * @user_data: (closure): user-supplied data.
+ *
+ * The type of the callback functions for walking a tree.
+ * See ggit_tree_walk().
+ *
+ * Returns: 0 to go for the next entry or a #GgitError in case there was an error.
+ *
+ */
+typedef gint (* GgitTreeWalkCallback) (const gchar *root,
+ const GgitTreeEntry *entry,
+ gpointer user_data);
+
G_END_DECLS
#endif /* __GGIT_TYPES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]