[libgit2-glib] Add new boxed type GgitConfigEntry
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Add new boxed type GgitConfigEntry
- Date: Mon, 29 Oct 2012 18:11:32 +0000 (UTC)
commit a47c69ce53e5733cf465d35e673b7474a0e6d150
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Oct 29 19:09:45 2012 +0100
Add new boxed type GgitConfigEntry
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-config-entry.c | 131 ++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-config-entry.h | 50 ++++++++++++++
3 files changed, 183 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 409e3fb..84d0db2 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -19,6 +19,7 @@ INST_H_FILES = \
ggit-branch.h \
ggit-commit.h \
ggit-config.h \
+ ggit-config-entry.h \
ggit-diff.h \
ggit-diff-delta.h \
ggit-diff-file.h \
@@ -58,6 +59,7 @@ C_FILES = \
ggit-branch.c \
ggit-commit.c \
ggit-config.c \
+ ggit-config-entry.c \
ggit-convert.c \
ggit-diff.c \
ggit-diff-delta.c \
diff --git a/libgit2-glib/ggit-config-entry.c b/libgit2-glib/ggit-config-entry.c
new file mode 100644
index 0000000..48bca2a
--- /dev/null
+++ b/libgit2-glib/ggit-config-entry.c
@@ -0,0 +1,131 @@
+/*
+ * ggit-config-entry.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ggit-config-entry.h"
+
+struct _GgitTreeEntry
+{
+ const git_config_entry *entry;
+ gint ref_count;
+};
+
+G_DEFINE_BOXED_TYPE (GgitConfigEntry,
+ ggit_config_entry,
+ ggit_config_entry_ref,
+ ggit_config_entry_unref)
+
+GgitConfigEntry *
+_ggit_config_entry_wrap (const git_config_entry *entry)
+{
+ GgitTreeEntry *ret;
+
+ ret = g_slice_new (GgitTreeEntry);
+ ret->entry = entry;
+ ret->ref_count = 1;
+
+ return ret;
+}
+
+/**
+ * ggit_config_entry_ref:
+ * @entry: a #GgitConfigEntry.
+ *
+ * Atomically increments the reference count of @entry by one.
+ * This function is MT-safe and may be called from any thread.
+ *
+ * Returns: (transfer none): a #GgitConfigEntry.
+ **/
+GgitConfigEntry *
+ggit_config_entry_ref (GgitConfigEntry *entry)
+{
+ g_return_val_if_fail (entry != NULL, NULL);
+
+ g_atomic_int_inc (&entry->ref_count);
+
+ return entry;
+}
+
+/**
+ * ggit_config_entry_unref:
+ * @entry: a #GgitConfigEntry.
+ *
+ * Atomically decrements the reference count of @entry by one.
+ * If the reference count drops to 0, @entry is freed.
+ **/
+void
+ggit_config_entry_unref (GgitConfigEntry *entry)
+{
+ g_return_if_fail (entry != NULL);
+
+ if (g_atomic_int_dec_and_test (&entry->ref_count))
+ {
+ g_slice_free (GgitTreeEntry, entry);
+ }
+}
+
+/**
+ * ggit_config_entry_get_name:
+ * @entry: a #GgitConfigEntry.
+ *
+ * Gets the name of @entry.
+ *
+ * Returns: the name of @entry:
+ */
+const gchar *
+ggit_config_entry_get_name (GgitConfigEntry *entry)
+{
+ g_return_val_if_fail (entry != NULL, NULL);
+
+ return entry->entry->name;
+}
+
+/**
+ * ggit_config_entry_get_value:
+ * @entry: a #GgitConfigEntry.
+ *
+ * Gets the value of @entry.
+ *
+ * Returns: the value of @entry.
+ */
+const gchar *
+ggit_config_entry_get_value (GgitConfigEntry *entry)
+{
+ g_return_val_if_fail (entry != NULL, NULL);
+
+ return entry->entry->value;
+}
+
+/**
+ * ggit_config_entry_level:
+ * @entry: a #GgitConfigEntry.
+ *
+ * Gets the #GgitConfigLevel of @entry.
+ *
+ * Returns: the #GgitConfigLevel of @entry.
+ */
+GgitConfigLevel
+ggit_config_entry_level (GgitConfigEntry *entry)
+{
+ g_return_val_if_fail (entry != NULL, 0);
+
+ return entry->entry->level;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-config-entry.h b/libgit2-glib/ggit-config-entry.h
new file mode 100644
index 0000000..c65cb2f
--- /dev/null
+++ b/libgit2-glib/ggit-config-entry.h
@@ -0,0 +1,50 @@
+/*
+ * ggit-config-entry.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GGIT_CONFIG_ENTRY_H__
+#define __GGIT_CONFIG_ENTRY_H__
+
+#include <git2/config.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_CONFIG_ENTRY (ggit_config_entry_get_type ())
+#define GGIT_CONFIG_ENTRY(obj) ((GgitConfigEntry *)obj)
+
+GType ggit_config_entry_get_type (void) G_GNUC_CONST;
+
+GgitConfigEntry *_ggit_config_entry_wrap (const git_config_entry *entry);
+
+GgitConfigEntry *ggit_config_entry_ref (GgitConfigEntry *entry);
+void ggit_config_entry_unref (GgitConfigEntry *entry);
+
+const gchar *ggit_config_entry_get_name (GgitConfigEntry *entry);
+
+const gchar *ggit_config_entry_get_value (GgitConfigEntry *entry);
+
+GgitConfigLevel ggit_config_entry_level (GgitConfigEntry *entry);
+
+G_END_DECLS
+
+#endif /* __GGIT_CONFIG_ENTRY_H__ */
+
+/* ex:set ts=8 noet: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]