diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-07 17:53:49 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-10-17 09:49:01 -0400 |
commit | f0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch) | |
tree | be5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /tests/diff/binary.c | |
parent | 5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff) | |
download | libgit2-f0e693b18afbe1de37d7da5b5a8967b6c87d8e53.tar.gz |
str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstr
libgit2 has two distinct requirements that were previously solved by
`git_buf`. We require:
1. A general purpose string class that provides a number of utility APIs
for manipulating data (eg, concatenating, truncating, etc).
2. A structure that we can use to return strings to callers that they
can take ownership of.
By using a single class (`git_buf`) for both of these purposes, we have
confused the API to the point that refactorings are difficult and
reasoning about correctness is also difficult.
Move the utility class `git_buf` to be called `git_str`: this represents
its general purpose, as an internal string buffer class. The name also
is an homage to Junio Hamano ("gitstr").
The public API remains `git_buf`, and has a much smaller footprint. It
is generally only used as an "out" param with strict requirements that
follow the documentation. (Exceptions exist for some legacy APIs to
avoid breaking callers unnecessarily.)
Utility functions exist to convert a user-specified `git_buf` to a
`git_str` so that we can call internal functions, then converting it
back again.
Diffstat (limited to 'tests/diff/binary.c')
-rw-r--r-- | tests/diff/binary.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/tests/diff/binary.c b/tests/diff/binary.c index 7edf37b51..24d2b22ef 100644 --- a/tests/diff/binary.c +++ b/tests/diff/binary.c @@ -2,7 +2,6 @@ #include "git2/sys/diff.h" -#include "buffer.h" #include "delta.h" #include "filebuf.h" #include "repository.h" @@ -53,7 +52,7 @@ void test_patch( cl_assert_equal_s(expected, actual.ptr); - git_buf_clear(&actual); + git_buf_dispose(&actual); cl_git_pass(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, git_diff_print_callback__to_buf, &actual)); cl_assert_equal_s(expected, actual.ptr); @@ -197,7 +196,7 @@ void test_diff_binary__delete(void) void test_diff_binary__delta(void) { git_index *index; - git_buf contents = GIT_BUF_INIT; + git_str contents = GIT_STR_INIT; size_t i; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = @@ -239,7 +238,7 @@ void test_diff_binary__delta(void) expected); git_index_free(index); - git_buf_dispose(&contents); + git_str_dispose(&contents); } void test_diff_binary__delta_append(void) @@ -283,7 +282,7 @@ void test_diff_binary__empty_for_no_diff(void) git_commit *commit; git_tree *tree; git_diff *diff; - git_buf actual = GIT_BUF_INIT; + git_str actual = GIT_STR_INIT; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; opts.id_abbrev = GIT_OID_HEXSZ; @@ -299,7 +298,7 @@ void test_diff_binary__empty_for_no_diff(void) cl_assert_equal_s("", actual.ptr); - git_buf_dispose(&actual); + git_str_dispose(&actual); git_diff_free(diff); git_commit_free(commit); git_tree_free(tree); @@ -359,24 +358,24 @@ static int print_cb( const git_diff_line *line, void *payload) { - git_buf *buf = (git_buf *)payload; + git_str *buf = (git_str *)payload; GIT_UNUSED(delta); if (hunk) - git_buf_put(buf, hunk->header, hunk->header_len); + git_str_put(buf, hunk->header, hunk->header_len); if (line) - git_buf_put(buf, line->content, line->content_len); + git_str_put(buf, line->content, line->content_len); - return git_buf_oom(buf) ? -1 : 0; + return git_str_oom(buf) ? -1 : 0; } void test_diff_binary__print_patch_from_diff(void) { git_index *index; git_diff *diff; - git_buf actual = GIT_BUF_INIT; + git_str actual = GIT_STR_INIT; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/untimely.txt b/untimely.txt\n" \ @@ -403,7 +402,7 @@ void test_diff_binary__print_patch_from_diff(void) cl_assert_equal_s(expected, actual.ptr); - git_buf_dispose(&actual); + git_str_dispose(&actual); git_diff_free(diff); git_index_free(index); } @@ -411,13 +410,13 @@ void test_diff_binary__print_patch_from_diff(void) struct diff_data { char *old_path; git_oid old_id; - git_buf old_binary_base85; + git_str old_binary_base85; size_t old_binary_inflatedlen; git_diff_binary_t old_binary_type; char *new_path; git_oid new_id; - git_buf new_binary_base85; + git_str new_binary_base85; size_t new_binary_inflatedlen; git_diff_binary_t new_binary_type; }; @@ -452,12 +451,12 @@ static int binary_cb( GIT_UNUSED(delta); - git_buf_encode_base85(&diff_data->old_binary_base85, + git_str_encode_base85(&diff_data->old_binary_base85, binary->old_file.data, binary->old_file.datalen); diff_data->old_binary_inflatedlen = binary->old_file.inflatedlen; diff_data->old_binary_type = binary->old_file.type; - git_buf_encode_base85(&diff_data->new_binary_base85, + git_str_encode_base85(&diff_data->new_binary_base85, binary->new_file.data, binary->new_file.datalen); diff_data->new_binary_inflatedlen = binary->new_file.inflatedlen; diff_data->new_binary_type = binary->new_file.type; @@ -541,6 +540,6 @@ void test_diff_binary__blob_to_blob(void) git__free(diff_data.old_path); git__free(diff_data.new_path); - git_buf_dispose(&diff_data.old_binary_base85); - git_buf_dispose(&diff_data.new_binary_base85); + git_str_dispose(&diff_data.old_binary_base85); + git_str_dispose(&diff_data.new_binary_base85); } |