[libgit2-glib] Implement diff patch using GString
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Implement diff patch using GString
- Date: Sat, 29 Jun 2013 15:44:28 +0000 (UTC)
commit 068efc05dab74c669555b4989323d03639172775
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Jun 29 17:44:17 2013 +0200
Implement diff patch using GString
libgit2-glib/ggit-diff-patch.c | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/libgit2-glib/ggit-diff-patch.c b/libgit2-glib/ggit-diff-patch.c
index 47c70b8..d52d5de 100644
--- a/libgit2-glib/ggit-diff-patch.c
+++ b/libgit2-glib/ggit-diff-patch.c
@@ -80,6 +80,20 @@ ggit_diff_patch_unref (GgitDiffPatch *diff_patch)
}
}
+static int
+patch_to_string (const git_diff_delta *delta,
+ const git_diff_range *range,
+ char line_origin,
+ const char *content,
+ size_t content_len,
+ void *payload)
+{
+ GString *s = payload;
+
+ g_string_append_len (s, content, content_len);
+ return content_len;
+}
+
/**
* ggit_diff_patch_to_string:
* @diff_patch: a #GgitDiffPatch.
@@ -93,24 +107,25 @@ gchar *
ggit_diff_patch_to_string (GgitDiffPatch *diff_patch,
GError **error)
{
- gchar *str;
gint ret;
- gchar *gstr;
+ GString *s;
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);
+ s = g_string_new ("");
+
+ ret = git_diff_patch_print (diff_patch->diff_patch,
+ patch_to_string,
+ s);
if (ret != GIT_OK)
{
+ g_string_free (s, TRUE);
return NULL;
}
- gstr = g_strdup (str);
- free (str);
-
- return gstr;
+ return g_string_free (s, FALSE);
}
typedef struct
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]