[libgit2-glib] Added ggit_diff_patch_to_stream
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added ggit_diff_patch_to_stream
- Date: Sat, 29 Jun 2013 15:34:26 +0000 (UTC)
commit 9421d6116add67ab89c444e69519f2603700e595
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Jun 29 17:34:14 2013 +0200
Added ggit_diff_patch_to_stream
libgit2-glib/ggit-diff-patch.c | 80 ++++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-diff-patch.h | 5 ++
2 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/ggit-diff-patch.c b/libgit2-glib/ggit-diff-patch.c
index 52411f6..47c70b8 100644
--- a/libgit2-glib/ggit-diff-patch.c
+++ b/libgit2-glib/ggit-diff-patch.c
@@ -19,6 +19,7 @@
*/
#include "ggit-diff-patch.h"
+#include "ggit-error.h"
struct _GgitDiffPatch
{
@@ -97,6 +98,7 @@ ggit_diff_patch_to_string (GgitDiffPatch *diff_patch,
gchar *gstr;
g_return_val_if_fail (diff_patch != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
ret = git_diff_patch_to_str (&str, diff_patch->diff_patch);
@@ -111,4 +113,82 @@ ggit_diff_patch_to_string (GgitDiffPatch *diff_patch,
return gstr;
}
+typedef struct
+{
+ GOutputStream *stream;
+ GError **error;
+} PatchToStream;
+
+static int
+patch_to_stream (const git_diff_delta *delta,
+ const git_diff_range *range,
+ char line_origin,
+ const char *content,
+ size_t content_len,
+ void *payload)
+{
+ PatchToStream *info = payload;
+ gboolean ret;
+ gsize written;
+
+ ret = g_output_stream_write_all (info->stream,
+ content,
+ content_len,
+ &written,
+ NULL,
+ info->error);
+
+ if (!ret)
+ {
+ return -1;
+ }
+ else
+ {
+ return written;
+ }
+}
+
+/**
+ * ggit_diff_patch_to_stream:
+ * @diff_patch: a #GgitDiffPatch.
+ * @stream: a #GOutputStream.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Write the contents of a patch to the provided stream.
+ *
+ * Returns: %TRUE if the patch was written successfully, %FALSE otherwise.
+ *
+ **/
+gboolean
+ggit_diff_patch_to_stream (GgitDiffPatch *diff_patch,
+ GOutputStream *stream,
+ GError **error)
+{
+ PatchToStream info;
+ gint ret;
+
+ g_return_val_if_fail (diff_patch != NULL, FALSE);
+ g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ info.stream = stream;
+ info.error = error;
+
+ ret = git_diff_patch_print (diff_patch->diff_patch,
+ patch_to_stream,
+ &info);
+
+ if (ret != GIT_OK)
+ {
+ if (error != NULL && *error == NULL)
+ {
+ _ggit_error_set (error, ret);
+ }
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-diff-patch.h b/libgit2-glib/ggit-diff-patch.h
index 2a6dde7..b7eccb0 100644
--- a/libgit2-glib/ggit-diff-patch.h
+++ b/libgit2-glib/ggit-diff-patch.h
@@ -22,6 +22,7 @@
#define __GGIT_DIFF_PATCH_H__
#include <glib-object.h>
+#include <gio/gio.h>
#include <git2.h>
#include "ggit-types.h"
@@ -41,6 +42,10 @@ void ggit_diff_patch_unref (GgitDiffPatch *diff_patch);
gchar *ggit_diff_patch_to_string (GgitDiffPatch *diff_patch,
GError **error);
+gboolean ggit_diff_patch_to_stream (GgitDiffPatch *diff_patch,
+ GOutputStream *stream,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_DIFF_PATCH_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]