summaryrefslogtreecommitdiff
path: root/src/diff_print.c
diff options
context:
space:
mode:
authorNicolas Hake <nh@nosebud.de>2014-01-22 13:22:15 +0100
committerNicolas Hake <nh@nosebud.de>2014-01-22 13:40:19 +0100
commit450e8e9e623b8c172ba4628c146838cbf4c56519 (patch)
tree06955fb7138124824950dfe04436a10678a1b50c /src/diff_print.c
parentaf2b969b6f63dafa8c55b88cadbcc7631c2dd30b (diff)
downloadlibgit2-450e8e9e623b8c172ba4628c146838cbf4c56519.tar.gz
Expose patch serialization to git_buf
Returning library-allocated strings from libgit2 works fine on Linux, but may cause problems on Windows because there is no one C Runtime that everything links against. With libgit2 not exposing its own allocator, freeing the string is a gamble. git_patch_to_str already serializes to a buffer, then returns the underlying memory. Expose the functionality directly, so callers can use the git_buf_free function to free the memory later.
Diffstat (limited to 'src/diff_print.c')
-rw-r--r--src/diff_print.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/diff_print.c b/src/diff_print.c
index 7a70e2b18..0ab21d033 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -452,7 +452,15 @@ static int diff_print_to_buffer_cb(
return git_buf_put(output, line->content, line->content_len);
}
-/* print a git_patch to a string buffer */
+/* print a git_patch to a git_buf */
+int git_patch_to_buf(
+ git_buf *out,
+ git_patch *patch)
+{
+ return git_patch_print(patch, diff_print_to_buffer_cb, out);
+}
+
+/* print a git_patch to a char* */
int git_patch_to_str(
char **string,
git_patch *patch)
@@ -460,7 +468,7 @@ int git_patch_to_str(
int error;
git_buf output = GIT_BUF_INIT;
- if (!(error = git_patch_print(patch, diff_print_to_buffer_cb, &output)))
+ if (!(error = git_patch_to_buf(&output, patch)))
*string = git_buf_detach(&output);
else {
git_buf_free(&output);