diff options
author | Nicolas Hake <nh@nosebud.de> | 2014-01-22 17:51:32 +0100 |
---|---|---|
committer | Nicolas Hake <nh@nosebud.de> | 2014-01-22 17:51:32 +0100 |
commit | c05cd7924d2409741bb4cb1eb3ba843bea7ec4a2 (patch) | |
tree | 548900c29909e116ec5c3c1fe41370bef3460ac5 /tests/diff/submodules.c | |
parent | 450e8e9e623b8c172ba4628c146838cbf4c56519 (diff) | |
download | libgit2-c05cd7924d2409741bb4cb1eb3ba843bea7ec4a2.tar.gz |
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.
Diffstat (limited to 'tests/diff/submodules.c')
-rw-r--r-- | tests/diff/submodules.c | 12 |
1 files changed, 7 insertions, 5 deletions
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], "<SKIP>")) continue; if (expected[d] && !strcmp(expected[d], "<END>")) { - 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], "<END>"), 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], "<END>"), file, line); |