[libgit2-glib] Added GgitRemoteHead



commit 746fde9f95da51c0e5a5e3bc42513229d4242023
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Fri Nov 22 19:51:20 2013 +0100

    Added GgitRemoteHead

 libgit2-glib/ggit-remote.c |  106 ++++++++++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-remote.h |   16 +++++-
 libgit2-glib/ggit-types.h  |    7 +++
 3 files changed, 126 insertions(+), 3 deletions(-)
---
diff --git a/libgit2-glib/ggit-remote.c b/libgit2-glib/ggit-remote.c
index 83c5897..39adece 100644
--- a/libgit2-glib/ggit-remote.c
+++ b/libgit2-glib/ggit-remote.c
@@ -33,7 +33,113 @@ struct _GgitRemote
        gint ref_count;
 };
 
+struct _GgitRemoteHead
+{
+       gboolean is_local;
+       GgitOId *oid;
+       GgitOId *local_oid;
+       gchar *name;
+
+       gint ref_count;
+};
+
 G_DEFINE_BOXED_TYPE (GgitRemote, ggit_remote, ggit_remote_ref, ggit_remote_unref)
+G_DEFINE_BOXED_TYPE (GgitRemoteHead, ggit_remote_head, ggit_remote_head_ref, ggit_remote_head_unref)
+
+static GgitRemoteHead *
+_ggit_remote_head_wrap (const git_remote_head *remote_head)
+{
+       GgitRemoteHead *ret;
+
+       ret = g_slice_new (GgitRemoteHead);
+       ret->ref_count = 1;
+       ret->is_local = remote_head->local;
+       ret->oid = _ggit_oid_wrap (&remote_head->oid);
+       ret->local_oid = _ggit_oid_wrap (&remote_head->loid);
+       ret->name = g_strdup (remote_head->name);
+
+       return ret;
+}
+
+GgitRemoteHead *
+ggit_remote_head_ref (GgitRemoteHead *remote_head)
+{
+       g_atomic_int_inc (&remote_head->ref_count);
+       return remote_head;
+}
+
+void
+ggit_remote_head_unref (GgitRemoteHead *remote_head)
+{
+       if (g_atomic_int_dec_and_test (&remote_head->ref_count))
+       {
+               ggit_oid_free (remote_head->oid);
+               ggit_oid_free (remote_head->local_oid);
+               g_free (remote_head->name);
+
+               g_slice_free (GgitRemoteHead, remote_head);
+       }
+}
+
+/**
+ * ggit_remote_head_get_oid:
+ * @remote_head: a #GgitRemoteHead.
+ *
+ * Get the remote oid of the remote head.
+ *
+ * Returns: (transfer none): the remote oid.
+ */
+GgitOId *
+ggit_remote_head_get_oid (GgitRemoteHead *remote_head)
+{
+       g_return_val_if_fail (remote_head != NULL, NULL);
+       return remote_head->oid;
+}
+
+/**
+ * ggit_remote_head_get_local_oid:
+ * @remote_head: a #GgitRemoteHead.
+ *
+ * Get the local oid of the remote head.
+ *
+ * Returns: (transfer none): the local oid.
+ */
+GgitOId *
+ggit_remote_head_get_local_oid (GgitRemoteHead *remote_head)
+{
+       g_return_val_if_fail (remote_head != NULL, NULL);
+       return remote_head->local_oid;
+}
+
+/**
+ * ggit_remote_head_is_local:
+ * @remote_head: a #GgitRemoteHead.
+ *
+ * Get whether the remote head is local.
+ *
+ * Returns: whether the remote head is local.
+ */
+gboolean
+ggit_remote_head_is_local (GgitRemoteHead *remote_head)
+{
+       g_return_val_if_fail (remote_head != NULL, FALSE);
+       return remote_head->is_local;
+}
+
+/**
+ * ggit_remote_head_get_name:
+ * @remote_head: a #GgitRemoteHead.
+ *
+ * Get the remote head name.
+ *
+ * Returns: the remote head name.
+ */
+const gchar *
+ggit_remote_head_get_name (GgitRemoteHead *remote_head)
+{
+       g_return_val_if_fail (remote_head != NULL, NULL);
+       return remote_head->name;
+}
 
 GgitRemote *
 _ggit_remote_wrap (const git_remote *remote)
diff --git a/libgit2-glib/ggit-remote.h b/libgit2-glib/ggit-remote.h
index 9b10a8f..2e30fa1 100644
--- a/libgit2-glib/ggit-remote.h
+++ b/libgit2-glib/ggit-remote.h
@@ -31,7 +31,19 @@ G_BEGIN_DECLS
 #define GGIT_TYPE_REMOTE        (ggit_remote_get_type ())
 #define GGIT_REMOTE(obj)        ((GgitRemote *)obj)
 
+#define GGIT_TYPE_REMOTE_HEAD   (ggit_remote_head_get_type ())
+#define GGIT_REMOTE_HEAD(obj)        ((GgitRemoteHead *)obj)
+
 GType              ggit_remote_get_type                 (void) G_GNUC_CONST;
+GType              ggit_remote_head_get_type            (void) G_GNUC_CONST;
+
+GgitRemoteHead    *ggit_remote_head_ref                 (GgitRemoteHead *remote_head);
+void               ggit_remote_head_unref               (GgitRemoteHead *remote_head);
+
+GgitOId           *ggit_remote_head_get_oid             (GgitRemoteHead *remote_head);
+GgitOId           *ggit_remote_head_get_local_oid       (GgitRemoteHead *remote_head);
+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);
 
@@ -66,9 +78,7 @@ void               ggit_remote_add_push_spec            (GgitRemote       *remot
                                                          const gchar      *push_spec,
                                                          GError          **error);
 
-void               ggit_remote_list                     (GgitRemote       *remote,
-                                                         GgitRemoteListCallback callback,
-                                                         gpointer          user_data,
+GgitRemoteHead   **ggit_remote_list                     (GgitRemote       *remote,
                                                          GError          **error);
 
 gboolean           ggit_remote_is_valid_url             (const gchar      *url);
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index bc5decc..da21e67 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -271,6 +271,13 @@ typedef struct _GgitReflogEntry GgitReflogEntry;
 typedef struct _GgitRemote GgitRemote;
 
 /**
+ * GgitRemoteHead:
+ *
+ * Represents a git remote head.
+ */
+typedef struct _GgitRemoteHead GgitRemoteHead;
+
+/**
  * GgitRemoteCbs:
  *
  * Represents a git remote callbacks.


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