summaryrefslogtreecommitdiff
path: root/tests/reset/hard.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-07 17:53:49 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-10-17 09:49:01 -0400
commitf0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch)
treebe5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /tests/reset/hard.c
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-ethomson/gitstr.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/reset/hard.c')
-rw-r--r--tests/reset/hard.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 1ea1d13fb..36e8f1470 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -40,7 +40,7 @@ static int strequal_ignore_eol(const char *exp, const char *str)
void test_reset_hard__resetting_reverts_modified_files(void)
{
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
int i;
static const char *files[4] = {
"current_file",
@@ -64,7 +64,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_assert(wd);
for (i = 0; i < 4; ++i) {
- cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_str_joinpath(&path, wd, files[i]));
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert_equal_s(before[i], content.ptr);
}
@@ -74,7 +74,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
for (i = 0; i < 4; ++i) {
- cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_str_joinpath(&path, wd, files[i]));
if (after[i]) {
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert(strequal_ignore_eol(after[i], content.ptr));
@@ -83,8 +83,8 @@ void test_reset_hard__resetting_reverts_modified_files(void)
}
}
- git_buf_dispose(&content);
- git_buf_dispose(&path);
+ git_str_dispose(&content);
+ git_str_dispose(&path);
}
void test_reset_hard__cannot_reset_in_a_bare_repository(void)
@@ -165,42 +165,42 @@ void test_reset_hard__resetting_reverts_unmerged(void)
void test_reset_hard__cleans_up_merge(void)
{
- git_buf merge_head_path = GIT_BUF_INIT,
- merge_msg_path = GIT_BUF_INIT,
- merge_mode_path = GIT_BUF_INIT,
- orig_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT,
+ merge_msg_path = GIT_STR_INIT,
+ merge_mode_path = GIT_STR_INIT,
+ orig_head_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_str_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
- cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
+ cl_git_pass(git_str_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
+ cl_git_mkfile(git_str_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
- cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
- cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");
+ cl_git_pass(git_str_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
+ cl_git_mkfile(git_str_cstr(&merge_mode_path), "");
- cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
- cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
+ cl_git_pass(git_str_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
+ cl_git_mkfile(git_str_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_head_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_msg_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_mode_path)));
- cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
- cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));
+ cl_assert(git_path_exists(git_str_cstr(&orig_head_path)));
+ cl_git_pass(p_unlink(git_str_cstr(&orig_head_path)));
- git_buf_dispose(&merge_head_path);
- git_buf_dispose(&merge_msg_path);
- git_buf_dispose(&merge_mode_path);
- git_buf_dispose(&orig_head_path);
+ git_str_dispose(&merge_head_path);
+ git_str_dispose(&merge_msg_path);
+ git_str_dispose(&merge_mode_path);
+ git_str_dispose(&orig_head_path);
}
void test_reset_hard__reflog_is_correct(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Add a file which name should appear before the "
"\"subdir/\" folder while being dealt with by the treewalker";
@@ -218,12 +218,12 @@ void test_reset_hard__reflog_is_correct(void)
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ cl_git_pass(git_str_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
- reflog_check(repo, "HEAD", 4, NULL, git_buf_cstr(&buf));
- reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));
+ reflog_check(repo, "HEAD", 4, NULL, git_str_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 4, NULL, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";