[libgit2-glib] Make GgitRemote a GgitNative
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Make GgitRemote a GgitNative
- Date: Wed, 22 Jan 2014 18:48:34 +0000 (UTC)
commit fc8005975e857c25de87c8cb678ff3a50eac64ac
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Wed Jan 22 19:47:54 2014 +0100
Make GgitRemote a GgitNative
libgit2-glib/ggit-push.c | 27 ++++++----
libgit2-glib/ggit-remote.c | 116 +++++++++++++++++--------------------------
libgit2-glib/ggit-remote.h | 32 ++++++++++--
3 files changed, 88 insertions(+), 87 deletions(-)
---
diff --git a/libgit2-glib/ggit-push.c b/libgit2-glib/ggit-push.c
index 245d974..e07693c 100644
--- a/libgit2-glib/ggit-push.c
+++ b/libgit2-glib/ggit-push.c
@@ -47,9 +47,14 @@ G_DEFINE_TYPE_EXTENDED (GgitPush, ggit_push, GGIT_TYPE_NATIVE,
static void
-ggit_push_finalize (GObject *object)
+ggit_push_dispose (GObject *object)
{
- G_OBJECT_CLASS (ggit_push_parent_class)->finalize (object);
+ GgitPushPrivate *priv;
+
+ priv = GGIT_PUSH (object)->priv;
+ g_clear_object (&priv->remote);
+
+ G_OBJECT_CLASS (ggit_push_parent_class)->dispose (object);
}
static void
@@ -63,7 +68,7 @@ ggit_push_get_property (GObject *object,
switch (prop_id)
{
case PROP_REMOTE:
- g_value_set_boxed (value, priv->remote);
+ g_value_set_object (value, priv->remote);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -82,7 +87,7 @@ ggit_push_set_property (GObject *object,
switch (prop_id)
{
case PROP_REMOTE:
- priv->remote = g_value_get_boxed (value);
+ priv->remote = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -95,18 +100,18 @@ ggit_push_class_init (GgitPushClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = ggit_push_finalize;
+ object_class->dispose = ggit_push_dispose;
object_class->get_property = ggit_push_get_property;
object_class->set_property = ggit_push_set_property;
g_object_class_install_property (object_class,
PROP_REMOTE,
- g_param_spec_boxed ("remote",
- "Remote",
- "The remote associated with this push",
- GGIT_TYPE_REMOTE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+ g_param_spec_object ("remote",
+ "Remote",
+ "The remote associated with this push",
+ GGIT_TYPE_REMOTE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof (GgitPushPrivate));
}
diff --git a/libgit2-glib/ggit-remote.c b/libgit2-glib/ggit-remote.c
index 4f3fc28..816c04a 100644
--- a/libgit2-glib/ggit-remote.c
+++ b/libgit2-glib/ggit-remote.c
@@ -26,13 +26,6 @@
#include "ggit-ref-spec.h"
#include "ggit-repository.h"
-
-struct _GgitRemote
-{
- git_remote *remote;
- gint ref_count;
-};
-
struct _GgitRemoteHead
{
gboolean is_local;
@@ -43,7 +36,7 @@ struct _GgitRemoteHead
gint ref_count;
};
-G_DEFINE_BOXED_TYPE (GgitRemote, ggit_remote, ggit_remote_ref, ggit_remote_unref)
+G_DEFINE_TYPE (GgitRemote, ggit_remote, GGIT_TYPE_NATIVE)
G_DEFINE_BOXED_TYPE (GgitRemoteHead, ggit_remote_head, ggit_remote_head_ref, ggit_remote_head_unref)
static GgitRemoteHead *
@@ -142,15 +135,36 @@ ggit_remote_head_get_name (GgitRemoteHead *remote_head)
}
GgitRemote *
-_ggit_remote_wrap (const git_remote *remote)
+_ggit_remote_wrap (git_remote *remote)
+{
+ return g_object_new (GGIT_TYPE_REMOTE, "native", remote, NULL);
+}
+
+static void
+ggit_remote_dispose (GObject *object)
+{
+ git_remote *native = _ggit_native_get (object);
+
+ if (native != NULL)
+ {
+ git_remote_free (native);
+ _ggit_native_set (object, NULL, NULL);
+ }
+
+ G_OBJECT_CLASS (ggit_remote_parent_class)->dispose (object);
+}
+
+static void
+ggit_remote_class_init (GgitRemoteClass *klass)
{
- GgitRemote *glib_remote;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- glib_remote = g_slice_new (GgitRemote);
- glib_remote->remote = (git_remote *)remote;
- glib_remote->ref_count = 1;
+ object_class->dispose = ggit_remote_dispose;
+}
- return glib_remote;
+static void
+ggit_remote_init (GgitRemote *self)
+{
}
/**
@@ -191,44 +205,6 @@ ggit_remote_new (GgitRepository *repository,
}
/**
- * ggit_remote_ref:
- * @remote: a #GgitRemote.
- *
- * Atomically increments the reference count of @remote by one.
- * This function is MT-safe and may be called from any thread.
- *
- * Returns: (transfer none): the passed in #GgitRemote.
- */
-GgitRemote *
-ggit_remote_ref (GgitRemote *remote)
-{
- g_return_val_if_fail (remote != NULL, NULL);
-
- g_atomic_int_inc (&remote->ref_count);
-
- return remote;
-}
-
-/**
- * ggit_remote_unref:
- * @remote: a #GgitRemote.
- *
- * Atomically decrements the reference count of @remote by one.
- * If the reference count drops to 0, @remote is freed.
- */
-void
-ggit_remote_unref (GgitRemote *remote)
-{
- g_return_if_fail (remote != NULL);
-
- if (g_atomic_int_dec_and_test (&remote->ref_count))
- {
- git_remote_free (remote->remote);
- g_slice_free (GgitRemote, remote);
- }
-}
-
-/**
* ggit_remote_save:
* @remote: a #GgitRemote.
* @error: a #GError or %NULL.
@@ -241,10 +217,10 @@ ggit_remote_save (GgitRemote *remote,
{
gint ret;
- g_return_if_fail (remote != NULL);
+ g_return_if_fail (GGIT_IS_REMOTE (remote));
g_return_if_fail (error == NULL || *error == NULL);
- ret = git_remote_save (remote->remote);
+ ret = git_remote_save (_ggit_native_get (remote));
if (ret != GIT_OK)
{
@@ -263,9 +239,9 @@ ggit_remote_save (GgitRemote *remote,
const gchar *
ggit_remote_get_name (GgitRemote *remote)
{
- g_return_val_if_fail (remote != NULL, NULL);
+ g_return_val_if_fail (GGIT_IS_REMOTE (remote), NULL);
- return git_remote_name (remote->remote);
+ return git_remote_name (_ggit_native_get (remote));
}
/**
@@ -279,9 +255,9 @@ ggit_remote_get_name (GgitRemote *remote)
const gchar *
ggit_remote_get_url (GgitRemote *remote)
{
- g_return_val_if_fail (remote != NULL, NULL);
+ g_return_val_if_fail (GGIT_IS_REMOTE (remote), NULL);
- return git_remote_url (remote->remote);
+ return git_remote_url (_ggit_native_get (remote));
}
/**
@@ -302,10 +278,10 @@ ggit_remote_connect (GgitRemote *remote,
{
gint ret;
- g_return_if_fail (remote != NULL);
+ g_return_if_fail (GGIT_IS_REMOTE (remote));
g_return_if_fail (error == NULL || *error == NULL);
- ret = git_remote_connect (remote->remote, direction);
+ ret = git_remote_connect (_ggit_native_get (remote), direction);
if (ret != GIT_OK)
{
@@ -324,9 +300,9 @@ ggit_remote_connect (GgitRemote *remote,
gboolean
ggit_remote_get_connected (GgitRemote *remote)
{
- g_return_val_if_fail (remote != NULL, FALSE);
+ g_return_val_if_fail (GGIT_IS_REMOTE (remote), FALSE);
- return git_remote_connected (remote->remote);
+ return git_remote_connected (_ggit_native_get (remote));
}
/**
@@ -339,9 +315,9 @@ ggit_remote_get_connected (GgitRemote *remote)
void
ggit_remote_disconnect (GgitRemote *remote)
{
- g_return_if_fail (remote != NULL);
+ g_return_if_fail (GGIT_IS_REMOTE (remote));
- git_remote_disconnect (remote->remote);
+ git_remote_disconnect (_ggit_native_get (remote));
}
/**
@@ -359,11 +335,11 @@ ggit_remote_add_fetch_spec (GgitRemote *remote,
{
gint ret;
- g_return_if_fail (remote != NULL);
+ g_return_if_fail (GGIT_IS_REMOTE (remote));
g_return_if_fail (fetch_spec != NULL && fetch_spec[0] != '\0');
g_return_if_fail (error == NULL || *error == NULL);
- ret = git_remote_add_fetch (remote->remote, fetch_spec);
+ ret = git_remote_add_fetch (_ggit_native_get (remote), fetch_spec);
if (ret != GIT_OK)
{
@@ -386,11 +362,11 @@ ggit_remote_add_push_spec (GgitRemote *remote,
{
gint ret;
- g_return_if_fail (remote != NULL);
+ g_return_if_fail (GGIT_IS_REMOTE (remote));
g_return_if_fail (push_spec != NULL && push_spec[0] != '\0');
g_return_if_fail (error == NULL || *error == NULL);
- ret = git_remote_add_push (remote->remote, push_spec);
+ ret = git_remote_add_push (_ggit_native_get (remote), push_spec);
if (ret != GIT_OK)
{
@@ -417,10 +393,10 @@ ggit_remote_list (GgitRemote *remote,
GgitRemoteHead **retval;
gint ret;
- g_return_val_if_fail (remote != NULL, NULL);
+ g_return_val_if_fail (GGIT_IS_REMOTE (remote), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- ret = git_remote_ls (&head, &size, remote->remote);
+ ret = git_remote_ls (&head, &size, _ggit_native_get (remote));
if (ret != GIT_OK)
{
diff --git a/libgit2-glib/ggit-remote.h b/libgit2-glib/ggit-remote.h
index 35aecb8..0a6093d 100644
--- a/libgit2-glib/ggit-remote.h
+++ b/libgit2-glib/ggit-remote.h
@@ -25,11 +25,34 @@
#include <git2.h>
#include <libgit2-glib/ggit-types.h>
+#include <libgit2-glib/ggit-native.h>
G_BEGIN_DECLS
-#define GGIT_TYPE_REMOTE (ggit_remote_get_type ())
-#define GGIT_REMOTE(obj) ((GgitRemote *)obj)
+#define GGIT_TYPE_REMOTE (ggit_remote_get_type ())
+#define GGIT_REMOTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_REMOTE, GgitRemote))
+#define GGIT_REMOTE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_REMOTE, GgitRemote
const))
+#define GGIT_REMOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_REMOTE, GgitRemoteClass))
+#define GGIT_IS_REMOTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_REMOTE))
+#define GGIT_IS_REMOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_REMOTE))
+#define GGIT_REMOTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_REMOTE, GgitRemoteClass))
+
+typedef struct _GgitRemoteClass GgitRemoteClass;
+
+struct _GgitRemote
+{
+ /*< private >*/
+ GgitNative parent;
+
+ /*< priv padding >*/
+ gpointer priv;
+};
+
+struct _GgitRemoteClass
+{
+ /*< private >*/
+ GgitNativeClass parent_class;
+};
#define GGIT_TYPE_REMOTE_HEAD (ggit_remote_head_get_type ())
#define GGIT_REMOTE_HEAD(obj) ((GgitRemoteHead *)obj)
@@ -45,16 +68,13 @@ GgitOId *ggit_remote_head_get_local_oid (GgitRemoteHead *remote_
gboolean ggit_remote_head_is_local (GgitRemoteHead *remote_head);
const gchar *ggit_remote_head_get_name (GgitRemoteHead *remote_head);
-GgitRemote *_ggit_remote_wrap (const git_remote *remote);
+GgitRemote *_ggit_remote_wrap (git_remote *remote);
GgitRemote *ggit_remote_new (GgitRepository *repository,
const gchar *url,
const gchar *fetch_spec,
GError **error);
-GgitRemote *ggit_remote_ref (GgitRemote *remote);
-void ggit_remote_unref (GgitRemote *remote);
-
void ggit_remote_save (GgitRemote *remote,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]