summaryrefslogtreecommitdiff
path: root/src/diff_file.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 /src/diff_file.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 'src/diff_file.c')
-rw-r--r--src/diff_file.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/diff_file.c b/src/diff_file.c
index eeaf4a5a2..78e332f22 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -178,7 +178,7 @@ static int diff_file_content_commit_to_str(
git_diff_file_content *fc, bool check_status)
{
char oid[GIT_OID_HEXSZ+1];
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
const char *status = "";
if (check_status) {
@@ -217,11 +217,11 @@ static int diff_file_content_commit_to_str(
}
git_oid_tostr(oid, sizeof(oid), &fc->file->id);
- if (git_buf_printf(&content, "Subproject commit %s%s\n", oid, status) < 0)
+ if (git_str_printf(&content, "Subproject commit %s%s\n", oid, status) < 0)
return -1;
- fc->map.len = git_buf_len(&content);
- fc->map.data = git_buf_detach(&content);
+ fc->map.len = git_str_len(&content);
+ fc->map.data = git_str_detach(&content);
fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
return 0;
@@ -270,24 +270,24 @@ static int diff_file_content_load_blob(
}
static int diff_file_content_load_workdir_symlink_fake(
- git_diff_file_content *fc, git_buf *path)
+ git_diff_file_content *fc, git_str *path)
{
- git_buf target = GIT_BUF_INIT;
+ git_str target = GIT_STR_INIT;
int error;
if ((error = git_futils_readbuffer(&target, path->ptr)) < 0)
return error;
- fc->map.len = git_buf_len(&target);
- fc->map.data = git_buf_detach(&target);
+ fc->map.len = git_str_len(&target);
+ fc->map.data = git_str_detach(&target);
fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
- git_buf_dispose(&target);
+ git_str_dispose(&target);
return error;
}
static int diff_file_content_load_workdir_symlink(
- git_diff_file_content *fc, git_buf *path)
+ git_diff_file_content *fc, git_str *path)
{
ssize_t alloc_len, read_len;
int symlink_supported, error;
@@ -309,7 +309,7 @@ static int diff_file_content_load_workdir_symlink(
fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
- read_len = p_readlink(git_buf_cstr(path), fc->map.data, alloc_len);
+ read_len = p_readlink(git_str_cstr(path), fc->map.data, alloc_len);
if (read_len < 0) {
git_error_set(GIT_ERROR_OS, "failed to read symlink '%s'", fc->file->path);
return -1;
@@ -321,13 +321,13 @@ static int diff_file_content_load_workdir_symlink(
static int diff_file_content_load_workdir_file(
git_diff_file_content *fc,
- git_buf *path,
+ git_str *path,
git_diff_options *diff_opts)
{
int error = 0;
git_filter_list *fl = NULL;
- git_file fd = git_futils_open_ro(git_buf_cstr(path));
- git_buf raw = GIT_BUF_INIT;
+ git_file fd = git_futils_open_ro(git_str_cstr(path));
+ git_str raw = GIT_STR_INIT;
if (fd < 0)
return fd;
@@ -360,7 +360,7 @@ static int diff_file_content_load_workdir_file(
}
if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) {
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
error = git_filter_list__convert_buf(&out, fl, &raw);
@@ -383,7 +383,7 @@ static int diff_file_content_load_workdir(
git_diff_options *diff_opts)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (fc->file->mode == GIT_FILEMODE_COMMIT)
return diff_file_content_commit_to_str(fc, true);
@@ -406,7 +406,7 @@ static int diff_file_content_load_workdir(
fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}