[libgit2-glib] Added ggit_index_entry_set_commit
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added ggit_index_entry_set_commit
- Date: Sun, 14 Dec 2014 09:56:11 +0000 (UTC)
commit 0156991832b6fd7d1365c3e9de71d1085dc16882
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sun Dec 14 10:55:49 2014 +0100
Added ggit_index_entry_set_commit
libgit2-glib/ggit-index-entry.c | 37 +++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-index-entry.h | 3 +++
2 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/ggit-index-entry.c b/libgit2-glib/ggit-index-entry.c
index 81d43e9..f0cf00b 100644
--- a/libgit2-glib/ggit-index-entry.c
+++ b/libgit2-glib/ggit-index-entry.c
@@ -21,6 +21,8 @@
#include "ggit-index-entry.h"
#include "ggit-index.h"
#include "ggit-repository.h"
+#include "ggit-commit.h"
+#include "ggit-signature.h"
#include <string.h>
@@ -775,6 +777,41 @@ ggit_index_entry_stat (GgitIndexEntry *entry,
return TRUE;
}
+/**
+ * ggit_index_entry_set_commit:
+ * @entry: a #GgitIndexEntry.
+ * @commit: a #GgitCommit.
+ *
+ * Set the index entry to point to a given commit. This sets the index entry
+ * id to the commit id, changes the mode to #GGIT_FILE_MODE_COMMIT and updates
+ * the timestamps to when the commit was made.
+ *
+ **/
+void
+ggit_index_entry_set_commit (GgitIndexEntry *entry,
+ GgitCommit *commit)
+{
+ GgitSignature *sig;
+ gint64 ut;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (GGIT_IS_COMMIT (commit));
+
+ ggit_index_entry_set_id (entry, ggit_object_get_id (GGIT_OBJECT (commit)));
+ ggit_index_entry_set_mode (entry, GIT_FILEMODE_COMMIT);
+
+ sig = ggit_commit_get_committer (commit);
+ ut = g_date_time_to_unix (ggit_signature_get_time (sig));
+
+ entry->entry->ctime.seconds = ut;
+ entry->entry->ctime.nanoseconds = 0;
+
+ entry->entry->mtime.seconds = ut;
+ entry->entry->mtime.nanoseconds = 0;
+
+ g_object_unref (sig);
+}
+
const git_index_entry *
_ggit_index_entry_get_native (GgitIndexEntry *entry)
{
diff --git a/libgit2-glib/ggit-index-entry.h b/libgit2-glib/ggit-index-entry.h
index 0f4935e..8e6ec0f 100644
--- a/libgit2-glib/ggit-index-entry.h
+++ b/libgit2-glib/ggit-index-entry.h
@@ -98,6 +98,9 @@ gboolean ggit_index_entry_stat (GgitIndexEntry *entry,
GFile *file,
GError **error);
+void ggit_index_entry_set_commit (GgitIndexEntry *entry,
+ GgitCommit *commit);
+
const git_index_entry
*_ggit_index_entry_get_native (GgitIndexEntry *entry);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]