[libgit2-glib] Added GgitRefSpec
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added GgitRefSpec
- Date: Wed, 13 Jun 2012 15:48:02 +0000 (UTC)
commit db7f2694c7725f98713e709296af03fc467c43b3
Author: Garrett Regier <garrettregier gmail com>
Date: Wed Jun 13 07:40:18 2012 -0700
Added GgitRefSpec
docs/reference/libgit2-glib-1.0-docs.sgml | 1 +
docs/reference/libgit2-glib-1.0-sections.txt | 19 ++++
docs/reference/libgit2-glib-1.0.types | 1 +
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-ref-spec.c | 135 ++++++++++++++++++++++++++
libgit2-glib/ggit-ref-spec.h | 48 +++++++++
libgit2-glib/ggit-remote.c | 105 ++++++++++++++++++++
libgit2-glib/ggit-remote.h | 10 ++
libgit2-glib/ggit-types.h | 7 ++
libgit2-glib/ggit.h | 1 +
10 files changed, 329 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libgit2-glib-1.0-docs.sgml b/docs/reference/libgit2-glib-1.0-docs.sgml
index 84f3daf..d5deaf5 100644
--- a/docs/reference/libgit2-glib-1.0-docs.sgml
+++ b/docs/reference/libgit2-glib-1.0-docs.sgml
@@ -30,6 +30,7 @@
<xi:include href="xml/ggit-object-factory-base.xml"/>
<xi:include href="xml/ggit-oid.xml"/>
<xi:include href="xml/ggit-ref.xml"/>
+ <xi:include href="xml/ggit-ref-spec.xml"/>
<xi:include href="xml/ggit-reflog.xml"/>
<xi:include href="xml/ggit-reflog-entry.xml"/>
<xi:include href="xml/ggit-remote.xml"/>
diff --git a/docs/reference/libgit2-glib-1.0-sections.txt b/docs/reference/libgit2-glib-1.0-sections.txt
index 1bf1c9d..3c703c4 100644
--- a/docs/reference/libgit2-glib-1.0-sections.txt
+++ b/docs/reference/libgit2-glib-1.0-sections.txt
@@ -373,6 +373,21 @@ ggit_ref_get_type
</SECTION>
<SECTION>
+<FILE>ggit-ref-spec</FILE>
+<TITLE>GgitRefSpec</TITLE>
+GgitRefSpec
+ggit_ref_spec_ref
+ggit_ref_spec_unref
+ggit_ref_spec_get_source
+ggit_ref_spec_get_destination
+ggit_ref_spec_is_forced
+<SUBSECTION Standard>
+GGIT_REF_SPEC
+GGIT_TYPE_REF_SPEC
+ggit_ref_spec_get_type
+</SECTION>
+
+<SECTION>
<FILE>ggit-reflog</FILE>
<TITLE>GgitReflog</TITLE>
GgitReflog
@@ -414,6 +429,10 @@ ggit_remote_get_url
ggit_remote_connect
ggit_remote_get_connected
ggit_remote_disconnect
+ggit_remote_set_fetch_spec
+ggit_remote_get_fetch_spec
+ggit_remote_set_push_spec
+ggit_remote_get_push_spec
ggit_remote_is_valid_url
ggit_remote_is_supported_url
<SUBSECTION Standard>
diff --git a/docs/reference/libgit2-glib-1.0.types b/docs/reference/libgit2-glib-1.0.types
index 5c14d96..511ce59 100644
--- a/docs/reference/libgit2-glib-1.0.types
+++ b/docs/reference/libgit2-glib-1.0.types
@@ -18,6 +18,7 @@ ggit_object_factory_get_type
ggit_object_get_type
ggit_oid_get_type
ggit_ref_get_type
+ggit_ref_spec_get_type
ggit_reflog_entry_get_type
ggit_reflog_get_type
ggit_remote_get_type
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index c876793..aec8ce1 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -34,6 +34,7 @@ INST_H_FILES = \
ggit-object-factory-base.h \
ggit-oid.h \
ggit-ref.h \
+ ggit-ref-spec.h \
ggit-reflog.h \
ggit-reflog-entry.h \
ggit-remote.h \
@@ -72,6 +73,7 @@ C_FILES = \
ggit-object-factory-base.c \
ggit-oid.c \
ggit-ref.c \
+ ggit-ref-spec.c \
ggit-reflog.c \
ggit-reflog-entry.c \
ggit-remote.c \
diff --git a/libgit2-glib/ggit-ref-spec.c b/libgit2-glib/ggit-ref-spec.c
new file mode 100644
index 0000000..8c62811
--- /dev/null
+++ b/libgit2-glib/ggit-ref-spec.c
@@ -0,0 +1,135 @@
+/*
+ * ggit-ref-spec.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Garrett Regier
+ *
+ * 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 <glib-object.h>
+#include <git2/refspec.h>
+
+#include "ggit-ref-spec.h"
+
+struct _GgitRefSpec {
+ gint ref_count;
+
+ const git_refspec *refspec;
+};
+
+G_DEFINE_BOXED_TYPE (GgitRefSpec, ggit_ref_spec,
+ ggit_ref_spec_ref, ggit_ref_spec_unref)
+
+
+GgitRefSpec *
+_ggit_ref_spec_wrap (const git_refspec *refspec)
+{
+ GgitRefSpec *grefspec;
+
+ g_return_val_if_fail (refspec != NULL, NULL);
+
+ grefspec = g_slice_new (GgitRefSpec);
+ grefspec->ref_count = 1;
+ grefspec->refspec = refspec;
+
+ return grefspec;
+}
+
+/**
+ * ggit_ref_spec_ref:
+ * @refspec: a #GgitRefSpec.
+ *
+ * Atomically increments the reference count of @refspec by one.
+ * This function is MT-safe and may be called from any thread.
+ *
+ * Returns: a #GgitRefSpec.
+ **/
+GgitRefSpec *
+ggit_ref_spec_ref (GgitRefSpec *refspec)
+{
+ g_return_val_if_fail (refspec != NULL, NULL);
+
+ g_atomic_int_inc (&refspec->ref_count);
+
+ return refspec;
+}
+
+/**
+ * ggit_ref_spec_unref:
+ * @refspec: a #GgitRefSpec.
+ *
+ * Atomically decrements the reference count of @refspec by one.
+ * If the reference count drops to 0, @refspec is freed.
+ **/
+void
+ggit_ref_spec_unref (GgitRefSpec *refspec)
+{
+ g_return_if_fail (refspec != NULL);
+
+ if (g_atomic_int_dec_and_test (&refspec->ref_count))
+ {
+ g_slice_free (GgitRefSpec, refspec);
+ }
+}
+
+/**
+ * ggit_ref_spec_get_source:
+ * @refspec: a #GgitRefSpec.
+ *
+ * Gets the @refspec's source.
+ *
+ * Returns: the refspec's source.
+ */
+const gchar *
+ggit_ref_spec_get_source (GgitRefSpec *refspec)
+{
+ g_return_val_if_fail (refspec != NULL, 0);
+
+ return git_refspec_src (refspec->refspec);
+}
+
+/**
+ * ggit_ref_spec_get_destination:
+ * @refspec: a #GgitRefSpec.
+ *
+ * Gets the @refspec's destination.
+ *
+ * Returns: the refspec's destination.
+ */
+const gchar *
+ggit_ref_spec_get_destination (GgitRefSpec *refspec)
+{
+ g_return_val_if_fail (refspec != NULL, 0);
+
+ return git_refspec_dst (refspec->refspec);
+}
+
+/**
+ * ggit_ref_spec_is_forced:
+ * @refspec: a #GgitRefSpec.
+ *
+ * Whether updating is done forcefully.
+ *
+ * Returns: if updating is done forcefully.
+ */
+gboolean
+ggit_ref_spec_is_forced (GgitRefSpec *refspec)
+{
+ g_return_val_if_fail (refspec != NULL, 0);
+
+ return git_refspec_force (refspec->refspec);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-ref-spec.h b/libgit2-glib/ggit-ref-spec.h
new file mode 100644
index 0000000..c0a6f43
--- /dev/null
+++ b/libgit2-glib/ggit-ref-spec.h
@@ -0,0 +1,48 @@
+/*
+ * ggit-ref-spec.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Garrett Regier
+ *
+ * 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_REF_SPEC_H__
+#define __GGIT_REF_SPEC_H__
+
+#include <git2/refspec.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_REF_SPEC (ggit_ref_spec_get_type ())
+#define GGIT_REF_SPEC(obj) ((GgitRefSpec *)obj)
+
+GType ggit_ref_spec_get_type (void) G_GNUC_CONST;
+
+GgitRefSpec *_ggit_ref_spec_wrap (const git_refspec *refspec);
+
+GgitRefSpec *ggit_ref_spec_ref (GgitRefSpec *refspec);
+void ggit_ref_spec_unref (GgitRefSpec *refspec);
+
+const gchar *ggit_ref_spec_get_source (GgitRefSpec *refspec);
+const gchar *ggit_ref_spec_get_destination (GgitRefSpec *refspec);
+gboolean ggit_ref_spec_is_forced (GgitRefSpec *refspec);
+
+G_END_DECLS
+
+#endif /* __GGIT_REF_SPEC_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-remote.c b/libgit2-glib/ggit-remote.c
index 8bf5fb2..485eb43 100644
--- a/libgit2-glib/ggit-remote.c
+++ b/libgit2-glib/ggit-remote.c
@@ -22,6 +22,7 @@
#include "ggit-remote.h"
#include "ggit-error.h"
+#include "ggit-ref-spec.h"
struct _GgitRemote
@@ -199,6 +200,110 @@ ggit_remote_disconnect (GgitRemote *remote)
}
/**
+ * ggit_remote_set_fetch_spec:
+ * @remote: a #GgitRemote.
+ * @fetch_spec: the fetch refspec.
+ * @error: a #GError or %NULL.
+ *
+ * Sets @remote's fetch spec to @fetch_spec.
+ */
+void
+ggit_remote_set_fetch_spec (GgitRemote *remote,
+ const gchar *fetch_spec,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (remote != NULL);
+ g_return_if_fail (fetch_spec != NULL && fetch_spec[0] != '\0');
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_remote_set_fetchspec (remote->remote, fetch_spec);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_remote_get_fetch_spec:
+ * @remote: a #GgitRemote.
+ *
+ * Gets @remote's fetch spec.
+ *
+ * Returns: the fetch spec of the remote, or %NULL.
+ */
+GgitRefSpec *
+ggit_remote_get_fetch_spec (GgitRemote *remote)
+{
+ const git_refspec *refspec;
+
+ g_return_val_if_fail (remote != NULL, NULL);
+
+ refspec = git_remote_fetchspec (remote->remote);
+
+ if (refspec == NULL)
+ {
+ return NULL;
+ }
+
+ return _ggit_ref_spec_wrap (refspec);
+}
+
+/**
+ * ggit_remote_set_push_spec:
+ * @remote: a #GgitRemote.
+ * @push_spec: the push refspec.
+ * @error: a #GError or %NULL.
+ *
+ * Sets @remote's push spec to @fetch_spec.
+ */
+void
+ggit_remote_set_push_spec (GgitRemote *remote,
+ const gchar *push_spec,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (remote != NULL);
+ g_return_if_fail (push_spec != NULL && push_spec[0] != '\0');
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_remote_set_pushspec (remote->remote, push_spec);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_remote_get_push_spec:
+ * @remote: a #GgitRemote.
+ *
+ * Gets @remote's push spec.
+ *
+ * Returns: the push spec of the remote, or %NULL.
+ */
+GgitRefSpec *
+ggit_remote_get_push_spec (GgitRemote *remote)
+{
+ const git_refspec *refspec;
+
+ g_return_val_if_fail (remote != NULL, NULL);
+
+ refspec = git_remote_pushspec (remote->remote);
+
+ if (refspec == NULL)
+ {
+ return NULL;
+ }
+
+ return _ggit_ref_spec_wrap (refspec);
+}
+
+/**
* ggit_remote_is_valid_url:
* @url: a url string.
*
diff --git a/libgit2-glib/ggit-remote.h b/libgit2-glib/ggit-remote.h
index bce6681..10c3624 100644
--- a/libgit2-glib/ggit-remote.h
+++ b/libgit2-glib/ggit-remote.h
@@ -53,6 +53,16 @@ gboolean ggit_remote_get_connected (GgitRemote *remot
void ggit_remote_disconnect (GgitRemote *remote);
+void ggit_remote_set_fetch_spec (GgitRemote *remote,
+ const gchar *fetch_spec,
+ GError **error);
+GgitRefSpec *ggit_remote_get_fetch_spec (GgitRemote *remote);
+
+void ggit_remote_set_push_spec (GgitRemote *remote,
+ const gchar *push_spec,
+ GError **error);
+GgitRefSpec *ggit_remote_get_push_spec (GgitRemote *remote);
+
gboolean ggit_remote_is_valid_url (const gchar *url);
gboolean ggit_remote_is_supported_url (const gchar *url);
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 57de29f..c0dff75 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -166,6 +166,13 @@ typedef struct _GgitOId GgitOId;
typedef struct _GgitRef GgitRef;
/**
+ * GgitRefSpec:
+ *
+ * Reprensents a git reference specification.
+ */
+typedef struct _GgitRefSpec GgitRefSpec;
+
+/**
* GgitReflog:
*
* Represents a reflog.
diff --git a/libgit2-glib/ggit.h b/libgit2-glib/ggit.h
index c94c1f3..171d003 100644
--- a/libgit2-glib/ggit.h
+++ b/libgit2-glib/ggit.h
@@ -40,6 +40,7 @@
#include <libgit2-glib/ggit-object-factory-base.h>
#include <libgit2-glib/ggit-oid.h>
#include <libgit2-glib/ggit-ref.h>
+#include <libgit2-glib/ggit-ref-spec.h>
#include <libgit2-glib/ggit-reflog.h>
#include <libgit2-glib/ggit-reflog-entry.h>
#include <libgit2-glib/ggit-remote.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]