[libgit2-glib] Port GgitDiff to G_DECLARE_DERIVABLE_TYPE macro



commit d02519cf7dcba18ce0d1e185091f3a13b7b1de84
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Jul 15 20:07:00 2015 +0200

    Port GgitDiff to G_DECLARE_DERIVABLE_TYPE macro

 libgit2-glib/ggit-autocleanup.h |    1 -
 libgit2-glib/ggit-diff.c        |   50 +++++++++++++++++++++++++++-----------
 libgit2-glib/ggit-diff.h        |   21 +--------------
 libgit2-glib/ggit-patch.h       |    1 +
 libgit2-glib/ggit-types.h       |    7 -----
 5 files changed, 38 insertions(+), 42 deletions(-)
---
diff --git a/libgit2-glib/ggit-autocleanup.h b/libgit2-glib/ggit-autocleanup.h
index a282c83..4faa080 100644
--- a/libgit2-glib/ggit-autocleanup.h
+++ b/libgit2-glib/ggit-autocleanup.h
@@ -74,7 +74,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffDelta, ggit_diff_delta_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffFile, ggit_diff_file_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffFindOptions, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffFormatEmailOptions, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiff, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffHunk, ggit_diff_hunk_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffLine, ggit_diff_line_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitDiffOptions, g_object_unref)
diff --git a/libgit2-glib/ggit-diff.c b/libgit2-glib/ggit-diff.c
index 1ccbde3..e36f3d4 100644
--- a/libgit2-glib/ggit-diff.c
+++ b/libgit2-glib/ggit-diff.c
@@ -35,13 +35,18 @@
 #include "ggit-diff-find-options.h"
 #include "ggit-diff-format-email-options.h"
 
-#define GGIT_DIFF_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_DIFF, GgitDiffPrivate))
 
