[libgit2-glib] Added tree builder API
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added tree builder API
- Date: Sun, 23 Jun 2013 12:44:03 +0000 (UTC)
commit b7501ac0315d748247a9b95f98c8f2f43ff90140
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sun Jun 23 14:35:08 2013 +0200
Added tree builder API
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-tree-builder.c | 120 ++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-tree-builder.h | 75 ++++++++++++++++++++++++
libgit2-glib/ggit-tree.c | 33 ++++++++++
libgit2-glib/ggit-tree.h | 3 +
5 files changed, 233 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 4d43eb4..36827af 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -54,6 +54,7 @@ INST_H_FILES = \
ggit-tag.h \
ggit-transfer-progress.h \
ggit-tree.h \
+ ggit-tree-builder.h \
ggit-tree-entry.h \
ggit-types.h \
ggit.h
@@ -100,6 +101,7 @@ C_FILES = \
ggit-tag.c \
ggit-transfer-progress.c \
ggit-tree.c \
+ ggit-tree-builder.c \
ggit-tree-entry.c \
ggit-types.c \
ggit-utils.c
diff --git a/libgit2-glib/ggit-tree-builder.c b/libgit2-glib/ggit-tree-builder.c
new file mode 100644
index 0000000..1d87132
--- /dev/null
+++ b/libgit2-glib/ggit-tree-builder.c
@@ -0,0 +1,120 @@
+/*
+ * ggit-tree-builder.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <git2/errors.h>
+
+#include "ggit-tree-builder.h"
+#include "ggit-error.h"
+#include "ggit-tree-entry.h"
+
+G_DEFINE_TYPE (GgitTreeBuilder, ggit_tree_builder, GGIT_TYPE_NATIVE)
+
+static void
+ggit_tree_builder_class_init (GgitTreeBuilderClass *klass)
+{
+}
+
+static void
+ggit_tree_builder_init (GgitTreeBuilder *self)
+{
+}
+
+GgitTreeBuilder *
+_ggit_tree_builder_wrap (git_treebuilder *builder,
+ gboolean owned)
+{
+ GgitTreeBuilder *gbuilder;
+
+ gbuilder = g_object_new (GGIT_TYPE_TREE_BUILDER,
+ "native", builder,
+ NULL);
+
+ if (owned)
+ {
+ _ggit_native_set_destroy_func (gbuilder,
+ (GDestroyNotify)git_treebuilder_free);
+ }
+
+ return gbuilder;
+}
+
+/**
+ * ggit_tree_builder_remove:
+ * @builder: a #GgitTreeBuilder.
+ * @path: the path to remove.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Remove an entry from the builder by path.
+ *
+ */
+void
+ggit_tree_builder_remove (GgitTreeBuilder *builder,
+ const gchar *path,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (GGIT_IS_TREE_BUILDER (builder));
+ g_return_if_fail (path != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_treebuilder_remove (_ggit_native_get (builder),
+ path);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_tree_builder_get_entry:
+ * @builder: a #GgitTreeBuilder.
+ * @path: the path to remove.
+ *
+ * Get an entry by path.
+ *
+ * Returns: the #GGitTreeEntry or %NULL if no such entry exists.
+ *
+ */
+GgitTreeEntry *
+ggit_tree_builder_get_entry (GgitTreeBuilder *builder,
+ const gchar *path)
+{
+ const git_tree_entry *ret;
+
+ g_return_val_if_fail (GGIT_IS_TREE_BUILDER (builder), NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ ret = git_treebuilder_get (_ggit_native_get (builder),
+ path);
+
+ if (ret != NULL)
+ {
+ return _ggit_tree_entry_wrap ((git_tree_entry *)ret, FALSE);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-tree-builder.h b/libgit2-glib/ggit-tree-builder.h
new file mode 100644
index 0000000..65f8e49
--- /dev/null
+++ b/libgit2-glib/ggit-tree-builder.h
@@ -0,0 +1,75 @@
+/*
+ * ggit-tree-builder.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GGIT_TREE_BUILDER_H__
+#define __GGIT_TREE_BUILDER_H__
+
+#include <git2/tree.h>
+#include <libgit2-glib/ggit-native.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_TREE_BUILDER (ggit_tree_builder_get_type ())
+#define GGIT_TREE_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_TREE_BUILDER,
GgitTreeBuilder))
+#define GGIT_TREE_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_TREE_BUILDER,
GgitTreeBuilderClass))
+#define GGIT_IS_TREE_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_TREE_BUILDER))
+#define GGIT_IS_TREE_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_TREE_BUILDER))
+#define GGIT_TREE_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_TREE_BUILDER,
GgitTreeBuilderClass))
+
+typedef struct _GgitTreeBuilderClass GgitTreeBuilderClass;
+
+struct _GgitTreeBuilder
+{
+ /*< private >*/
+ GgitNative parent;
+
+ /* priv padding */
+ gpointer priv;
+};
+
+/**
+ * GgitTreeBuilderClass:
+ * @parent_class: The parent class.
+ *
+ * The class structure for #GgitTreeBuilderClass.
+ */
+struct _GgitTreeBuilderClass
+{
+ /*< private >*/
+ GgitNativeClass parent_class;
+};
+
+GType ggit_tree_builder_get_type (void) G_GNUC_CONST;
+
+GgitTreeBuilder *_ggit_tree_builder_wrap (git_treebuilder *builder,
+ gboolean owned);
+
+void ggit_tree_builder_remove (GgitTreeBuilder *builder,
+ const gchar *path,
+ GError **error);
+
+ GgitTreeEntry *ggit_tree_builder_get_entry (GgitTreeBuilder *builder,
+ const gchar *path);
+
+G_END_DECLS
+
+#endif /* __GGIT_TREE_BUILDER_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-tree.c b/libgit2-glib/ggit-tree.c
index c6a6a50..7e68bec 100644
--- a/libgit2-glib/ggit-tree.c
+++ b/libgit2-glib/ggit-tree.c
@@ -23,6 +23,7 @@
#include "ggit-tree.h"
#include "ggit-oid.h"
#include "ggit-error.h"
+#include "ggit-tree-builder.h"
G_DEFINE_TYPE (GgitTree, ggit_tree, GGIT_TYPE_OBJECT)
@@ -265,4 +266,36 @@ ggit_tree_walk (GgitTree *tree,
}
}
+/**
+ * ggit_tree_create_builder:
+ * @tree: (allow-none): a #GgitTree.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Create a tree builder for initialized with @tree. If @tree is %NULL,
+ * then the builder will initially be empty.
+ *
+ * Returns: (transfer full): a new #GgitTreeBuilder object, or %NULL if there was an error.
+ *
+ **/
+GgitTreeBuilder *
+ggit_tree_create_builder (GgitTree *tree,
+ GError **error)
+{
+ gint ret;
+ git_treebuilder *builder;
+
+ g_return_val_if_fail (tree == NULL || GGIT_IS_TREE (tree), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ ret = git_treebuilder_create (&builder, _ggit_native_get (tree));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+
+ return _ggit_tree_builder_wrap (builder, TRUE);
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-tree.h b/libgit2-glib/ggit-tree.h
index 8572c1b..eb393f7 100644
--- a/libgit2-glib/ggit-tree.h
+++ b/libgit2-glib/ggit-tree.h
@@ -84,6 +84,9 @@ void ggit_tree_walk (GgitTree *tree,
gpointer user_data,
GError **error);
+GgitTreeBuilder *ggit_tree_create_builder (GgitTree *tree,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_TREE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]