[libgit2-glib] Add GgitDiffBinary boxed type
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Add GgitDiffBinary boxed type
- Date: Tue, 30 Jun 2015 19:18:13 +0000 (UTC)
commit 8822e80b33da84632634310184406189cb68ae15
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Jun 30 20:50:26 2015 +0200
Add GgitDiffBinary boxed type
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-diff-binary.c | 122 +++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-diff-binary.h | 48 +++++++++++++++
libgit2-glib/ggit-types.h | 7 ++
4 files changed, 179 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 1f7a9c1..7b52283 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -34,6 +34,7 @@ H_FILES = \
ggit-cred.h \
ggit-cred-plaintext.h \
ggit-diff.h \
+ ggit-diff-binary.h \
ggit-diff-binary-file.h \
ggit-diff-delta.h \
ggit-diff-file.h \
@@ -100,6 +101,7 @@ C_FILES = \
ggit-cred.c \
ggit-cred-plaintext.c \
ggit-diff.c \
+ ggit-diff-binary.c \
ggit-diff-binary-file.c \
ggit-diff-delta.c \
ggit-diff-file.c \
diff --git a/libgit2-glib/ggit-diff-binary.c b/libgit2-glib/ggit-diff-binary.c
new file mode 100644
index 0000000..7eec56e
--- /dev/null
+++ b/libgit2-glib/ggit-diff-binary.c
@@ -0,0 +1,122 @@
+/*
+ * ggit-diff-binary.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2015 - Ignacio Casal Quinteiro
+ *
+ * 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 <glib-object.h>
+
+#include "ggit-diff-binary.h"
+#include "ggit-diff-binary-file.h"
+
+struct _GgitDiffBinary {
+ gint ref_count;
+
+ GgitDiffBinaryFile *old_file;
+ GgitDiffBinaryFile *new_file;
+};
+
+G_DEFINE_BOXED_TYPE (GgitDiffBinary, ggit_diff_binary,
+ ggit_diff_binary_ref, ggit_diff_binary_unref)
+
+GgitDiffBinary *
+_ggit_diff_binary_wrap (const git_diff_binary *binary)
+{
+ GgitDiffBinary *gbinary;
+
+ g_return_val_if_fail (binary != NULL, NULL);
+
+ gbinary = g_slice_new (GgitDiffBinary);
+ gbinary->ref_count = 1;
+ gbinary->old_file = _ggit_diff_binary_file_wrap (&binary->old_file);
+ gbinary->new_file = _ggit_diff_binary_file_wrap (&binary->new_file);
+
+ return gbinary;
+}
+
+/**
+ * ggit_diff_binary_ref:
+ * @binary: a #GgitDiffBinary.
+ *
+ * Atomically increments the reference count of @binary by one.
+ * This function is MT-safe and may be called from any thread.
+ *
+ * Returns: a #GgitDiffBinary.
+ **/
+GgitDiffBinary *
+ggit_diff_binary_ref (GgitDiffBinary *binary)
+{
+ g_return_val_if_fail (binary != NULL, NULL);
+
+ g_atomic_int_inc (&binary->ref_count);
+
+ return binary;
+}
+
+/**
+ * ggit_diff_binary_unref:
+ * @binary: a #GgitDiffBinary.
+ *
+ * Atomically decrements the reference count of @binary by one.
+ * If the reference count drops to 0, @binary is freed.
+ **/
+void
+ggit_diff_binary_unref (GgitDiffBinary *binary)
+{
+ g_return_if_fail (binary != NULL);
+
+ if (g_atomic_int_dec_and_test (&binary->ref_count))
+ {
+ ggit_diff_binary_file_unref (binary->old_file);
+ ggit_diff_binary_file_unref (binary->new_file);
+ g_slice_free (GgitDiffBinary, binary);
+ }
+}
+
+/**
+ * ggit_diff_binary_get_old_file:
+ * @binary: a #GgitDiffBinary.
+ *
+ * Gets the #GgitDiffBinaryFile old file for @binary.
+ *
+ * Returns: (transfer none): the contents of the old file.
+ */
+GgitDiffBinaryFile *
+ggit_diff_binary_get_old_file (GgitDiffBinary *binary)
+{
+ g_return_val_if_fail (binary != NULL, NULL);
+
+ return binary->old_file;
+}
+
+/**
+ * ggit_diff_binary_get_new_file:
+ * @binary: a #GgitDiffBinary.
+ *
+ * Gets the #GgitDiffBinaryFile new file for @binary.
+ *
+ * Returns: (transfer none): the contents of the new file.
+ */
+GgitDiffBinaryFile *
+ggit_diff_binary_get_new_file (GgitDiffBinary *binary)
+{
+ g_return_val_if_fail (binary != NULL, NULL);
+
+ return binary->new_file;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-diff-binary.h b/libgit2-glib/ggit-diff-binary.h
new file mode 100644
index 0000000..b3d67dc
--- /dev/null
+++ b/libgit2-glib/ggit-diff-binary.h
@@ -0,0 +1,48 @@
+/*
+ * ggit-diff-binary.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2015 - Ignacio Casal Quinteiro
+ *
+ * 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_DIFF_BINARY_H__
+#define __GGIT_DIFF_BINARY_H__
+
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_DIFF_BINARY (ggit_diff_binary_get_type ())
+#define GGIT_DIFF_BINARY(obj) ((GgitDiffBinary *)obj)
+
+GType ggit_diff_binary_get_type (void) G_GNUC_CONST;
+
+GgitDiffBinary *_ggit_diff_binary_wrap (const git_diff_binary *binary);
+
+GgitDiffBinary *ggit_diff_binary_ref (GgitDiffBinary *binary);
+void ggit_diff_binary_unref (GgitDiffBinary *binary);
+
+GgitDiffBinaryFile *ggit_diff_binary_get_old_file (GgitDiffBinary *binary);
+
+GgitDiffBinaryFile *ggit_diff_binary_get_new_file (GgitDiffBinary *binary);
+
+G_END_DECLS
+
+#endif /* __GGIT_DIFF_BINARY_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 8e82d55..adcaa77 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -131,6 +131,13 @@ typedef struct _GgitCredPlaintext GgitCredPlaintext;
typedef struct _GgitDiff GgitDiff;
/**
+ * GgitDiffBinary:
+ *
+ * Represents a diff binary.
+ */
+typedef struct _GgitDiffBinary GgitDiffBinary;
+
+/**
* GgitDiffBinaryFile:
*
* Represents a diff binary file.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]