[libgit2-glib] Port GgitCommit to G_DECLARE_DERIVABLE_TYPE macro
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Port GgitCommit to G_DECLARE_DERIVABLE_TYPE macro
- Date: Tue, 14 Jul 2015 21:07:26 +0000 (UTC)
commit 08096bed34e1ecb592d6390309f7d4bdb90b4c0b
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Jul 14 23:07:07 2015 +0200
Port GgitCommit to G_DECLARE_DERIVABLE_TYPE macro
libgit2-glib/ggit-autocleanup.h | 1 -
libgit2-glib/ggit-commit-parents.h | 1 +
libgit2-glib/ggit-commit.c | 55 +++++++++++++++++++++++-------------
libgit2-glib/ggit-commit.h | 22 +-------------
libgit2-glib/ggit-index-entry.h | 1 +
libgit2-glib/ggit-types.h | 7 ----
6 files changed, 39 insertions(+), 48 deletions(-)
---
diff --git a/libgit2-glib/ggit-autocleanup.h b/libgit2-glib/ggit-autocleanup.h
index f45b202..a9318d5 100644
--- a/libgit2-glib/ggit-autocleanup.h
+++ b/libgit2-glib/ggit-autocleanup.h
@@ -63,7 +63,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitBlobOutputStream, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitBranchEnumerator, ggit_branch_enumerator_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitCherryPickOptions, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitCloneOptions, ggit_clone_options_free)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitCommit, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitCommitParents, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitConfigEntry, ggit_config_entry_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitCred, g_object_unref)
diff --git a/libgit2-glib/ggit-commit-parents.h b/libgit2-glib/ggit-commit-parents.h
index 6713ab3..766890b 100644
--- a/libgit2-glib/ggit-commit-parents.h
+++ b/libgit2-glib/ggit-commit-parents.h
@@ -25,6 +25,7 @@
#include <glib-object.h>
#include <libgit2-glib/ggit-types.h>
+#include <libgit2-glib/ggit-commit.h>
G_BEGIN_DECLS
diff --git a/libgit2-glib/ggit-commit.c b/libgit2-glib/ggit-commit.c
index 6d9f388..5984ac9 100644
--- a/libgit2-glib/ggit-commit.c
+++ b/libgit2-glib/ggit-commit.c
@@ -28,23 +28,30 @@
#include "ggit-tree.h"
#include "ggit-commit-parents.h"
-#define GGIT_COMMIT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_COMMIT,
GgitCommitPrivate))
+/**
+ * GgitCommit:
+ *
+ * Represents a commit object.
+ */
-struct _GgitCommitPrivate
+typedef struct _GgitCommitPrivate
{
gchar *message_utf8;
gchar *subject_utf8;
-};
+} GgitCommitPrivate;
-G_DEFINE_TYPE (GgitCommit, ggit_commit, GGIT_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GgitCommit, ggit_commit, GGIT_TYPE_OBJECT)
static void
ggit_commit_finalize (GObject *object)
{
GgitCommit *commit = GGIT_COMMIT (object);
+ GgitCommitPrivate *priv;
- g_free (commit->priv->message_utf8);
- g_free (commit->priv->subject_utf8);
+ priv = ggit_commit_get_instance_private (commit);
+
+ g_free (priv->message_utf8);
+ g_free (priv->subject_utf8);
G_OBJECT_CLASS (ggit_commit_parent_class)->finalize (object);
}
@@ -55,14 +62,11 @@ ggit_commit_class_init (GgitCommitClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = ggit_commit_finalize;
-
- g_type_class_add_private (object_class, sizeof (GgitCommitPrivate));
}
static void
ggit_commit_init (GgitCommit *self)
{
- self->priv = GGIT_COMMIT_GET_PRIVATE (self);
}
GgitCommit *
@@ -121,12 +125,15 @@ ggit_commit_get_message_encoding (GgitCommit *commit)
static void
ensure_message_utf8 (GgitCommit *commit)
{
+ GgitCommitPrivate *priv;
git_commit *c;
const gchar *msg;
const gchar *encoding;
const gchar *ptr;
- if (commit->priv->message_utf8)
+ priv = ggit_commit_get_instance_private (commit);
+
+ if (priv->message_utf8)
{
return;
}
@@ -136,17 +143,17 @@ ensure_message_utf8 (GgitCommit *commit)
encoding = ggit_commit_get_message_encoding (commit);
- commit->priv->message_utf8 = ggit_convert_utf8 (msg,
- -1,
- encoding);
+ priv->message_utf8 = ggit_convert_utf8 (msg,
+ -1,
+ encoding);
/* Extract the subject */
- ptr = g_utf8_strchr (commit->priv->message_utf8, -1, '\n');
+ ptr = g_utf8_strchr (priv->message_utf8, -1, '\n');
if (ptr != NULL)
{
- commit->priv->subject_utf8 = g_strndup (commit->priv->message_utf8,
- ptr - commit->priv->message_utf8);
+ priv->subject_utf8 = g_strndup (priv->message_utf8,
+ ptr - priv->message_utf8);
}
}
@@ -162,11 +169,15 @@ ensure_message_utf8 (GgitCommit *commit)
const gchar *
ggit_commit_get_message (GgitCommit *commit)
{
+ GgitCommitPrivate *priv;
+
g_return_val_if_fail (GGIT_IS_COMMIT (commit), NULL);
+ priv = ggit_commit_get_instance_private (commit);
+
ensure_message_utf8 (commit);
- return commit->priv->message_utf8;
+ return priv->message_utf8;
}
/**
@@ -182,17 +193,21 @@ ggit_commit_get_message (GgitCommit *commit)
const gchar *
ggit_commit_get_subject (GgitCommit *commit)
{
+ GgitCommitPrivate *priv;
+
g_return_val_if_fail (GGIT_IS_COMMIT (commit), NULL);
+ priv = ggit_commit_get_instance_private (commit);
+
ensure_message_utf8 (commit);
- if (commit->priv->subject_utf8)
+ if (priv->subject_utf8)
{
- return commit->priv->subject_utf8;
+ return priv->subject_utf8;
}
else
{
- return commit->priv->message_utf8;
+ return priv->message_utf8;
}
}
diff --git a/libgit2-glib/ggit-commit.h b/libgit2-glib/ggit-commit.h
index 0ce3ede..4bbb044 100644
--- a/libgit2-glib/ggit-commit.h
+++ b/libgit2-glib/ggit-commit.h
@@ -30,24 +30,8 @@
G_BEGIN_DECLS
-#define GGIT_TYPE_COMMIT (ggit_commit_get_type ())
-#define GGIT_COMMIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_COMMIT, GgitCommit))
-#define GGIT_COMMIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_COMMIT, GgitCommitClass))
-#define GGIT_IS_COMMIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_COMMIT))
-#define GGIT_IS_COMMIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_COMMIT))
-#define GGIT_COMMIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_COMMIT, GgitCommitClass))
-
-typedef struct _GgitCommitClass GgitCommitClass;
-typedef struct _GgitCommitPrivate GgitCommitPrivate;
-
-struct _GgitCommit
-{
- /*< private >*/
- GgitObject parent;
-
- /* priv padding */
- GgitCommitPrivate *priv;
-};
+#define GGIT_TYPE_COMMIT (ggit_commit_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GgitCommit, ggit_commit, GGIT, COMMIT, GgitObject)
/**
* GgitCommitClass:
@@ -61,8 +45,6 @@ struct _GgitCommitClass
GgitObjectClass parent_class;
};
-GType ggit_commit_get_type (void) G_GNUC_CONST;
-
GgitCommit *_ggit_commit_wrap (git_commit *commit,
gboolean owned);
diff --git a/libgit2-glib/ggit-index-entry.h b/libgit2-glib/ggit-index-entry.h
index 8e6ec0f..eec13c1 100644
--- a/libgit2-glib/ggit-index-entry.h
+++ b/libgit2-glib/ggit-index-entry.h
@@ -25,6 +25,7 @@
#include <gio/gio.h>
#include <libgit2-glib/ggit-oid.h>
#include <libgit2-glib/ggit-types.h>
+#include <libgit2-glib/ggit-commit.h>
#include <git2.h>
G_BEGIN_DECLS
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 415cc7f..1c19ff2 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -47,13 +47,6 @@ typedef struct _GgitBranchEnumerator GgitBranchEnumerator;
typedef struct _GgitCloneOptions GgitCloneOptions;
/**
- * GgitCommit:
- *
- * Represents a commit object.
- */
-typedef struct _GgitCommit GgitCommit;
-
-/**
* GgitCommitParents:
*
* Represents the parents of a commit object.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]