From f0e693b18afbe1de37d7da5b5a8967b6c87d8e53 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 7 Sep 2021 17:53:49 -0400 Subject: str: introduce `git_str` for internal, `git_buf` is external 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. --- tests/merge/analysis.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/merge/analysis.c') diff --git a/tests/merge/analysis.c b/tests/merge/analysis.c index 1432a7d11..8c61303e3 100644 --- a/tests/merge/analysis.c +++ b/tests/merge/analysis.c @@ -53,28 +53,28 @@ static void analysis_from_branch( const char *our_branchname, const char *their_branchname) { - git_buf our_refname = GIT_BUF_INIT; - git_buf their_refname = GIT_BUF_INIT; + git_str our_refname = GIT_STR_INIT; + git_str their_refname = GIT_STR_INIT; git_reference *our_ref; git_reference *their_ref; git_annotated_commit *their_head; if (our_branchname != NULL) { - cl_git_pass(git_buf_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname)); - cl_git_pass(git_reference_lookup(&our_ref, repo, git_buf_cstr(&our_refname))); + cl_git_pass(git_str_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname)); + cl_git_pass(git_reference_lookup(&our_ref, repo, git_str_cstr(&our_refname))); } else { cl_git_pass(git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE)); } - cl_git_pass(git_buf_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname)); + cl_git_pass(git_str_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname)); - cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&their_refname))); + cl_git_pass(git_reference_lookup(&their_ref, repo, git_str_cstr(&their_refname))); cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref)); cl_git_pass(git_merge_analysis_for_ref(merge_analysis, merge_pref, repo, our_ref, (const git_annotated_commit **)&their_head, 1)); - git_buf_dispose(&our_refname); - git_buf_dispose(&their_refname); + git_str_dispose(&our_refname); + git_str_dispose(&their_refname); git_annotated_commit_free(their_head); git_reference_free(our_ref); git_reference_free(their_ref); @@ -120,15 +120,15 @@ void test_merge_analysis__unborn(void) { git_merge_analysis_t merge_analysis; git_merge_preference_t merge_pref; - git_buf master = GIT_BUF_INIT; + git_str master = GIT_STR_INIT; - cl_git_pass(git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master")); - cl_must_pass(p_unlink(git_buf_cstr(&master))); + cl_git_pass(git_str_joinpath(&master, git_repository_path(repo), "refs/heads/master")); + cl_must_pass(p_unlink(git_str_cstr(&master))); analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH); cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis); - git_buf_dispose(&master); + git_str_dispose(&master); } void test_merge_analysis__fastforward_with_config_noff(void) -- cgit v1.2.1