summaryrefslogtreecommitdiff
path: root/src/merge.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/merge.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/merge.c')
-rw-r--r--src/merge.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/merge.c b/src/merge.c
index d838e4ba9..ae1d453ec 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -8,7 +8,7 @@
#include "merge.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "repository.h"
#include "revwalk.h"
#include "commit_list.h"
@@ -591,7 +591,7 @@ int git_repository_mergehead_foreach(
git_repository_mergehead_foreach_cb cb,
void *payload)
{
- git_buf merge_head_path = GIT_BUF_INIT, merge_head_file = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT, merge_head_file = GIT_STR_INIT;
char *buffer, *line;
size_t line_num = 1;
git_oid oid;
@@ -600,12 +600,12 @@ int git_repository_mergehead_foreach(
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(cb);
- if ((error = git_buf_joinpath(&merge_head_path, repo->gitdir,
+ if ((error = git_str_joinpath(&merge_head_path, repo->gitdir,
GIT_MERGE_HEAD_FILE)) < 0)
return error;
if ((error = git_futils_readbuffer(&merge_head_file,
- git_buf_cstr(&merge_head_path))) < 0)
+ git_str_cstr(&merge_head_path))) < 0)
goto cleanup;
buffer = merge_head_file.ptr;
@@ -635,8 +635,8 @@ int git_repository_mergehead_foreach(
}
cleanup:
- git_buf_dispose(&merge_head_path);
- git_buf_dispose(&merge_head_file);
+ git_str_dispose(&merge_head_path);
+ git_str_dispose(&merge_head_file);
return error;
}
@@ -893,7 +893,7 @@ static int merge_conflict_invoke_driver(
git_merge_driver_source *src)
{
git_index_entry *result;
- git_buf buf = GIT_BUF_INIT;
+ git_buf buf = {0};
const char *path;
uint32_t mode;
git_odb *odb = NULL;
@@ -2473,14 +2473,14 @@ static int write_merge_head(
size_t heads_len)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
size_t i;
int error = 0;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(heads);
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
@@ -2495,7 +2495,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -2503,12 +2503,12 @@ cleanup:
static int write_merge_mode(git_repository *repo)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
GIT_ASSERT_ARG(repo);
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
@@ -2521,7 +2521,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -2719,7 +2719,7 @@ static int write_merge_msg(
size_t heads_len)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
struct merge_msg_entry *entries;
git_vector matching = GIT_VECTOR_INIT;
size_t i;
@@ -2740,7 +2740,7 @@ static int write_merge_msg(
for (i = 0; i < heads_len; i++)
entries[i].merge_head = heads[i];
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) < 0 ||
(error = git_filebuf_write(&file, "Merge ", 6)) < 0)
goto cleanup;
@@ -2822,7 +2822,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
git_vector_free(&matching);
git__free(entries);
@@ -3114,7 +3114,7 @@ int git_merge__append_conflicts_to_merge_msg(
git_index *index)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
const char *last = NULL;
size_t i;
int error;
@@ -3122,7 +3122,7 @@ int git_merge__append_conflicts_to_merge_msg(
if (!git_index_has_conflicts(index))
return 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_APPEND, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
@@ -3146,7 +3146,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}