[libgit2-glib] Basic wrapping for GgitNote
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Basic wrapping for GgitNote
- Date: Sat, 18 Oct 2014 10:43:07 +0000 (UTC)
commit cd18205884b0ef6ad93ca75cb4ebcce25e89a3eb
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sat Oct 18 11:40:56 2014 +0200
Basic wrapping for GgitNote
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-note.c | 121 ++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-note.h | 49 +++++++++++++++
libgit2-glib/ggit-repository.c | 127 ++++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-repository.h | 19 ++++++
libgit2-glib/ggit-types.h | 7 ++
6 files changed, 325 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index db2d17c..51fcc7d 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -47,6 +47,7 @@ INST_H_FILES = \
ggit-message.h \
ggit-merge-options.h \
ggit-native.h \
+ ggit-note.h \
ggit-object.h \
ggit-object-factory.h \
ggit-object-factory-base.h \
@@ -111,6 +112,7 @@ C_FILES = \
ggit-message.c \
ggit-merge-options.c \
ggit-native.c \
+ ggit-note.c \
ggit-object.c \
ggit-object-factory.c \
ggit-object-factory-base.c \
diff --git a/libgit2-glib/ggit-note.c b/libgit2-glib/ggit-note.c
new file mode 100644
index 0000000..8c494dc
--- /dev/null
+++ b/libgit2-glib/ggit-note.c
@@ -0,0 +1,121 @@
+/*
+ * ggit-note.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - 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 "ggit-note.h"
+#include "ggit-oid.h"
+
+struct _GgitNote
+{
+ gint ref_count;
+
+ git_note *note;
+ GgitOId *id;
+};
+
+G_DEFINE_BOXED_TYPE (GgitNote, ggit_note,
+ ggit_note_ref, ggit_note_unref)
+
+GgitNote *
+_ggit_note_wrap (git_note *note)
+{
+ GgitNote *gnote;
+
+ g_return_val_if_fail (note != NULL, NULL);
+
+ gnote = g_slice_new (GgitNote);
+ gnote->ref_count = 1;
+ gnote->note = note;
+ gnote->id = _ggit_oid_wrap (git_note_id (note));
+
+ return gnote;
+}
+
+/**
+ * ggit_note_ref:
+ * @note: a #GgitNote.
+ *
+ * Atomically increments the reference count of @note by one.
+ * This function is MT-safe and may be called from any thread.
+ *
+ * Returns: a #GgitNote.
+ **/
+GgitNote *
+ggit_note_ref (GgitNote *note)
+{
+ g_return_val_if_fail (note != NULL, NULL);
+
+ g_atomic_int_inc (¬e->ref_count);
+
+ return note;
+}
+
+/**
+ * ggit_note_unref:
+ * @note: a #GgitNote.
+ *
+ * Atomically decrements the reference count of @note by one.
+ * If the reference count drops to 0, @note is freed.
+ **/
+void
+ggit_note_unref (GgitNote *note)
+{
+ g_return_if_fail (note != NULL);
+
+ if (g_atomic_int_dec_and_test (¬e->ref_count))
+ {
+ git_note_free (note->note);
+ ggit_oid_free (note->id);
+ g_slice_free (GgitNote, note);
+ }
+}
+
+/**
+ * ggit_note_get_message:
+ * @note: a #GgitNote.
+ *
+ * Gets the note message.
+ *
+ * Returns: the note message.
+ */
+const gchar *
+ggit_note_get_message (GgitNote *note)
+{
+ g_return_val_if_fail (note != NULL, NULL);
+
+ return git_note_message (note->note);
+}
+
+/**
+ * ggit_note_get_id:
+ * @note: a #GgitNote.
+ *
+ * Gets the note object's id.
+ *
+ * Returns: (transfer none): the object's id.
+ */
+GgitOId *
+ggit_note_get_id (GgitNote *note)
+{
+ g_return_val_if_fail (note != NULL, NULL);
+
+ return note->id;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-note.h b/libgit2-glib/ggit-note.h
new file mode 100644
index 0000000..6b69b91
--- /dev/null
+++ b/libgit2-glib/ggit-note.h
@@ -0,0 +1,49 @@
+/*
+ * ggit-note.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - 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_NOTE_H__
+#define __GGIT_NOTE_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_NOTE (ggit_note_get_type ())
+#define GGIT_NOTE(obj) ((GgitNote *)obj)
+
+GType ggit_note_get_type (void) G_GNUC_CONST;
+
+GgitNote *_ggit_note_wrap (git_note *note);
+
+GgitNote *ggit_note_ref (GgitNote *note);
+void ggit_note_unref (GgitNote *note);
+
+const gchar *ggit_note_get_message (GgitNote *note);
+
+GgitOId *ggit_note_get_id (GgitNote *note);
+
+G_END_DECLS
+
+#endif /* __GGIT_NOTE_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index cc22c03..72eb2fb 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -2992,4 +2992,131 @@ ggit_repository_cherry_pick_commit (GgitRepository *repository,
return _ggit_index_wrap (idx);
}
+/**
+ * ggit_repository_get_default_notes_ref:
+ * @repository: a #GgitRepository.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Gets the default notes reference for @repository.
+ *
+ * Returns: the default notes reference for @repository.
+ */
+const gchar *
+ggit_repository_get_default_notes_ref (GgitRepository *repository,
+ GError **error)
+{
+ const gchar *ref = NULL;
+ gint ret;
+
+ g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_note_default_ref (&ref, _ggit_native_get (repository));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+
+ return ref;
+}
+
+/**
+ * ggit_repository_create_note:
+ * @repository: a #GgitRepository.
+ * @author: author signature.
+ * @committer: committer signature.
+ * @notes_ref: (allow-none): canonical name of the reference to use, or %NULL to use the default ref.
+ * @id: OID of the git object to decorate.
+ * @note: content of the note to add for object oid.
+ * @force: whether to overwrite existing note.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Adds a note for an object.
+ *
+ * Returns: (transfer full): the OID for the note or %NULL in case of error.
+ */
+GgitOId *
+ggit_repository_create_note (GgitRepository *repository,
+ GgitSignature *author,
+ GgitSignature *committer,
+ const gchar *notes_ref,
+ GgitOId *id,
+ const gchar *note,
+ gboolean force,
+ GError **error)
+{
+ gint ret;
+ git_oid oid;
+
+ g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), NULL);
+ g_return_val_if_fail (GGIT_IS_SIGNATURE (author), NULL);
+ g_return_val_if_fail (GGIT_IS_SIGNATURE (committer), NULL);
+ g_return_val_if_fail (id != NULL, NULL);
+ g_return_val_if_fail (note != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_note_create (&oid,
+ _ggit_native_get (repository),
+ _ggit_native_get (author),
+ _ggit_native_get (committer),
+ notes_ref,
+ _ggit_oid_get_oid (id),
+ note,
+ force);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+
+ return _ggit_oid_wrap (&oid);
+}
+
+/**
+ * ggit_repository_remove_note:
+ * @repository: a #GgitRepository.
+ * @notes_ref: (allow-none): canonical name of the reference to use, or %NULL to use the default ref.
+ * @author: author signature.
+ * @committer: committer signature.
+ * @id: OID of the git object to decorate.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Removes the note for an object.
+ *
+ * Returns: %TRUE if the note was removed from @id.
+ */
+gboolean
+ggit_repository_remove_note (GgitRepository *repository,
+ const gchar *notes_ref,
+ GgitSignature *author,
+ GgitSignature *committer,
+ GgitOId *id,
+ GError **error)
+{
+ gint ret;
+
+ g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+ g_return_val_if_fail (GGIT_IS_SIGNATURE (author), FALSE);
+ g_return_val_if_fail (GGIT_IS_SIGNATURE (committer), FALSE);
+ g_return_val_if_fail (id != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_note_remove (_ggit_native_get (repository),
+ notes_ref,
+ _ggit_native_get (author),
+ _ggit_native_get (committer),
+ _ggit_oid_get_oid (id));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 0931878..a0ca2b8 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -387,6 +387,25 @@ GgitIndex *ggit_repository_cherry_pick_commit (GgitRepository
GgitMergeOptions *merge_options,
GError **error);
+const gchar *ggit_repository_get_default_notes_ref (GgitRepository *repository,
+ GError **error);
+
+GgitOId *ggit_repository_create_note (GgitRepository *repository,
+ GgitSignature *author,
+ GgitSignature *committer,
+ const gchar *notes_ref,
+ GgitOId *id,
+ const gchar *note,
+ gboolean force,
+ GError **error);
+
+gboolean ggit_repository_remove_note (GgitRepository *repository,
+ const gchar *notes_ref,
+ GgitSignature *author,
+ GgitSignature *committer,
+ GgitOId *id,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_REPOSITORY_H__ */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 85e4872..47697f0 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -243,6 +243,13 @@ typedef struct _GgitMergeOptions GgitMergeOptions;
typedef struct _GgitNative GgitNative;
/**
+ * GgitNote:
+ *
+ * Represents a note object.
+ */
+typedef struct _GgitNote GgitNote;
+
+/**
* GgitObject:
*
* Represents a generic object in a repository.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]