[libgit2-glib] Bind blame buffer
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Bind blame buffer
- Date: Mon, 25 Nov 2013 12:01:55 +0000 (UTC)
commit 46ee05a77f840599fa98a3352a11b472ca4a039f
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Mon Nov 25 13:01:46 2013 +0100
Bind blame buffer
libgit2-glib/ggit-blame.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-
libgit2-glib/ggit-blame.h | 5 ++++
2 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/libgit2-glib/ggit-blame.c b/libgit2-glib/ggit-blame.c
index ae8e240..6891991 100644
--- a/libgit2-glib/ggit-blame.c
+++ b/libgit2-glib/ggit-blame.c
@@ -21,6 +21,7 @@
#include "ggit-blame.h"
#include "ggit-oid.h"
#include "ggit-signature.h"
+#include "ggit-error.h"
struct _GgitBlameHunk
{
@@ -338,4 +339,49 @@ ggit_blame_get_hunk_by_index (GgitBlame *blame,
return ggit_blame_hunk_wrap (git_blame_get_hunk_byindex (_ggit_native_get (blame),
idx));
-}
+}
+
+/**
+ * ggit_blame_from_buffer:
+ * @blame: a #GgitBlame.
+ * @buffer: (array length=buffer_length): the contents of the file.
+ * @buffer_length: the length of the buffer.
+ * @error: a #GError.
+ *
+ * Get blame data for a file that has been modified in memory. @blame is a
+ * pre-calculated blame for the in-odb history of the file. This means that once
+ * a file blame is completed (which can be expensitve), updating the buffer
+ * blame is very fast.
+ *
+ * Lines that differ between the buffer and the committed version are marked as
+ * having a zero id for their #ggit_blame_hunk_get_final_commit_id.
+ *
+ * Returns: (transfer full): a #GgitBlame.
+ *
+ **/
+GgitBlame *
+ggit_blame_from_buffer (GgitBlame *blame,
+ guint8 const *buffer,
+ gsize buffer_length,
+ GError **error)
+{
+ git_blame *gblame;
+ int ret;
+
+ g_return_val_if_fail (GGIT_IS_BLAME (blame), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ ret = git_blame_buffer (&gblame,
+ _ggit_native_get (blame),
+ (const char *)buffer,
+ buffer_length);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+
+ return _ggit_blame_wrap (gblame);
+}
+
diff --git a/libgit2-glib/ggit-blame.h b/libgit2-glib/ggit-blame.h
index cc562b2..2eb3f02 100644
--- a/libgit2-glib/ggit-blame.h
+++ b/libgit2-glib/ggit-blame.h
@@ -82,6 +82,11 @@ GgitBlameHunk *ggit_blame_get_hunk_by_line (GgitBlame *blame,
GgitBlameHunk *ggit_blame_get_hunk_by_index (GgitBlame *blame,
guint32 idx);
+GgitBlame *ggit_blame_from_buffer (GgitBlame *blame,
+ const guint8 *buffer,
+ gsize buffer_length,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_BLAME_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]