[libgit2-glib] Add GgitRemoteCbs



commit e3d22e649d568ff61afb9e0eb31323cd6b45ceb9
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Nov 21 16:34:12 2013 +0100

    Add GgitRemoteCbs

 libgit2-glib/Makefile.am             |    2 +
 libgit2-glib/ggit-remote-callbacks.c |  102 ++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-remote-callbacks.h |   48 ++++++++++++++++
 libgit2-glib/ggit-types.h            |    7 ++
 4 files changed, 159 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 8e36162..09de9ce 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -52,6 +52,7 @@ INST_H_FILES =                                \
        ggit-reflog.h                   \
        ggit-reflog-entry.h             \
        ggit-remote.h                   \
+       ggit-remote-callbacks.h         \
        ggit-repository.h               \
        ggit-revision-walker.h          \
        ggit-signature.h                \
@@ -105,6 +106,7 @@ C_FILES =                           \
        ggit-reflog.c                   \
        ggit-reflog-entry.c             \
        ggit-remote.c                   \
+       ggit-remote-callbacks.c         \
        ggit-repository.c               \
        ggit-revision-walker.c          \
        ggit-signature.c                \
diff --git a/libgit2-glib/ggit-remote-callbacks.c b/libgit2-glib/ggit-remote-callbacks.c
new file mode 100644
index 0000000..d518d9d
--- /dev/null
+++ b/libgit2-glib/ggit-remote-callbacks.c
@@ -0,0 +1,102 @@
+/*
+ * ggit-remote-callbacks.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - 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 <git2.h>
+
+#include "ggit-remote-callbacks.h"
+
+struct _GgitRemoteCbs
+{
+       git_remote_callbacks remote_cbs;
+       gint ref_count;
+};
+
+G_DEFINE_BOXED_TYPE (GgitRemoteCbs, ggit_remote_cbs,
+                     ggit_remote_cbs_ref, ggit_remote_cbs_unref)
+
+const git_remote_callbacks *
+_ggit_remote_cbs_get_remote_callbacks (GgitRemoteCbs *remote_cbs)
+{
+       /* NULL is common for remote_cbs as it specifies to use the default
+        * so handle a NULL remote_cbs here instead of in every caller.
+        */
+       if (remote_cbs == NULL)
+       {
+               return NULL;
+       }
+
+       return (const git_remote_callbacks *)&remote_cbs->remote_cbs;
+}
+
+/**
+ * ggit_remote_cbs_ref:
+ * @remote_cbs: a #GgitRemoteCbs.
+ *
+ * Copies @remote_cbs into a newly allocated #GgitRemoteCbs.
+ *
+ * Returns: (transfer full): a newly allocated #GgitRemoteCbs.
+ */
+GgitRemoteCbs *
+ggit_remote_cbs_ref (GgitRemoteCbs *remote_cbs)
+{
+       g_return_val_if_fail (remote_cbs != NULL, NULL);
+
+       g_atomic_int_inc (&remote_cbs->ref_count);
+
+       return remote_cbs;
+}
+
+/**
+ * ggit_remote_cbs_unref:
+ * @remote_cbs: a #GgitRemoteCbs.
+ *
+ * Frees @remote_cbs.
+ */
+void
+ggit_remote_cbs_unref (GgitRemoteCbs *remote_cbs)
+{
+       g_return_if_fail (remote_cbs != NULL);
+
+       if (g_atomic_int_dec_and_test (&remote_cbs->ref_count))
+       {
+               g_slice_free (GgitRemoteCbs, remote_cbs);
+       }
+}
+
+/**
+ * ggit_remote_cbs_new:
+ *
+ * Creates a new #GgitRemoteCbs.
+ *
+ * Returns: a newly allocated #GgitRemoteCbs.
+ */
+GgitRemoteCbs *
+ggit_remote_cbs_new (void)
+{
+       GgitRemoteCbs *remote_cbs;
+       git_remote_callbacks gremote_cbs = GIT_REMOTE_CALLBACKS_INIT;
+
+       remote_cbs = g_slice_new (GgitRemoteCbs);
+       remote_cbs->remote_cbs = gremote_cbs;
+
+       return remote_cbs;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-remote-callbacks.h b/libgit2-glib/ggit-remote-callbacks.h
new file mode 100644
index 0000000..1690b9e
--- /dev/null
+++ b/libgit2-glib/ggit-remote-callbacks.h
@@ -0,0 +1,48 @@
+/*
+ * ggit-remote-callbacks.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - 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_REMOTE_CBS_H__
+#define __GGIT_REMOTE_CBS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_REMOTE_CBS       (ggit_remote_cbs_get_type ())
+#define GGIT_REMOTE_CBS(obj)       ((GgitRemoteCbs *)obj)
+
+GType                      ggit_remote_cbs_get_type            (void) G_GNUC_CONST;
+
+const git_remote_callbacks *_ggit_remote_cbs_get_remote_callbacks  (GgitRemoteCbs        *cbs);
+
+GgitRemoteCbs             *ggit_remote_cbs_ref                 (GgitRemoteCbs        *cbs);
+void                       ggit_remote_cbs_unref               (GgitRemoteCbs        *cbs);
+
+GgitRemoteCbs             *ggit_remote_cbs_new                 (void);
+
+G_END_DECLS
+
+#endif /* __GGIT_REMOTE_CBS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 6f8252b..4768558 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -264,6 +264,13 @@ typedef struct _GgitReflogEntry GgitReflogEntry;
 typedef struct _GgitRemote GgitRemote;
 
 /**
+ * GgitRemoteCbs:
+ *
+ * Represents a git remote callbacks.
+ */
+typedef struct _GgitRemoteCbs GgitRemoteCbs;
+
+/**
  * GgitRepository:
  *
  * Represents an existing git repository including all of it's


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