diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-27 22:57:53 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-29 11:33:58 +0100 |
commit | 8d0d31856aa591e939fd89972508b47e8e33690b (patch) | |
tree | bdc0a628e2a0f9b6f6fce81a14664884dceb80ac | |
parent | 143f545ba99663eebb6087ccac3595c94e9d70e9 (diff) | |
download | libgit2-8d0d31856aa591e939fd89972508b47e8e33690b.tar.gz |
diff: user-facing functions write to a userbuf
-rw-r--r-- | include/git2/diff.h | 12 | ||||
-rw-r--r-- | src/diff.c | 15 | ||||
-rw-r--r-- | src/diff_print.c | 12 | ||||
-rw-r--r-- | src/diff_stats.c | 21 | ||||
-rw-r--r-- | tests/diff/format_email.c | 20 | ||||
-rw-r--r-- | tests/diff/parse.c | 16 | ||||
-rw-r--r-- | tests/diff/rename.c | 12 | ||||
-rw-r--r-- | tests/diff/stats.c | 100 | ||||
-rw-r--r-- | tests/diff/tree.c | 4 | ||||
-rw-r--r-- | tests/diff/workdir.c | 4 |
10 files changed, 111 insertions, 105 deletions
diff --git a/include/git2/diff.h b/include/git2/diff.h index 3976ab1b9..4ab01e9e3 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -1118,14 +1118,14 @@ GIT_EXTERN(int) git_diff_print( * Produce the complete formatted text output from a diff into a * buffer. * - * @param out A pointer to a user-allocated git_buf that will + * @param out A pointer to a user-allocated git_userbuf that will * contain the diff text * @param diff A git_diff generated by one of the above functions. * @param format A git_diff_format_t value to pick the text format. * @return 0 on success or error code */ GIT_EXTERN(int) git_diff_to_buf( - git_buf *out, + git_userbuf *out, git_diff *diff, git_diff_format_t format); @@ -1339,7 +1339,7 @@ GIT_EXTERN(size_t) git_diff_stats_deletions( const git_diff_stats *stats); /** - * Print diff statistics to a `git_buf`. + * Print diff statistics to a `git_userbuf`. * * @param out buffer to store the formatted diff statistics in. * @param stats A `git_diff_stats` generated by one of the above functions. @@ -1348,7 +1348,7 @@ GIT_EXTERN(size_t) git_diff_stats_deletions( * @return 0 on success; non-zero on error */ GIT_EXTERN(int) git_diff_stats_to_buf( - git_buf *out, + git_userbuf *out, const git_diff_stats *stats, git_diff_stats_format_t format, size_t width); @@ -1413,7 +1413,7 @@ typedef struct { * @return 0 or an error code */ GIT_EXTERN(int) git_diff_format_email( - git_buf *out, + git_userbuf *out, git_diff *diff, const git_diff_format_email_options *opts); @@ -1432,7 +1432,7 @@ GIT_EXTERN(int) git_diff_format_email( * @return 0 or an error code */ GIT_EXTERN(int) git_diff_commit_as_email( - git_buf *out, + git_userbuf *out, git_repository *repo, git_commit *commit, size_t patch_no, diff --git a/src/diff.c b/src/diff.c index 16adb4225..8ffe712d9 100644 --- a/src/diff.c +++ b/src/diff.c @@ -12,6 +12,7 @@ #include "patch.h" #include "commit.h" #include "index.h" +#include "userbuf.h" struct patch_id_args { git_hash_ctx ctx; @@ -237,7 +238,7 @@ int git_diff_format_email__append_patches_tobuf( } int git_diff_format_email( - git_buf *out, + git_userbuf *out, git_diff *diff, const git_diff_format_email_options *opts) { @@ -292,7 +293,7 @@ int git_diff_format_email( strncpy(summary, opts->summary, offset); } - error = git_diff_format_email__append_header_tobuf(out, + error = git_diff_format_email__append_header_tobuf((git_buf *)out, opts->id, opts->author, summary == NULL ? opts->summary : summary, opts->body, opts->patch_no, opts->total_patches, ignore_marker); @@ -301,14 +302,14 @@ int git_diff_format_email( format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY; - if ((error = git_buf_puts(out, "---\n")) < 0 || + if ((error = git_buf_puts((git_buf *)out, "---\n")) < 0 || (error = git_diff_get_stats(&stats, diff)) < 0 || (error = git_diff_stats_to_buf(out, stats, format_flags, 0)) < 0 || - (error = git_buf_putc(out, '\n')) < 0 || - (error = git_diff_format_email__append_patches_tobuf(out, diff)) < 0) + (error = git_buf_putc((git_buf *)out, '\n')) < 0 || + (error = git_diff_format_email__append_patches_tobuf((git_buf *)out, diff)) < 0) goto on_error; - error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n"); + error = git_buf_puts((git_buf *)out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n"); on_error: git__free(summary); @@ -318,7 +319,7 @@ on_error: } int git_diff_commit_as_email( - git_buf *out, + git_userbuf *out, git_repository *repo, git_commit *commit, size_t patch_no, diff --git a/src/diff_print.c b/src/diff_print.c index 926bf3188..d10eed7f6 100644 --- a/src/diff_print.c +++ b/src/diff_print.c @@ -754,13 +754,15 @@ int git_diff_print_callback__to_file_handle( return 0; } -/* print a git_diff to a git_buf */ -int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format) +/* print a git_diff to a git_userbuf */ +int git_diff_to_buf(git_userbuf *out, git_diff *diff, git_diff_format_t format) { assert(out && diff); - git_buf_sanitize(out); - return git_diff_print( - diff, format, git_diff_print_callback__to_buf, out); + + git_userbuf_sanitize(out); + + return git_diff_print(diff, + format, git_diff_print_callback__to_buf, (git_buf *)out); } /* print a git_patch to an output callback */ diff --git a/src/diff_stats.c b/src/diff_stats.c index 19c9da05f..3100f3e62 100644 --- a/src/diff_stats.c +++ b/src/diff_stats.c @@ -10,6 +10,7 @@ #include "vector.h" #include "diff.h" #include "patch_generate.h" +#include "userbuf.h" #define DIFF_RENAME_FILE_SEPARATOR " => " #define STATS_FULL_MIN_SCALE 7 @@ -272,7 +273,7 @@ size_t git_diff_stats_deletions( } int git_diff_stats_to_buf( - git_buf *out, + git_userbuf *out, const git_diff_stats *stats, git_diff_stats_format_t format, size_t width) @@ -283,13 +284,15 @@ int git_diff_stats_to_buf( assert(out && stats); + git_userbuf_sanitize(out); + if (format & GIT_DIFF_STATS_NUMBER) { for (i = 0; i < stats->files_changed; ++i) { if ((delta = git_diff_get_delta(stats->diff, i)) == NULL) continue; error = git_diff_file_stats__number_to_buf( - out, delta, &stats->filestats[i]); + (git_buf *)out, delta, &stats->filestats[i]); if (error < 0) return error; } @@ -310,7 +313,7 @@ int git_diff_stats_to_buf( continue; error = git_diff_file_stats__full_to_buf( - out, delta, &stats->filestats[i], stats, width); + (git_buf *)out, delta, &stats->filestats[i], stats, width); if (error < 0) return error; } @@ -318,22 +321,22 @@ int git_diff_stats_to_buf( if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) { git_buf_printf( - out, " %" PRIuZ " file%s changed", + (git_buf *)out, " %" PRIuZ " file%s changed", stats->files_changed, stats->files_changed != 1 ? "s" : ""); if (stats->insertions || stats->deletions == 0) git_buf_printf( - out, ", %" PRIuZ " insertion%s(+)", + (git_buf *)out, ", %" PRIuZ " insertion%s(+)", stats->insertions, stats->insertions != 1 ? "s" : ""); if (stats->deletions || stats->insertions == 0) git_buf_printf( - out, ", %" PRIuZ " deletion%s(-)", + (git_buf *)out, ", %" PRIuZ " deletion%s(-)", stats->deletions, stats->deletions != 1 ? "s" : ""); - git_buf_putc(out, '\n'); + git_buf_putc((git_buf *)out, '\n'); - if (git_buf_oom(out)) + if (git_buf_oom((git_buf *)out)) return -1; } @@ -342,7 +345,7 @@ int git_diff_stats_to_buf( if ((delta = git_diff_get_delta(stats->diff, i)) == NULL) continue; - error = git_diff_file_stats__summary_to_buf(out, delta); + error = git_diff_file_stats__summary_to_buf((git_buf *)out, delta); if (error < 0) return error; } diff --git a/tests/diff/format_email.c b/tests/diff/format_email.c index 28f840ab0..90a4c03e5 100644 --- a/tests/diff/format_email.c +++ b/tests/diff/format_email.c @@ -26,7 +26,7 @@ static void assert_email_match( git_oid oid; git_commit *commit = NULL; git_diff *diff = NULL; - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; git_oid_fromstr(&oid, oidstr); @@ -40,16 +40,16 @@ static void assert_email_match( cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_diff_format_email(&buf, diff, opts)); - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - git_buf_clear(&buf); + cl_assert_equal_s(expected, buf.ptr); + git_userbuf_dispose(&buf); cl_git_pass(git_diff_commit_as_email( &buf, repo, commit, 1, 1, opts->flags, NULL)); - cl_assert_equal_s(expected, git_buf_cstr(&buf)); + cl_assert_equal_s(expected, buf.ptr); git_diff_free(diff); git_commit_free(commit); - git_buf_dispose(&buf); + git_userbuf_dispose(&buf); } void test_diff_format_email__simple(void) @@ -145,7 +145,7 @@ void test_diff_format_email__multiple(void) git_commit *commit = NULL; git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *email = "From 10808fe9c9be5a190c0ba68d1a002233fb363508 Mon Sep 17 00:00:00 2001\n" \ @@ -251,11 +251,11 @@ void test_diff_format_email__multiple(void) cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert_equal_s(email, git_buf_cstr(&buf)); + cl_assert_equal_s(email, buf.ptr); git_diff_free(diff); git_commit_free(commit); - git_buf_dispose(&buf); + git_userbuf_dispose(&buf); } void test_diff_format_email__exclude_marker(void) @@ -312,7 +312,7 @@ void test_diff_format_email__invalid_no(void) git_commit *commit = NULL; git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); @@ -331,7 +331,7 @@ void test_diff_format_email__invalid_no(void) git_diff_free(diff); git_commit_free(commit); - git_buf_dispose(&buf); + git_userbuf_dispose(&buf); } void test_diff_format_email__mode_change(void) diff --git a/tests/diff/parse.c b/tests/diff/parse.c index 0269eb831..7b59c0010 100644 --- a/tests/diff/parse.c +++ b/tests/diff/parse.c @@ -125,7 +125,7 @@ static void test_tree_to_tree_computed_to_parsed( git_tree *a, *b; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; - git_buf computed_buf = GIT_BUF_INIT; + git_userbuf computed_buf = GIT_USERBUF_INIT; repo = cl_git_sandbox_init(sandbox); @@ -155,7 +155,7 @@ static void test_tree_to_tree_computed_to_parsed( git_diff_free(computed); git_diff_free(parsed); - git_buf_dispose(&computed_buf); + git_userbuf_dispose(&computed_buf); cl_git_sandbox_cleanup(); } @@ -209,7 +209,7 @@ void test_diff_parse__get_patch_from_diff(void) git_diff *computed, *parsed; git_tree *a, *b; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_buf computed_buf = GIT_BUF_INIT; + git_userbuf computed_buf = GIT_USERBUF_INIT; git_patch *patch_computed, *patch_parsed; repo = cl_git_sandbox_init("diff"); @@ -243,7 +243,7 @@ void test_diff_parse__get_patch_from_diff(void) git_diff_free(computed); git_diff_free(parsed); - git_buf_dispose(&computed_buf); + git_userbuf_dispose(&computed_buf); cl_git_sandbox_cleanup(); } @@ -287,7 +287,7 @@ void test_diff_parse__parsing_minimal_patch_succeeds(void) "@@ -1 +1 @@\n" "-a\n" "+\n"; - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; git_diff *diff; cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch))); @@ -295,14 +295,14 @@ void test_diff_parse__parsing_minimal_patch_succeeds(void) cl_assert_equal_s(patch, buf.ptr); git_diff_free(diff); - git_buf_dispose(&buf); + git_userbuf_dispose(&buf); } void test_diff_parse__patch_roundtrip_succeeds(void) { const char buf1[] = "a\n", buf2[] = "b\n"; git_userbuf patchbuf = GIT_USERBUF_INIT; - git_buf diffbuf = GIT_BUF_INIT; + git_userbuf diffbuf = GIT_USERBUF_INIT; git_patch *patch; git_diff *diff; @@ -317,7 +317,7 @@ void test_diff_parse__patch_roundtrip_succeeds(void) git_patch_free(patch); git_diff_free(diff); git_userbuf_dispose(&patchbuf); - git_buf_dispose(&diffbuf); + git_userbuf_dispose(&diffbuf); } #define cl_assert_equal_i_src(i1,i2,file,line) clar__assert_equal(file,line,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2)) diff --git a/tests/diff/rename.c b/tests/diff/rename.c index 37f7f0ac6..8fa8b957f 100644 --- a/tests/diff/rename.c +++ b/tests/diff/rename.c @@ -1733,7 +1733,7 @@ void test_diff_rename__identical(void) git_diff *diff; git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; git_diff_find_options find_opts = GIT_DIFF_FIND_OPTIONS_INIT; - git_buf diff_buf = GIT_BUF_INIT; + git_userbuf diff_buf = GIT_USERBUF_INIT; const char *expected = "diff --git a/serving.txt b/sixserving.txt\n" "similarity index 100%\n" @@ -1759,7 +1759,7 @@ void test_diff_rename__identical(void) cl_assert_equal_s(expected, diff_buf.ptr); - git_buf_dispose(&diff_buf); + git_userbuf_dispose(&diff_buf); git_diff_free(diff); git_tree_free(old_tree); git_tree_free(new_tree); @@ -1772,7 +1772,7 @@ void test_diff_rename__rewrite_and_delete(void) git_tree *old_tree, *new_tree; git_diff *diff; git_diff_find_options find_opts = GIT_DIFF_FIND_OPTIONS_INIT; - git_buf diff_buf = GIT_BUF_INIT; + git_userbuf diff_buf = GIT_USERBUF_INIT; const char *expected = "diff --git a/ikeepsix.txt b/ikeepsix.txt\n" "deleted file mode 100644\n" @@ -1910,7 +1910,7 @@ void test_diff_rename__rewrite_and_delete(void) cl_assert_equal_s(expected, diff_buf.ptr); - git_buf_dispose(&diff_buf); + git_userbuf_dispose(&diff_buf); git_diff_free(diff); git_tree_free(old_tree); git_tree_free(new_tree); @@ -1923,7 +1923,7 @@ void test_diff_rename__delete_and_rename(void) git_tree *old_tree, *new_tree; git_diff *diff; git_diff_find_options find_opts = GIT_DIFF_FIND_OPTIONS_INIT; - git_buf diff_buf = GIT_BUF_INIT; + git_userbuf diff_buf = GIT_USERBUF_INIT; const char *expected = "diff --git a/sixserving.txt b/sixserving.txt\n" "deleted file mode 100644\n" @@ -1973,7 +1973,7 @@ void test_diff_rename__delete_and_rename(void) cl_assert_equal_s(expected, diff_buf.ptr); - git_buf_dispose(&diff_buf); + git_userbuf_dispose(&diff_buf); git_diff_free(diff); git_tree_free(old_tree); git_tree_free(new_tree); diff --git a/tests/diff/stats.c b/tests/diff/stats.c index 150355686..4a040f46e 100644 --- a/tests/diff/stats.c +++ b/tests/diff/stats.c @@ -40,7 +40,7 @@ static void diff_stats_from_commit_oid( void test_diff_stats__stat(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file1.txt | 8 +++++---\n" \ " 1 file changed, 5 insertions(+), 3 deletions(-)\n"; @@ -53,17 +53,17 @@ void test_diff_stats__stat(void) cl_assert_equal_sz(3, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - git_buf_dispose(&buf); + cl_assert(strcmp(buf.ptr, stat) == 0); + git_userbuf_dispose(&buf); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 80)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - git_buf_dispose(&buf); + cl_assert(strcmp(buf.ptr, stat) == 0); + git_userbuf_dispose(&buf); } void test_diff_stats__multiple_hunks(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt | 5 +++--\n" \ " file3.txt | 6 ++++--\n" \ @@ -77,13 +77,13 @@ void test_diff_stats__multiple_hunks(void) cl_assert_equal_sz(4, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__numstat(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = "3 2 file2.txt\n" "4 2 file3.txt\n"; @@ -92,13 +92,13 @@ void test_diff_stats__numstat(void) &_stats, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2", false); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__shortstat(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " 1 file changed, 5 insertions(+), 3 deletions(-)\n"; @@ -110,13 +110,13 @@ void test_diff_stats__shortstat(void) cl_assert_equal_sz(3, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__shortstat_noinsertions(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " 1 file changed, 2 deletions(-)\n"; @@ -128,13 +128,13 @@ void test_diff_stats__shortstat_noinsertions(void) cl_assert_equal_sz(2, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__shortstat_nodeletions(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " 1 file changed, 3 insertions(+)\n"; @@ -146,13 +146,13 @@ void test_diff_stats__shortstat_nodeletions(void) cl_assert_equal_sz(0, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt => file2.txt.renamed | 1 +\n" " file3.txt => file3.txt.renamed | 4 +++-\n" @@ -166,13 +166,13 @@ void test_diff_stats__rename(void) cl_assert_equal_sz(1, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename_nochanges(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt.renamed => file2.txt.renamed2 | 0\n" " file3.txt.renamed => file3.txt.renamed2 | 0\n" @@ -186,13 +186,13 @@ void test_diff_stats__rename_nochanges(void) cl_assert_equal_sz(0, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename_and_modifiy(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt.renamed2 | 2 +-\n" " file3.txt.renamed2 => file3.txt.renamed | 0\n" @@ -206,13 +206,13 @@ void test_diff_stats__rename_and_modifiy(void) cl_assert_equal_sz(1, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename_in_subdirectory(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " dir/{orig.txt => renamed.txt} | 0\n" " 1 file changed, 0 insertions(+), 0 deletions(-)\n"; @@ -225,13 +225,13 @@ void test_diff_stats__rename_in_subdirectory(void) cl_assert_equal_sz(0, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename_no_find(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt | 5 -----\n" " file2.txt.renamed | 6 ++++++\n" @@ -247,13 +247,13 @@ void test_diff_stats__rename_no_find(void) cl_assert_equal_sz(10, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename_nochanges_no_find(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt.renamed | 6 ------\n" " file2.txt.renamed2 | 6 ++++++\n" @@ -269,13 +269,13 @@ void test_diff_stats__rename_nochanges_no_find(void) cl_assert_equal_sz(13, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__rename_and_modify_no_find(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file2.txt.renamed2 | 2 +-\n" " file3.txt.renamed | 7 +++++++\n" @@ -290,13 +290,13 @@ void test_diff_stats__rename_and_modify_no_find(void) cl_assert_equal_sz(8, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__binary(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " binary.bin | Bin 3 -> 0 bytes\n" " 1 file changed, 0 insertions(+), 0 deletions(-)\n"; @@ -310,13 +310,13 @@ void test_diff_stats__binary(void) cl_assert_equal_sz(0, git_diff_stats_deletions(_stats)); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__binary_numstat(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = "- - binary.bin\n"; @@ -324,13 +324,13 @@ void test_diff_stats__binary_numstat(void) &_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } void test_diff_stats__mode_change(void) { - git_buf buf = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; const char *stat = " file1.txt.renamed | 0\n" \ " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ @@ -340,6 +340,6 @@ void test_diff_stats__mode_change(void) &_stats, "7ade76dd34bba4733cf9878079f9fd4a456a9189", false); cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0)); - cl_assert_equal_s(stat, git_buf_cstr(&buf)); - git_buf_dispose(&buf); + cl_assert_equal_s(stat, buf.ptr); + git_userbuf_dispose(&buf); } diff --git a/tests/diff/tree.c b/tests/diff/tree.c index dfe4d254c..0c104d307 100644 --- a/tests/diff/tree.c +++ b/tests/diff/tree.c @@ -530,7 +530,7 @@ void test_diff_tree__diff_tree_with_empty_dir_entry_succeeds(void) const char *content = "This is a blob\n"; const git_diff_delta *delta; git_oid empty_tree, invalid_tree, blob; - git_buf patch = GIT_BUF_INIT; + git_userbuf patch = GIT_USERBUF_INIT; git_treebuilder *builder; g_repo = cl_git_sandbox_init("empty_standard_repo"); @@ -571,5 +571,5 @@ void test_diff_tree__diff_tree_with_empty_dir_entry_succeeds(void) cl_assert_equal_s(delta->new_file.path, "blob"); git_treebuilder_free(builder); - git_buf_dispose(&patch); + git_userbuf_dispose(&patch); } diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index 578180434..efc6c7ae8 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -2165,7 +2165,7 @@ void test_diff_workdir__symlink_changed_on_non_symlink_platform(void) void test_diff_workdir__order(void) { git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_buf patch = GIT_BUF_INIT; + git_userbuf patch = GIT_USERBUF_INIT; git_oid tree_oid, blob_oid; git_treebuilder *builder; git_tree *tree; @@ -2200,7 +2200,7 @@ void test_diff_workdir__order(void) "+bar\n"); git_treebuilder_free(builder); - git_buf_dispose(&patch); + git_userbuf_dispose(&patch); git_diff_free(diff); git_tree_free(tree); } |