From c05cd7924d2409741bb4cb1eb3ba843bea7ec4a2 Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Wed, 22 Jan 2014 17:51:32 +0100 Subject: Drop git_patch_to_str It's hard or even impossible to correctly free the string buffer allocated by git_patch_to_str in some circumstances. Drop the function so people have to use git_patch_to_buf instead - git_buf has a dedicated destructor. --- tests/diff/submodules.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tests/diff/submodules.c') diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c index 24545b2c7..da96ba9c5 100644 --- a/tests/diff/submodules.c +++ b/tests/diff/submodules.c @@ -13,13 +13,15 @@ void test_diff_submodules__cleanup(void) { } +#define get_buf_ptr(buf) ((buf)->asize ? (buf)->ptr : NULL) + static void check_diff_patches_at_line( git_diff *diff, const char **expected, const char *file, int line) { const git_diff_delta *delta; git_patch *patch = NULL; size_t d, num_d = git_diff_num_deltas(diff); - char *patch_text; + git_buf buf = GIT_BUF_INIT; for (d = 0; d < num_d; ++d, git_patch_free(patch)) { cl_git_pass(git_patch_from_diff(&patch, diff, d)); @@ -33,16 +35,16 @@ static void check_diff_patches_at_line( if (expected[d] && !strcmp(expected[d], "")) continue; if (expected[d] && !strcmp(expected[d], "")) { - cl_git_pass(git_patch_to_str(&patch_text, patch)); + cl_git_pass(git_patch_to_buf(&buf, patch)); cl_assert_at_line(!strcmp(expected[d], ""), file, line); } - cl_git_pass(git_patch_to_str(&patch_text, patch)); + cl_git_pass(git_patch_to_buf(&buf, patch)); clar__assert_equal( file, line, "expected diff did not match actual diff", 1, - "%s", expected[d], patch_text); - git__free(patch_text); + "%s", expected[d], get_buf_ptr(&buf)); + git_buf_free(&buf); } cl_assert_at_line(expected[d] && !strcmp(expected[d], ""), file, line); -- cgit v1.2.1