summaryrefslogtreecommitdiff
path: root/src/repository.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/repository.c')
-rw-r--r--src/repository.c524
1 files changed, 267 insertions, 257 deletions
diff --git a/src/repository.c b/src/repository.c
index 9b3e9c9e3..29684e463 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -12,6 +12,7 @@
#include "git2/object.h"
#include "git2/sys/repository.h"
+#include "buf.h"
#include "common.h"
#include "commit.h"
#include "tag.h"
@@ -75,13 +76,13 @@ static int check_extensions(git_config *config, int version);
#define GIT_REPO_VERSION 0
#define GIT_REPO_MAX_VERSION 1
-git_buf git_repository__reserved_names_win32[] = {
+git_str git_repository__reserved_names_win32[] = {
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
{ GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
};
size_t git_repository__reserved_names_win32_len = 2;
-git_buf git_repository__reserved_names_posix[] = {
+git_str git_repository__reserved_names_posix[] = {
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
};
size_t git_repository__reserved_names_posix_len = 1;
@@ -171,7 +172,7 @@ void git_repository_free(git_repository *repo)
repo->diff_drivers = NULL;
for (i = 0; i < repo->reserved_names.size; i++)
- git_buf_dispose(git_array_get(repo->reserved_names, i));
+ git_str_dispose(git_array_get(repo->reserved_names, i));
git_array_clear(repo->reserved_names);
git__free(repo->gitlink);
@@ -187,9 +188,9 @@ void git_repository_free(git_repository *repo)
}
/* Check if we have a separate commondir (e.g. we have a worktree) */
-static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *repository_path)
+static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
{
- git_buf common_link = GIT_BUF_INIT;
+ git_str common_link = GIT_STR_INIT;
int error;
/*
@@ -197,7 +198,7 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
* common path, but it needs a trailing slash.
*/
if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
- if ((error = git_buf_set(commondir, repository_path->ptr, repository_path->size)) == 0)
+ if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
error = git_path_to_dir(commondir);
*separate = false;
@@ -206,19 +207,19 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
*separate = true;
- if ((error = git_buf_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
(error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
goto done;
- git_buf_rtrim(&common_link);
+ git_str_rtrim(&common_link);
if (git_path_is_relative(common_link.ptr)) {
- if ((error = git_buf_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
+ if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
goto done;
} else {
- git_buf_swap(commondir, &common_link);
+ git_str_swap(commondir, &common_link);
}
- git_buf_dispose(&common_link);
+ git_str_dispose(&common_link);
/* Make sure the commondir path always has a trailing slash */
error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
@@ -227,7 +228,7 @@ done:
return error;
}
-GIT_INLINE(int) validate_repo_path(git_buf *path)
+GIT_INLINE(int) validate_repo_path(git_str *path)
{
/*
* The longest static path in a repository (or commondir) is the
@@ -248,7 +249,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
*
* Open a repository object from its path
*/
-static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf *common_path)
+static int is_valid_repository_path(bool *out, git_str *repository_path, git_str *common_path)
{
bool separate_commondir = false;
int error;
@@ -333,12 +334,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
return 0;
}
-static int load_workdir(git_repository *repo, git_config *config, git_buf *parent_path)
+static int load_workdir(git_repository *repo, git_config *config, git_str *parent_path)
{
int error;
git_config_entry *ce;
- git_buf worktree = GIT_BUF_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str worktree = GIT_STR_INIT;
+ git_str path = GIT_STR_INIT;
if (repo->is_bare)
return 0;
@@ -354,7 +355,7 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
goto cleanup;
}
- git_buf_attach(&worktree, gitlink, 0);
+ git_str_attach(&worktree, gitlink, 0);
if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
git_path_to_dir(&worktree) < 0) {
@@ -362,17 +363,17 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
goto cleanup;
}
- repo->workdir = git_buf_detach(&worktree);
+ repo->workdir = git_str_detach(&worktree);
}
else if (ce && ce->value) {
if ((error = git_path_prettify_dir(
&worktree, ce->value, repo->gitdir)) < 0)
goto cleanup;
- repo->workdir = git_buf_detach(&worktree);
+ repo->workdir = git_str_detach(&worktree);
}
else if (parent_path && git_path_isdir(parent_path->ptr))
- repo->workdir = git_buf_detach(parent_path);
+ repo->workdir = git_str_detach(parent_path);
else {
if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
git_path_to_dir(&worktree) < 0) {
@@ -380,12 +381,12 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
goto cleanup;
}
- repo->workdir = git_buf_detach(&worktree);
+ repo->workdir = git_str_detach(&worktree);
}
GIT_ERROR_CHECK_ALLOC(repo->workdir);
cleanup:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_config_entry_free(ce);
return error;
}
@@ -394,7 +395,7 @@ cleanup:
* This function returns furthest offset into path where a ceiling dir
* is found, so we can stop processing the path at that point.
*
- * Note: converting this to use git_bufs instead of GIT_PATH_MAX buffers on
+ * Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
* the stack could remove directories name limits, but at the cost of doing
* repeated malloc/frees inside the loop below, so let's not do it now.
*/
@@ -447,10 +448,10 @@ static size_t find_ceiling_dir_offset(
* it points to. Before calling, set `path_out` to the base directory that
* should be used if the contents of `file_path` are a relative path.
*/
-static int read_gitfile(git_buf *path_out, const char *file_path)
+static int read_gitfile(git_str *path_out, const char *file_path)
{
int error = 0;
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
GIT_ASSERT_ARG(path_out);
@@ -459,41 +460,41 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
if (git_futils_readbuffer(&file, file_path) < 0)
return -1;
- git_buf_rtrim(&file);
+ git_str_rtrim(&file);
/* apparently on Windows, some people use backslashes in paths */
git_path_mkposix(file.ptr);
- if (git_buf_len(&file) <= prefix_len ||
- memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
+ if (git_str_len(&file) <= prefix_len ||
+ memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
{
git_error_set(GIT_ERROR_REPOSITORY,
"the `.git` file at '%s' is malformed", file_path);
error = -1;
}
else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
- const char *gitlink = git_buf_cstr(&file) + prefix_len;
+ const char *gitlink = git_str_cstr(&file) + prefix_len;
while (*gitlink && git__isspace(*gitlink)) gitlink++;
error = git_path_prettify_dir(
- path_out, gitlink, git_buf_cstr(path_out));
+ path_out, gitlink, git_str_cstr(path_out));
}
- git_buf_dispose(&file);
+ git_str_dispose(&file);
return error;
}
static int find_repo(
- git_buf *gitdir_path,
- git_buf *workdir_path,
- git_buf *gitlink_path,
- git_buf *commondir_path,
+ git_str *gitdir_path,
+ git_str *workdir_path,
+ git_str *gitlink_path,
+ git_str *commondir_path,
const char *start_path,
uint32_t flags,
const char *ceiling_dirs)
{
- git_buf path = GIT_BUF_INIT;
- git_buf repo_link = GIT_BUF_INIT;
- git_buf common_link = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
+ git_str repo_link = GIT_STR_INIT;
+ git_str common_link = GIT_STR_INIT;
struct stat st;
dev_t initial_device = 0;
int min_iterations;
@@ -501,7 +502,7 @@ static int find_repo(
size_t ceiling_offset = 0;
int error;
- git_buf_clear(gitdir_path);
+ git_str_clear(gitdir_path);
error = git_path_prettify(&path, start_path, NULL);
if (error < 0)
@@ -525,7 +526,7 @@ static int find_repo(
for (;;) {
if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
if (!in_dot_git) {
- if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
+ if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
goto out;
}
in_dot_git = !in_dot_git;
@@ -545,14 +546,14 @@ static int find_repo(
if (is_valid) {
if ((error = git_path_to_dir(&path)) < 0 ||
- (error = git_buf_set(gitdir_path, path.ptr, path.size)) < 0)
+ (error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
goto out;
if (gitlink_path)
- if ((error = git_buf_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
+ if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
goto out;
if (commondir_path)
- git_buf_swap(&common_link, commondir_path);
+ git_str_swap(&common_link, commondir_path);
break;
}
@@ -562,13 +563,13 @@ static int find_repo(
goto out;
if (is_valid) {
- git_buf_swap(gitdir_path, &repo_link);
+ git_str_swap(gitdir_path, &repo_link);
if (gitlink_path)
- if ((error = git_buf_put(gitlink_path, path.ptr, path.size)) < 0)
+ if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
goto out;
if (commondir_path)
- git_buf_swap(&common_link, commondir_path);
+ git_str_swap(&common_link, commondir_path);
}
break;
}
@@ -592,8 +593,8 @@ static int find_repo(
}
if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
- if (!git_buf_len(gitdir_path))
- git_buf_clear(workdir_path);
+ if (!git_str_len(gitdir_path))
+ git_str_clear(workdir_path);
else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 ||
(error = git_path_to_dir(workdir_path)) < 0)
goto out;
@@ -601,16 +602,16 @@ static int find_repo(
/* If we didn't find the repository, and we don't have any other error
* to report, report that. */
- if (!git_buf_len(gitdir_path)) {
+ if (!git_str_len(gitdir_path)) {
git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
error = GIT_ENOTFOUND;
goto out;
}
out:
- git_buf_dispose(&path);
- git_buf_dispose(&repo_link);
- git_buf_dispose(&common_link);
+ git_str_dispose(&path);
+ git_str_dispose(&repo_link);
+ git_str_dispose(&common_link);
return error;
}
@@ -618,7 +619,7 @@ int git_repository_open_bare(
git_repository **repo_ptr,
const char *bare_path)
{
- git_buf path = GIT_BUF_INIT, common_path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
git_repository *repo = NULL;
bool is_valid;
int error;
@@ -628,8 +629,8 @@ int git_repository_open_bare(
return error;
if (!is_valid) {
- git_buf_dispose(&path);
- git_buf_dispose(&common_path);
+ git_str_dispose(&path);
+ git_str_dispose(&common_path);
git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
return GIT_ENOTFOUND;
}
@@ -637,9 +638,9 @@ int git_repository_open_bare(
repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo);
- repo->gitdir = git_buf_detach(&path);
+ repo->gitdir = git_str_detach(&path);
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
- repo->commondir = git_buf_detach(&common_path);
+ repo->commondir = git_str_detach(&common_path);
GIT_ERROR_CHECK_ALLOC(repo->commondir);
/* of course we're bare! */
@@ -658,15 +659,15 @@ static int _git_repository_open_ext_from_env(
git_repository *repo = NULL;
git_index *index = NULL;
git_odb *odb = NULL;
- git_buf dir_buf = GIT_BUF_INIT;
- git_buf ceiling_dirs_buf = GIT_BUF_INIT;
- git_buf across_fs_buf = GIT_BUF_INIT;
- git_buf index_file_buf = GIT_BUF_INIT;
- git_buf namespace_buf = GIT_BUF_INIT;
- git_buf object_dir_buf = GIT_BUF_INIT;
- git_buf alts_buf = GIT_BUF_INIT;
- git_buf work_tree_buf = GIT_BUF_INIT;
- git_buf common_dir_buf = GIT_BUF_INIT;
+ git_str dir_buf = GIT_STR_INIT;
+ git_str ceiling_dirs_buf = GIT_STR_INIT;
+ git_str across_fs_buf = GIT_STR_INIT;
+ git_str index_file_buf = GIT_STR_INIT;
+ git_str namespace_buf = GIT_STR_INIT;
+ git_str object_dir_buf = GIT_STR_INIT;
+ git_str alts_buf = GIT_STR_INIT;
+ git_str work_tree_buf = GIT_STR_INIT;
+ git_str common_dir_buf = GIT_STR_INIT;
const char *ceiling_dirs = NULL;
unsigned flags = 0;
int error;
@@ -679,7 +680,7 @@ static int _git_repository_open_ext_from_env(
} else if (error < 0)
goto error;
else {
- start_path = git_buf_cstr(&dir_buf);
+ start_path = git_str_cstr(&dir_buf);
flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
}
@@ -691,7 +692,7 @@ static int _git_repository_open_ext_from_env(
else if (error < 0)
goto error;
else
- ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
+ ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
if (error == GIT_ENOTFOUND)
@@ -700,7 +701,7 @@ static int _git_repository_open_ext_from_env(
goto error;
else {
int across_fs = 0;
- error = git_config_parse_bool(&across_fs, git_buf_cstr(&across_fs_buf));
+ error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
if (error < 0)
goto error;
if (across_fs)
@@ -713,7 +714,7 @@ static int _git_repository_open_ext_from_env(
else if (error < 0)
goto error;
else {
- error = git_index_open(&index, git_buf_cstr(&index_file_buf));
+ error = git_index_open(&index, git_str_cstr(&index_file_buf));
if (error < 0)
goto error;
}
@@ -730,7 +731,7 @@ static int _git_repository_open_ext_from_env(
else if (error < 0)
goto error;
else {
- error = git_odb_open(&odb, git_buf_cstr(&object_dir_buf));
+ error = git_odb_open(&odb, git_str_cstr(&object_dir_buf));
if (error < 0)
goto error;
}
@@ -779,7 +780,7 @@ static int _git_repository_open_ext_from_env(
goto error;
}
- end = git_buf_cstr(&alts_buf) + git_buf_len(&alts_buf);
+ end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
;
@@ -791,8 +792,8 @@ static int _git_repository_open_ext_from_env(
}
}
- if (git_buf_len(&namespace_buf)) {
- error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
+ if (git_str_len(&namespace_buf)) {
+ error = git_repository_set_namespace(repo, git_str_cstr(&namespace_buf));
if (error < 0)
goto error;
}
@@ -808,21 +809,21 @@ error:
success:
git_odb_free(odb);
git_index_free(index);
- git_buf_dispose(&common_dir_buf);
- git_buf_dispose(&work_tree_buf);
- git_buf_dispose(&alts_buf);
- git_buf_dispose(&object_dir_buf);
- git_buf_dispose(&namespace_buf);
- git_buf_dispose(&index_file_buf);
- git_buf_dispose(&across_fs_buf);
- git_buf_dispose(&ceiling_dirs_buf);
- git_buf_dispose(&dir_buf);
+ git_str_dispose(&common_dir_buf);
+ git_str_dispose(&work_tree_buf);
+ git_str_dispose(&alts_buf);
+ git_str_dispose(&object_dir_buf);
+ git_str_dispose(&namespace_buf);
+ git_str_dispose(&index_file_buf);
+ git_str_dispose(&across_fs_buf);
+ git_str_dispose(&ceiling_dirs_buf);
+ git_str_dispose(&dir_buf);
return error;
}
static int repo_is_worktree(unsigned *out, const git_repository *repo)
{
- git_buf gitdir_link = GIT_BUF_INIT;
+ git_str gitdir_link = GIT_STR_INIT;
int error;
/* Worktrees cannot have the same commondir and gitdir */
@@ -832,14 +833,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
return 0;
}
- if ((error = git_buf_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
+ if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
return -1;
/* A 'gitdir' file inside a git directory is currently
* only used when the repository is a working tree. */
*out = !!git_path_exists(gitdir_link.ptr);
- git_buf_dispose(&gitdir_link);
+ git_str_dispose(&gitdir_link);
return error;
}
@@ -851,8 +852,8 @@ int git_repository_open_ext(
{
int error;
unsigned is_worktree;
- git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
- gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
+ git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
+ gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
git_repository *repo = NULL;
git_config *config = NULL;
int version = 0;
@@ -872,15 +873,15 @@ int git_repository_open_ext(
repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo);
- repo->gitdir = git_buf_detach(&gitdir);
+ repo->gitdir = git_str_detach(&gitdir);
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
if (gitlink.size) {
- repo->gitlink = git_buf_detach(&gitlink);
+ repo->gitlink = git_str_detach(&gitlink);
GIT_ERROR_CHECK_ALLOC(repo->gitlink);
}
if (commondir.size) {
- repo->commondir = git_buf_detach(&commondir);
+ repo->commondir = git_str_detach(&commondir);
GIT_ERROR_CHECK_ALLOC(repo->commondir);
}
@@ -914,10 +915,10 @@ int git_repository_open_ext(
}
cleanup:
- git_buf_dispose(&gitdir);
- git_buf_dispose(&workdir);
- git_buf_dispose(&gitlink);
- git_buf_dispose(&commondir);
+ git_str_dispose(&gitdir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&gitlink);
+ git_str_dispose(&commondir);
git_config_free(config);
if (error < 0)
@@ -936,7 +937,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo = NULL;
size_t len;
int err;
@@ -952,7 +953,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
goto out;
}
- if ((err = git_buf_set(&path, wt->gitlink_path, len - 4)) < 0)
+ if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
goto out;
if ((err = git_repository_open(&repo, path.ptr)) < 0)
@@ -961,7 +962,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
*repo_out = repo;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return err;
}
@@ -986,14 +987,10 @@ int git_repository_discover(
const char *ceiling_dirs)
{
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
- int error;
GIT_ASSERT_ARG(start_path);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
+ GIT_BUF_WRAP_PRIVATE(out, find_repo, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
}
static int load_config(
@@ -1005,7 +1002,7 @@ static int load_config(
const char *programdata_path)
{
int error;
- git_buf config_path = GIT_BUF_INIT;
+ git_str config_path = GIT_STR_INIT;
git_config *cfg = NULL;
GIT_ASSERT_ARG(out);
@@ -1014,13 +1011,13 @@ static int load_config(
return error;
if (repo) {
- if ((error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
+ if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
if (error && error != GIT_ENOTFOUND)
goto on_error;
- git_buf_dispose(&config_path);
+ git_str_dispose(&config_path);
}
if (global_config_path != NULL &&
@@ -1053,15 +1050,15 @@ static int load_config(
return 0;
on_error:
- git_buf_dispose(&config_path);
+ git_str_dispose(&config_path);
git_config_free(cfg);
*out = NULL;
return error;
}
-static const char *path_unless_empty(git_buf *buf)
+static const char *path_unless_empty(git_str *buf)
{
- return git_buf_len(buf) > 0 ? git_buf_cstr(buf) : NULL;
+ return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
}
int git_repository_config__weakptr(git_config **out, git_repository *repo)
@@ -1069,19 +1066,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
int error = 0;
if (repo->_config == NULL) {
- git_buf global_buf = GIT_BUF_INIT;
- git_buf xdg_buf = GIT_BUF_INIT;
- git_buf system_buf = GIT_BUF_INIT;
- git_buf programdata_buf = GIT_BUF_INIT;
+ git_str global_buf = GIT_STR_INIT;
+ git_str xdg_buf = GIT_STR_INIT;
+ git_str system_buf = GIT_STR_INIT;
+ git_str programdata_buf = GIT_STR_INIT;
git_config *config;
- git_config_find_global(&global_buf);
- git_config_find_xdg(&xdg_buf);
- git_config_find_system(&system_buf);
- git_config_find_programdata(&programdata_buf);
+ git_config__find_global(&global_buf);
+ git_config__find_xdg(&xdg_buf);
+ git_config__find_system(&system_buf);
+ git_config__find_programdata(&programdata_buf);
/* If there is no global file, open a backend for it anyway */
- if (git_buf_len(&global_buf) == 0)
+ if (git_str_len(&global_buf) == 0)
git_config__global_location(&global_buf);
error = load_config(
@@ -1099,10 +1096,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
}
}
- git_buf_dispose(&global_buf);
- git_buf_dispose(&xdg_buf);
- git_buf_dispose(&system_buf);
- git_buf_dispose(&programdata_buf);
+ git_str_dispose(&global_buf);
+ git_str_dispose(&xdg_buf);
+ git_str_dispose(&system_buf);
+ git_str_dispose(&programdata_buf);
}
*out = repo->_config;
@@ -1147,10 +1144,10 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
*out = git_atomic_load(repo->_odb);
if (*out == NULL) {
- git_buf odb_path = GIT_BUF_INIT;
+ git_str odb_path = GIT_STR_INIT;
git_odb *odb;
- if ((error = git_repository_item_path(&odb_path, repo,
+ if ((error = git_repository__item_path(&odb_path, repo,
GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
(error = git_odb_new(&odb)) < 0)
return error;
@@ -1168,7 +1165,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
git_odb_free(odb);
}
- git_buf_dispose(&odb_path);
+ git_str_dispose(&odb_path);
*out = git_atomic_load(repo->_odb);
}
@@ -1244,10 +1241,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
GIT_ASSERT_ARG(repo);
if (repo->_index == NULL) {
- git_buf index_path = GIT_BUF_INIT;
+ git_str index_path = GIT_STR_INIT;
git_index *index;
- if ((error = git_buf_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
+ if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
return error;
error = git_index_open(&index, index_path.ptr);
@@ -1263,7 +1260,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
GIT_INDEX_CAPABILITY_FROM_OWNER);
}
- git_buf_dispose(&index_path);
+ git_str_dispose(&index_path);
}
*out = repo->_index;
@@ -1311,7 +1308,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
const char *def_dot_git = DOT_GIT;
size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
- git_buf *buf;
+ git_str *buf;
if (!name)
return 0;
@@ -1327,17 +1324,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
return -1;
- git_buf_attach(buf, name, name_len);
+ git_str_attach(buf, name, name_len);
return true;
}
bool git_repository__reserved_names(
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
{
GIT_UNUSED(include_ntfs);
if (repo->reserved_names.size == 0) {
- git_buf *buf;
+ git_str *buf;
size_t i;
/* Add the static defaults */
@@ -1389,7 +1386,7 @@ on_error:
}
#else
bool git_repository__reserved_names(
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
{
GIT_UNUSED(repo);
@@ -1435,7 +1432,7 @@ static git_vector user_extensions = GIT_VECTOR_INIT;
static int check_valid_extension(const git_config_entry *entry, void *payload)
{
- git_buf cfg = GIT_BUF_INIT;
+ git_str cfg = GIT_STR_INIT;
bool reject;
const char *extension;
size_t i;
@@ -1444,7 +1441,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
GIT_UNUSED(payload);
git_vector_foreach (&user_extensions, i, extension) {
- git_buf_clear(&cfg);
+ git_str_clear(&cfg);
/*
* Users can specify that they don't want to support an
@@ -1453,7 +1450,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
if ((reject = (extension[0] == '!')) == true)
extension = &extension[1];
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
goto done;
if (strcmp(entry->name, cfg.ptr) == 0) {
@@ -1467,7 +1464,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
extension = builtin_extensions[i];
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
goto done;
if (strcmp(entry->name, cfg.ptr) == 0)
@@ -1479,7 +1476,7 @@ fail:
error = -1;
done:
- git_buf_dispose(&cfg);
+ git_str_dispose(&cfg);
return error;
}
@@ -1557,12 +1554,12 @@ void git_repository__free_extensions(void)
int git_repository_create_head(const char *git_dir, const char *ref_name)
{
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
git_filebuf ref = GIT_FILEBUF_INIT;
const char *fmt;
int error;
- if ((error = git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
(error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
goto out;
@@ -1576,7 +1573,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
goto out;
out:
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
git_filebuf_cleanup(&ref);
return error;
}
@@ -1599,23 +1596,23 @@ static bool is_chmod_supported(const char *file_path)
static bool is_filesystem_case_insensitive(const char *gitdir_path)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int is_insensitive = -1;
- if (!git_buf_joinpath(&path, gitdir_path, "CoNfIg"))
- is_insensitive = git_path_exists(git_buf_cstr(&path));
+ if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
+ is_insensitive = git_path_exists(git_str_cstr(&path));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return is_insensitive;
}
static bool are_symlinks_supported(const char *wd_path)
{
git_config *config = NULL;
- git_buf global_buf = GIT_BUF_INIT;
- git_buf xdg_buf = GIT_BUF_INIT;
- git_buf system_buf = GIT_BUF_INIT;
- git_buf programdata_buf = GIT_BUF_INIT;
+ git_str global_buf = GIT_STR_INIT;
+ git_str xdg_buf = GIT_STR_INIT;
+ git_str system_buf = GIT_STR_INIT;
+ git_str programdata_buf = GIT_STR_INIT;
int symlinks = 0;
/*
@@ -1626,10 +1623,10 @@ static bool are_symlinks_supported(const char *wd_path)
* _not_ set, then we do not test or enable symlink support.
*/
#ifdef GIT_WIN32
- git_config_find_global(&global_buf);
- git_config_find_xdg(&xdg_buf);
- git_config_find_system(&system_buf);
- git_config_find_programdata(&programdata_buf);
+ git_config__find_global(&global_buf);
+ git_config__find_xdg(&xdg_buf);
+ git_config__find_system(&system_buf);
+ git_config__find_programdata(&programdata_buf);
if (load_config(&config, NULL,
path_unless_empty(&global_buf),
@@ -1646,10 +1643,10 @@ static bool are_symlinks_supported(const char *wd_path)
goto done;
done:
- git_buf_dispose(&global_buf);
- git_buf_dispose(&xdg_buf);
- git_buf_dispose(&system_buf);
- git_buf_dispose(&programdata_buf);
+ git_str_dispose(&global_buf);
+ git_str_dispose(&xdg_buf);
+ git_str_dispose(&system_buf);
+ git_str_dispose(&programdata_buf);
git_config_free(config);
return symlinks != 0;
}
@@ -1673,7 +1670,7 @@ static int create_empty_file(const char *path, mode_t mode)
static int repo_local_config(
git_config **out,
- git_buf *config_dir,
+ git_str *config_dir,
git_repository *repo,
const char *repo_dir)
{
@@ -1681,9 +1678,9 @@ static int repo_local_config(
git_config *parent;
const char *cfg_path;
- if (git_buf_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
+ if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
return -1;
- cfg_path = git_buf_cstr(config_dir);
+ cfg_path = git_str_cstr(config_dir);
/* make LOCAL config if missing */
if (!git_path_isfile(cfg_path) &&
@@ -1759,7 +1756,7 @@ static int repo_init_config(
uint32_t mode)
{
int error = 0;
- git_buf cfg_path = GIT_BUF_INIT, worktree_path = GIT_BUF_INIT;
+ git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
git_config *config = NULL;
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
@@ -1789,7 +1786,7 @@ static int repo_init_config(
SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
- if ((error = git_buf_sets(&worktree_path, work_dir)) < 0)
+ if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
goto cleanup;
if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
@@ -1813,8 +1810,8 @@ static int repo_init_config(
}
cleanup:
- git_buf_dispose(&cfg_path);
- git_buf_dispose(&worktree_path);
+ git_str_dispose(&cfg_path);
+ git_str_dispose(&worktree_path);
git_config_free(config);
return error;
@@ -1836,7 +1833,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
int git_repository_reinit_filesystem(git_repository *repo, int recurse)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config *config = NULL;
const char *repo_dir = git_repository_path(repo);
@@ -1845,7 +1842,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
config, path.ptr, repo_dir, git_repository_workdir(repo), true);
git_config_free(config);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_repository__configmap_lookup_cache_clear(repo);
@@ -1863,10 +1860,10 @@ static int repo_write_template(
bool hidden,
const char *content)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fd, error = 0, flags;
- if (git_buf_joinpath(&path, git_dir, file) < 0)
+ if (git_str_joinpath(&path, git_dir, file) < 0)
return -1;
if (allow_overwrite)
@@ -1874,7 +1871,7 @@ static int repo_write_template(
else
flags = O_WRONLY | O_CREAT | O_EXCL;
- fd = p_open(git_buf_cstr(&path), flags, mode);
+ fd = p_open(git_str_cstr(&path), flags, mode);
if (fd >= 0) {
error = p_write(fd, content, strlen(content));
@@ -1893,7 +1890,7 @@ static int repo_write_template(
GIT_UNUSED(hidden);
#endif
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error)
git_error_set(GIT_ERROR_OS,
@@ -1906,13 +1903,13 @@ static int repo_write_gitlink(
const char *in_dir, const char *to_repo, bool use_relative_path)
{
int error;
- git_buf buf = GIT_BUF_INIT;
- git_buf path_to_repo = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
+ git_str path_to_repo = GIT_STR_INIT;
struct stat st;
git_path_dirname_r(&buf, to_repo);
git_path_to_dir(&buf);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
/* don't write gitlink to natural workdir */
@@ -1923,7 +1920,7 @@ static int repo_write_gitlink(
goto cleanup;
}
- if ((error = git_buf_joinpath(&buf, in_dir, DOT_GIT)) < 0)
+ if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
goto cleanup;
if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
@@ -1933,22 +1930,22 @@ static int repo_write_gitlink(
goto cleanup;
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- error = git_buf_sets(&path_to_repo, to_repo);
+ error = git_str_sets(&path_to_repo, to_repo);
if (!error && use_relative_path)
error = git_path_make_relative(&path_to_repo, in_dir);
if (!error)
- error = git_buf_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
+ error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
if (!error)
error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
cleanup:
- git_buf_dispose(&buf);
- git_buf_dispose(&path_to_repo);
+ git_str_dispose(&buf);
+ git_str_dispose(&path_to_repo);
return error;
}
@@ -2001,12 +1998,12 @@ static int repo_init_structure(
git_config *cfg = NULL;
const char *tdir = NULL;
bool default_template = false;
- git_buf template_buf = GIT_BUF_INIT;
+ git_str template_buf = GIT_STR_INIT;
if (opts->template_path)
tdir = opts->template_path;
else if ((error = git_config_open_default(&cfg)) >= 0) {
- if (!git_config_get_path(&template_buf, cfg, "init.templatedir"))
+ if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
tdir = template_buf.ptr;
git_error_clear();
}
@@ -2032,7 +2029,7 @@ static int repo_init_structure(
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
}
- git_buf_dispose(&template_buf);
+ git_str_dispose(&template_buf);
git_config_free(cfg);
if (error < 0) {
@@ -2073,7 +2070,7 @@ static int repo_init_structure(
return error;
}
-static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
+static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
{
/* When making parent directories during repository initialization
* don't try to set gid or grant world write access
@@ -2085,8 +2082,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
}
static int repo_init_directories(
- git_buf *repo_path,
- git_buf *wd_path,
+ git_str *repo_path,
+ git_str *wd_path,
const char *given_repo,
git_repository_init_options *opts)
{
@@ -2124,7 +2121,7 @@ static int repo_init_directories(
git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
- if (git_buf_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
+ if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
return -1;
has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
@@ -2150,7 +2147,7 @@ static int repo_init_directories(
if (git_path_to_dir(wd_path) < 0)
return -1;
} else {
- git_buf_clear(wd_path);
+ git_str_clear(wd_path);
}
natural_wd =
@@ -2219,11 +2216,11 @@ static int repo_init_directories(
static int repo_init_head(const char *repo_dir, const char *given)
{
git_config *cfg = NULL;
- git_buf head_path = GIT_BUF_INIT, cfg_branch = GIT_BUF_INIT;
+ git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
const char *initial_head = NULL;
int error;
- if ((error = git_buf_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
goto out;
/*
@@ -2236,7 +2233,7 @@ static int repo_init_head(const char *repo_dir, const char *given)
if (given) {
initial_head = given;
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
- (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
+ (error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
*cfg_branch.ptr) {
initial_head = cfg_branch.ptr;
}
@@ -2248,8 +2245,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
out:
git_config_free(cfg);
- git_buf_dispose(&head_path);
- git_buf_dispose(&cfg_branch);
+ git_str_dispose(&head_path);
+ git_str_dispose(&cfg_branch);
return error;
}
@@ -2283,8 +2280,8 @@ int git_repository_init_ext(
const char *given_repo,
git_repository_init_options *opts)
{
- git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
- common_path = GIT_BUF_INIT;
+ git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
+ common_path = GIT_STR_INIT;
const char *wd;
bool is_valid;
int error;
@@ -2298,7 +2295,7 @@ int git_repository_init_ext(
if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
goto out;
- wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_buf_cstr(&wd_path);
+ wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
goto out;
@@ -2332,9 +2329,9 @@ int git_repository_init_ext(
goto out;
out:
- git_buf_dispose(&common_path);
- git_buf_dispose(&repo_path);
- git_buf_dispose(&wd_path);
+ git_str_dispose(&common_path);
+ git_str_dispose(&repo_path);
+ git_str_dispose(&wd_path);
return error;
}
@@ -2522,7 +2519,7 @@ static int repo_contains_no_reference(git_repository *repo)
return error;
}
-int git_repository_initialbranch(git_buf *out, git_repository *repo)
+int git_repository_initialbranch(git_str *out, git_repository *repo)
{
git_config *config;
git_config_entry *entry = NULL;
@@ -2543,8 +2540,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
goto done;
}
- if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
- (error = git_buf_puts(out, branch)) < 0 ||
+ if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
+ (error = git_str_puts(out, branch)) < 0 ||
(error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
goto done;
@@ -2561,7 +2558,7 @@ done:
int git_repository_is_empty(git_repository *repo)
{
git_reference *head = NULL;
- git_buf initialbranch = GIT_BUF_INIT;
+ git_str initialbranch = GIT_STR_INIT;
int result = 0;
if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
@@ -2574,7 +2571,7 @@ int git_repository_is_empty(git_repository *repo)
done:
git_reference_free(head);
- git_buf_dispose(&initialbranch);
+ git_str_dispose(&initialbranch);
return result;
}
@@ -2603,7 +2600,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
return parent;
}
-int git_repository_item_path(git_buf *out, const git_repository *repo, git_repository_item_t item)
+int git_repository_item_path(
+ git_buf *out,
+ const git_repository *repo,
+ git_repository_item_t item)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item);
+}
+
+int git_repository__item_path(
+ git_str *out,
+ const git_repository *repo,
+ git_repository_item_t item)
{
const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
if (parent == NULL) {
@@ -2611,11 +2619,11 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
return GIT_ENOTFOUND;
}
- if (git_buf_sets(out, parent) < 0)
+ if (git_str_sets(out, parent) < 0)
return -1;
if (items[item].name) {
- if (git_buf_joinpath(out, parent, items[item].name) < 0)
+ if (git_str_joinpath(out, parent, items[item].name) < 0)
return -1;
}
@@ -2644,7 +2652,7 @@ const char *git_repository_workdir(const git_repository *repo)
}
int git_repository_workdir_path(
- git_buf *out, git_repository *repo, const char *path)
+ git_str *out, git_repository *repo, const char *path)
{
int error;
@@ -2653,7 +2661,7 @@ int git_repository_workdir_path(
return GIT_EBAREREPO;
}
- if (!(error = git_buf_joinpath(out, repo->workdir, path)))
+ if (!(error = git_str_joinpath(out, repo->workdir, path)))
error = git_path_validate_workdir_buf(repo, out);
return error;
@@ -2669,7 +2677,7 @@ int git_repository_set_workdir(
git_repository *repo, const char *workdir, int update_gitlink)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(workdir);
@@ -2701,7 +2709,7 @@ int git_repository_set_workdir(
if (!error) {
char *old_workdir = repo->workdir;
- repo->workdir = git_buf_detach(&path);
+ repo->workdir = git_str_detach(&path);
repo->is_bare = 0;
git__free(old_workdir);
@@ -2770,13 +2778,13 @@ cleanup:
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
char orig_head_str[GIT_OID_HEXSZ];
int error = 0;
git_oid_fmt(orig_head_str, orig_head);
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
error = git_filebuf_commit(&file);
@@ -2784,46 +2792,48 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
-int git_repository_message(git_buf *out, git_repository *repo)
+static int git_repository__message(git_str *out, git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
int error;
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
- if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
+ if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
if (errno == ENOENT)
error = GIT_ENOTFOUND;
git_error_set(GIT_ERROR_OS, "could not access message file");
} else {
- error = git_futils_readbuffer(out, git_buf_cstr(&path));
+ error = git_futils_readbuffer(out, git_str_cstr(&path));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
+int git_repository_message(git_buf *out, git_repository *repo)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo);
+}
+
int git_repository_message_remove(git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
- error = p_unlink(git_buf_cstr(&path));
- git_buf_dispose(&path);
+ error = p_unlink(git_str_cstr(&path));
+ git_str_dispose(&path);
return error;
}
@@ -2839,7 +2849,7 @@ int git_repository_hashfile(
git_filter_list *fl = NULL;
git_file fd = -1;
uint64_t len;
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
const char *workdir = git_repository_workdir(repo);
/* as_path can be NULL */
@@ -2895,30 +2905,30 @@ cleanup:
if (fd >= 0)
p_close(fd);
git_filter_list_free(fl);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
-static int checkout_message(git_buf *out, git_reference *old, const char *new)
+static int checkout_message(git_str *out, git_reference *old, const char *new)
{
- git_buf_puts(out, "checkout: moving from ");
+ git_str_puts(out, "checkout: moving from ");
if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
- git_buf_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
+ git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
else
- git_buf_puts(out, git_oid_tostr_s(git_reference_target(old)));
+ git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
- git_buf_puts(out, " to ");
+ git_str_puts(out, " to ");
if (git_reference__is_branch(new) ||
git_reference__is_tag(new) ||
git_reference__is_remote(new))
- git_buf_puts(out, git_reference__shorthand(new));
+ git_str_puts(out, git_reference__shorthand(new));
else
- git_buf_puts(out, new);
+ git_str_puts(out, new);
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
return 0;
@@ -2927,7 +2937,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
static int detach(git_repository *repo, const git_oid *id, const char *new)
{
int error;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
git_object *object = NULL, *peeled = NULL;
git_reference *new_head = NULL, *current = NULL;
@@ -2949,10 +2959,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
if ((error = checkout_message(&log_message, current, new)) < 0)
goto cleanup;
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_buf_cstr(&log_message));
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message));
cleanup:
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
git_object_free(object);
git_object_free(peeled);
git_reference_free(current);
@@ -2965,7 +2975,7 @@ int git_repository_set_head(
const char *refname)
{
git_reference *ref = NULL, *current = NULL, *new_head = NULL;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(repo);
@@ -2992,18 +3002,18 @@ int git_repository_set_head(
if (!error) {
if (git_reference_is_branch(ref)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
- git_reference_name(ref), true, git_buf_cstr(&log_message));
+ git_reference_name(ref), true, git_str_cstr(&log_message));
} else {
error = detach(repo, git_reference_target(ref),
git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
}
} else if (git_reference__is_branch(refname)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
- true, git_buf_cstr(&log_message));
+ true, git_str_cstr(&log_message));
}
cleanup:
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
git_reference_free(current);
git_reference_free(ref);
git_reference_free(new_head);
@@ -3031,7 +3041,7 @@ int git_repository_detach_head(git_repository *repo)
{
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
git_object *object = NULL;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(repo);
@@ -3049,10 +3059,10 @@ int git_repository_detach_head(git_repository *repo)
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
- 1, git_buf_cstr(&log_message));
+ 1, git_str_cstr(&log_message));
cleanup:
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
git_object_free(object);
git_reference_free(old_head);
git_reference_free(new_head);
@@ -3066,12 +3076,12 @@ cleanup:
*/
int git_repository_state(git_repository *repo)
{
- git_buf repo_path = GIT_BUF_INIT;
+ git_str repo_path = GIT_STR_INIT;
int state = GIT_REPOSITORY_STATE_NONE;
GIT_ASSERT_ARG(repo);
- if (git_buf_puts(&repo_path, repo->gitdir) < 0)
+ if (git_str_puts(&repo_path, repo->gitdir) < 0)
return -1;
if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
@@ -3099,24 +3109,24 @@ int git_repository_state(git_repository *repo)
} else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
state = GIT_REPOSITORY_STATE_BISECT;
- git_buf_dispose(&repo_path);
+ git_str_dispose(&repo_path);
return state;
}
int git_repository__cleanup_files(
git_repository *repo, const char *files[], size_t files_len)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t i;
int error;
for (error = 0, i = 0; !error && i < files_len; ++i) {
const char *path;
- if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
+ if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
return -1;
- path = git_buf_cstr(&buf);
+ path = git_str_cstr(&buf);
if (git_path_isfile(path)) {
error = p_unlink(path);
@@ -3125,10 +3135,10 @@ int git_repository__cleanup_files(
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -3153,15 +3163,15 @@ int git_repository_state_cleanup(git_repository *repo)
int git_repository_is_shallow(git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
int error;
- if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
+ if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
return error;
error = git_path_lstat(path.ptr, &st);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error == GIT_ENOTFOUND) {
git_error_clear();