-struct _GgitDiffPrivate
+/**
+ * GgitDiff:
+ *
+ * Represents a diff list.
+ */
+
+typedef struct _GgitDiffPrivate
 {
        GgitRepository *repository;
        gchar *encoding;
-};
+} GgitDiffPrivate;
 
 typedef struct {
        GgitDiff *diff;
@@ -55,7 +60,7 @@ typedef struct {
        GgitDiffLineCallback line_cb;
 } CallbackWrapperData;
 
-G_DEFINE_TYPE (GgitDiff, ggit_diff, GGIT_TYPE_NATIVE)
+G_DEFINE_TYPE_WITH_PRIVATE (GgitDiff, ggit_diff, GGIT_TYPE_NATIVE)
 
 enum
 {
@@ -78,8 +83,11 @@ ggit_diff_file_callback_wrapper (const git_diff_delta *delta,
 
        if (data->diff != NULL)
        {
+               GgitDiffPrivate *priv;
                GgitDiffFile *file;
 
+               priv = ggit_diff_get_instance_private (data->diff);
+
                if (ggit_diff_delta_get_status (gdelta) == GGIT_DELTA_DELETED)
                {
                        file = ggit_diff_delta_get_old_file (gdelta);
@@ -96,7 +104,7 @@ ggit_diff_file_callback_wrapper (const git_diff_delta *delta,
                        path = ggit_diff_file_get_path (file);
 
                        data->encoding =
-                               ggit_repository_get_attribute (data->diff->priv->repository,
+                               ggit_repository_get_attribute (priv->repository,
                                                               path,
                                                               "encoding",
                                                               GGIT_ATTRIBUTE_CHECK_FILE_THEN_INDEX,
@@ -172,7 +180,10 @@ ggit_diff_line_callback_wrapper (const git_diff_delta *delta,
        }
        else if (data->diff != NULL)
        {
-               encoding = data->diff->priv->encoding;
+               GgitDiffPrivate *priv;
+
+               priv = ggit_diff_get_instance_private (data->diff);
+               encoding = priv->encoding;
        }
 
        gdelta = _ggit_diff_delta_wrap (delta);
@@ -199,7 +210,10 @@ ggit_diff_line_callback_wrapper (const git_diff_delta *delta,
 static void
 ggit_diff_finalize (GObject *object)
 {
-       GgitDiffPrivate *priv = GGIT_DIFF (object)->priv;
+       GgitDiff *diff = GGIT_DIFF (object);
+       GgitDiffPrivate *priv;
+
+       priv = ggit_diff_get_instance_private (diff);
 
        g_free (priv->encoding);
 
@@ -212,12 +226,15 @@ ggit_diff_set_property (GObject      *object,
                         const GValue *value,
                         GParamSpec   *pspec)
 {
-       GgitDiff *self = GGIT_DIFF (object);
+       GgitDiff *diff = GGIT_DIFF (object);
+       GgitDiffPrivate *priv;
+
+       priv = ggit_diff_get_instance_private (diff);
 
        switch (prop_id)
        {
                case PROP_REPOSITORY:
-                       self->priv->repository = g_value_dup_object (value);
+                       priv->repository = g_value_dup_object (value);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -231,12 +248,15 @@ ggit_diff_get_property (GObject    *object,
                         GValue     *value,
                         GParamSpec *pspec)
 {
-       GgitDiff *self = GGIT_DIFF (object);
+       GgitDiff *diff = GGIT_DIFF (object);
+       GgitDiffPrivate *priv;
+
+       priv = ggit_diff_get_instance_private (diff);
 
        switch (prop_id)
        {
                case PROP_REPOSITORY:
-                       g_value_set_object (value, self->priv->repository);
+                       g_value_set_object (value, priv->repository);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -247,9 +267,12 @@ ggit_diff_get_property (GObject    *object,
 static void
 ggit_diff_constructed (GObject *object)
 {
-       GgitDiffPrivate *priv = GGIT_DIFF (object)->priv;
+       GgitDiff *diff = GGIT_DIFF (object);
+       GgitDiffPrivate *priv;
        GgitConfig *config = NULL;
 
+       priv = ggit_diff_get_instance_private (diff);
+
        if (priv->repository != NULL)
        {
                config = ggit_repository_get_config (priv->repository, NULL);
@@ -290,14 +313,11 @@ ggit_diff_class_init (GgitDiffClass *klass)
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY |
                                                              G_PARAM_STATIC_STRINGS));
-
-       g_type_class_add_private (object_class, sizeof (GgitDiffPrivate));
 }
 
 static void
 ggit_diff_init (GgitDiff *self)
 {
-       self->priv = GGIT_DIFF_GET_PRIVATE (self);
 }
 
 static GgitDiff *
diff --git a/libgit2-glib/ggit-diff.h b/libgit2-glib/ggit-diff.h
index 1154f17..b2dab13 100644
--- a/libgit2-glib/ggit-diff.h
+++ b/libgit2-glib/ggit-diff.h
@@ -28,23 +28,8 @@
 
 G_BEGIN_DECLS
 
-#define GGIT_TYPE_DIFF                 (ggit_diff_get_type ())
-#define GGIT_DIFF(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_DIFF, GgitDiff))
-#define GGIT_DIFF_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_DIFF, GgitDiffClass))
-#define GGIT_IS_DIFF(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_DIFF))
-#define GGIT_IS_DIFF_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_DIFF))
-#define GGIT_DIFF_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_DIFF, GgitDiffClass))
-
-typedef struct _GgitDiffClass  GgitDiffClass;
-typedef struct _GgitDiffPrivate GgitDiffPrivate;
-
-struct _GgitDiff
-{
-       /*< private >*/
-       GgitNative parent;
-
-       GgitDiffPrivate *priv;
-};
+#define GGIT_TYPE_DIFF (ggit_diff_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GgitDiff, ggit_diff, GGIT, DIFF, GgitNative)
 
 /**
  * GgitDiffClass:
@@ -58,8 +43,6 @@ struct _GgitDiffClass
        GgitNativeClass parent_class;
 };
 
-GType          ggit_diff_get_type                  (void) G_GNUC_CONST;
-
 GgitDiff      *ggit_diff_new_tree_to_tree          (GgitRepository        *repository,
                                                     GgitTree              *old_tree,
                                                     GgitTree              *new_tree,
diff --git a/libgit2-glib/ggit-patch.h b/libgit2-glib/ggit-patch.h
index 59c8fe7..8909dbb 100644
--- a/libgit2-glib/ggit-patch.h
+++ b/libgit2-glib/ggit-patch.h
@@ -26,6 +26,7 @@
 #include <git2.h>
 #include "ggit-types.h"
 #include "ggit-blob.h"
+#include "ggit-diff.h"
 
 G_BEGIN_DECLS
 
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index e8544bf..526ab86 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -96,13 +96,6 @@ typedef struct _GgitCredSshKeyFromAgent GgitCredSshKeyFromAgent;
 typedef struct _GgitCredPlaintext GgitCredPlaintext;
 
 /**
- * GgitDiff:
- *
- * Represents a diff list.
- */
-typedef struct _GgitDiff GgitDiff;
-
-/**
  * GgitDiffBinary:
  *
  * Represents a diff binary.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]