[libgit2-glib] Reorganize reflog
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Reorganize reflog
- Date: Fri, 5 Jul 2013 13:43:14 +0000 (UTC)
commit d925cd469438fe8ca760e8ce8402185081b88b91
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Fri Jul 5 14:27:13 2013 +0200
Reorganize reflog
libgit2-glib/ggit-ref.c | 73 +---------------------------
libgit2-glib/ggit-ref.h | 9 +---
libgit2-glib/ggit-reflog.c | 113 +++++++++++++++++++++++++++++++++++++++++++-
libgit2-glib/ggit-reflog.h | 26 ++++++++--
4 files changed, 136 insertions(+), 85 deletions(-)
---
diff --git a/libgit2-glib/ggit-ref.c b/libgit2-glib/ggit-ref.c
index 3764634..7824297 100644
--- a/libgit2-glib/ggit-ref.c
+++ b/libgit2-glib/ggit-ref.c
@@ -427,7 +427,8 @@ ggit_ref_has_reflog (GgitRef *ref)
* @ref: a #GgitRef.
* @error: a #GError for error reporting, or %NULL.
*
- * Gets the #GgitReflog for @ref.
+ * Gets the #GgitReflog for @ref. The reflog will be created if it doesn't exist
+ * yet.
*
* Returns: (transfer full): the reflog.
*/
@@ -449,75 +450,7 @@ ggit_ref_get_reflog (GgitRef *ref,
return NULL;
}
- return _ggit_reflog_wrap (reflog);
-}
-
-/**
- * ggit_ref_create_reflog:
- * @ref: a #GgitRef.
- * @oid: a #GgitOId.
- * @committer: a #GgitSignature.
- * @message: the message.
- * @error: a #GError for error reporting, or %NULL.
- *
- * Creates a #GgitReflog with the given properties.
- *
- * Returns: (transfer full): the created reflog, or %NULL if error is set.
- */
-GgitReflog *
-ggit_ref_create_reflog (GgitRef *ref,
- GgitOId *oid,
- GgitSignature *committer,
- const gchar *message,
- GError **error)
-{
- gint ret;
-
- g_return_val_if_fail (GGIT_IS_REF (ref), NULL);
- g_return_val_if_fail (oid != NULL, NULL);
- g_return_val_if_fail (GGIT_IS_SIGNATURE (committer), NULL);
- g_return_val_if_fail (message != NULL && *message != '\0', NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- ret = git_reflog_append (_ggit_native_get (ref),
- _ggit_oid_get_oid (oid),
- _ggit_native_get (committer),
- message);
-
- if (ret != GIT_OK)
- {
- _ggit_error_set (error, ret);
- return NULL;
- }
-
- return ggit_ref_get_reflog (ref, error);
-}
-
-/**
- * ggit_ref_rename_reflog:
- * @ref: a #GgitRef.
- * @new_name: the new name of the reference.
- * @error: a #GError for error reporting, or %NULL.
- *
- * Renames the reflog for @ref to @new_name, on error @error is set.
- */
-void
-ggit_ref_rename_reflog (GgitRef *ref,
- const gchar *new_name,
- GError **error)
-{
- gint ret;
-
- g_return_if_fail (GGIT_IS_REF (ref));
- g_return_if_fail (new_name != NULL && *new_name != '\0');
- g_return_if_fail (error == NULL || *error == NULL);
-
- ret = git_reflog_rename (_ggit_native_get (ref), new_name);
-
- if (ret != GIT_OK)
- {
- _ggit_error_set (error, ret);
- }
+ return _ggit_reflog_wrap (ref, reflog);
}
/**
diff --git a/libgit2-glib/ggit-ref.h b/libgit2-glib/ggit-ref.h
index 1803bf8..f122721 100644
--- a/libgit2-glib/ggit-ref.h
+++ b/libgit2-glib/ggit-ref.h
@@ -99,14 +99,7 @@ gboolean ggit_ref_has_reflog (GgitRef *ref);
GgitReflog *ggit_ref_get_reflog (GgitRef *ref,
GError **error);
-GgitReflog *ggit_ref_create_reflog (GgitRef *ref,
- GgitOId *oid,
- GgitSignature *committer,
- const gchar *message,
- GError **error);
-void ggit_ref_rename_reflog (GgitRef *ref,
- const gchar *new_name,
- GError **error);
+
void ggit_ref_delete_reflog (GgitRef *ref,
GError **error);
diff --git a/libgit2-glib/ggit-reflog.c b/libgit2-glib/ggit-reflog.c
index 4f893f2..1d0f2db 100644
--- a/libgit2-glib/ggit-reflog.c
+++ b/libgit2-glib/ggit-reflog.c
@@ -21,9 +21,14 @@
#include "ggit-reflog.h"
#include "ggit-reflog-entry.h"
+#include "ggit-native.h"
+#include "ggit-error.h"
+#include "ggit-signature.h"
+#include "ggit-oid.h"
struct _GgitReflog
{
+ GgitRef *ref;
git_reflog *reflog;
gint ref_count;
};
@@ -31,12 +36,14 @@ struct _GgitReflog
G_DEFINE_BOXED_TYPE (GgitReflog, ggit_reflog, ggit_reflog_ref, ggit_reflog_unref)
GgitReflog *
-_ggit_reflog_wrap (git_reflog *reflog)
+_ggit_reflog_wrap (GgitRef *ref,
+ git_reflog *reflog)
{
GgitReflog *greflog;
greflog = g_slice_new (GgitReflog);
greflog->reflog = reflog;
+ greflog->ref = g_object_ref (ref);
greflog->ref_count = 1;
return greflog;
@@ -75,12 +82,44 @@ ggit_reflog_unref (GgitReflog *reflog)
if (g_atomic_int_dec_and_test (&reflog->ref_count))
{
+ g_object_unref (reflog->ref);
+
git_reflog_free (reflog->reflog);
g_slice_free (GgitReflog, reflog);
}
}
/**
+ * ggit_reflog_write:
+ * @reflog: a #GgitReflog.
+ * @error: a #GError.
+ *
+ * Write the reflog to disk.
+ *
+ * Returns: %TRUE if the reflog was successfully written, or %FALSE on error.
+ *
+ **/
+gboolean
+ggit_reflog_write (GgitReflog *reflog,
+ GError **error)
+{
+ gint ret;
+
+ g_return_val_if_fail (reflog != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_reflog_write (reflog->reflog);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* ggit_reflog_get_entry_count:
* @reflog: a #GgitReflog.
*
@@ -123,4 +162,76 @@ ggit_reflog_get_entry_from_index (GgitReflog *reflog,
return _ggit_reflog_entry_wrap (reflog_entry);
}
+
+/**
+ * ggit_reflog_rename:
+ * @reflog: a #GgitReflog.
+ * @new_name: the new name of the reference.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Renames the reflog for to @new_name, on error @error is set.
+ */
+gboolean
+ggit_reflog_rename (GgitReflog *reflog,
+ const gchar *new_name,
+ GError **error)
+{
+ gint ret;
+
+ g_return_val_if_fail (reflog != NULL, FALSE);
+ g_return_val_if_fail (new_name != NULL && *new_name != '\0', FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_reflog_rename (_ggit_native_get (reflog->ref), new_name);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * ggit_reflog_append:
+ * @reflog: a #GgitReflog.
+ * @oid: a #GgitOId.
+ * @committer: a #GgitSignature.
+ * @message: the message.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Creates a reflog entry.
+ *
+ * Returns: %TRUE if the reflog was successfully created, or %FALSE if error is set.
+ */
+gboolean
+ggit_reflog_append (GgitReflog *reflog,
+ GgitOId *oid,
+ GgitSignature *committer,
+ const gchar *message,
+ GError **error)
+{
+ gint ret;
+
+ g_return_val_if_fail (reflog != NULL, FALSE);
+ g_return_val_if_fail (oid != NULL, FALSE);
+ g_return_val_if_fail (GGIT_IS_SIGNATURE (committer), FALSE);
+ g_return_val_if_fail (message != NULL && *message != '\0', FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_reflog_append (reflog->reflog,
+ _ggit_oid_get_oid (oid),
+ _ggit_native_get (committer),
+ message);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-reflog.h b/libgit2-glib/ggit-reflog.h
index a4e5bff..de5ec55 100644
--- a/libgit2-glib/ggit-reflog.h
+++ b/libgit2-glib/ggit-reflog.h
@@ -32,14 +32,28 @@ G_BEGIN_DECLS
GType ggit_reflog_get_type (void) G_GNUC_CONST;
-GgitReflog *_ggit_reflog_wrap (git_reflog *reflog);
+GgitReflog *_ggit_reflog_wrap (GgitRef *ref,
+ git_reflog *reflog);
-GgitReflog *ggit_reflog_ref (GgitReflog *reflog);
-void ggit_reflog_unref (GgitReflog *reflog);
+GgitReflog *ggit_reflog_ref (GgitReflog *reflog);
+void ggit_reflog_unref (GgitReflog *reflog);
-guint ggit_reflog_get_entry_count (GgitReflog *reflog);
-GgitReflogEntry *ggit_reflog_get_entry_from_index (GgitReflog *reflog,
- guint idx);
+guint ggit_reflog_get_entry_count (GgitReflog *reflog);
+GgitReflogEntry *ggit_reflog_get_entry_from_index (GgitReflog *reflog,
+ guint idx);
+
+gboolean ggit_reflog_write (GgitReflog *reflog,
+ GError **error);
+
+gboolean ggit_reflog_rename (GgitReflog *reflog,
+ const gchar *new_name,
+ GError **error);
+
+gboolean ggit_reflog_append (GgitReflog *reflog,
+ GgitOId *oid,
+ GgitSignature *committer,
+ const gchar *message,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]