summaryrefslogtreecommitdiff
path: root/tests/submodule/submodule_helpers.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/submodule/submodule_helpers.c
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-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/submodule/submodule_helpers.c')
-rw-r--r--tests/submodule/submodule_helpers.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index 1d4759616..95d20a009 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "util.h"
#include "posix.h"
@@ -12,12 +11,12 @@
*/
void rewrite_gitmodules(const char *workdir)
{
- git_buf in_f = GIT_BUF_INIT, out_f = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str in_f = GIT_STR_INIT, out_f = GIT_STR_INIT, path = GIT_STR_INIT;
FILE *in, *out;
char line[256];
- cl_git_pass(git_buf_joinpath(&in_f, workdir, "gitmodules"));
- cl_git_pass(git_buf_joinpath(&out_f, workdir, ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&in_f, workdir, "gitmodules"));
+ cl_git_pass(git_str_joinpath(&out_f, workdir, ".gitmodules"));
cl_assert((in = fopen(in_f.ptr, "rb")) != NULL);
cl_assert((out = fopen(out_f.ptr, "wb")) != NULL);
@@ -32,16 +31,16 @@ void rewrite_gitmodules(const char *workdir)
scan += strlen("path =");
while (*scan == ' ') scan++;
- git_buf_joinpath(&path, workdir, scan);
- git_buf_rtrim(&path);
- git_buf_joinpath(&path, path.ptr, ".gitted");
+ git_str_joinpath(&path, workdir, scan);
+ git_str_rtrim(&path);
+ git_str_joinpath(&path, path.ptr, ".gitted");
- if (!git_buf_oom(&path) && p_access(path.ptr, F_OK) == 0) {
- git_buf_joinpath(&out_f, workdir, scan);
- git_buf_rtrim(&out_f);
- git_buf_joinpath(&out_f, out_f.ptr, ".git");
+ if (!git_str_oom(&path) && p_access(path.ptr, F_OK) == 0) {
+ git_str_joinpath(&out_f, workdir, scan);
+ git_str_rtrim(&out_f);
+ git_str_joinpath(&out_f, out_f.ptr, ".git");
- if (!git_buf_oom(&out_f))
+ if (!git_str_oom(&out_f))
p_rename(path.ptr, out_f.ptr);
}
}
@@ -57,18 +56,18 @@ void rewrite_gitmodules(const char *workdir)
while (*scan == ' ') scan++;
if (*scan == '.') {
- git_buf_joinpath(&path, workdir, scan);
- git_buf_rtrim(&path);
+ git_str_joinpath(&path, workdir, scan);
+ git_str_rtrim(&path);
} else if (!*scan || *scan == '\n') {
- git_buf_joinpath(&path, workdir, "../testrepo.git");
+ git_str_joinpath(&path, workdir, "../testrepo.git");
} else {
fputs(line, out);
continue;
}
git_path_prettify(&path, path.ptr, NULL);
- git_buf_putc(&path, '\n');
- cl_assert(!git_buf_oom(&path));
+ git_str_putc(&path, '\n');
+ cl_assert(!git_str_oom(&path));
fwrite(line, scan - line, sizeof(char), out);
fputs(path.ptr, out);
@@ -79,9 +78,9 @@ void rewrite_gitmodules(const char *workdir)
cl_must_pass(p_unlink(in_f.ptr));
- git_buf_dispose(&in_f);
- git_buf_dispose(&out_f);
- git_buf_dispose(&path);
+ git_str_dispose(&in_f);
+ git_str_dispose(&out_f);
+ git_str_dispose(&path);
}
static void cleanup_fixture_submodules(void *payload)