summaryrefslogtreecommitdiff
path: root/src
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
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 'src')
-rw-r--r--src/apply.c36
-rw-r--r--src/apply.h4
-rw-r--r--src/attr.c26
-rw-r--r--src/attr_file.c28
-rw-r--r--src/attr_file.h8
-rw-r--r--src/attrcache.c16
-rw-r--r--src/blob.c46
-rw-r--r--src/blob.h2
-rw-r--r--src/branch.c252
-rw-r--r--src/branch.h18
-rw-r--r--src/buf.c126
-rw-r--r--src/buf.h50
-rw-r--r--src/buffer.h374
-rw-r--r--src/checkout.c96
-rw-r--r--src/cherrypick.c20
-rw-r--r--src/clone.c116
-rw-r--r--src/commit.c148
-rw-r--r--src/commit.h23
-rw-r--r--src/commit_graph.c85
-rw-r--r--src/commit_graph.h9
-rw-r--r--src/common.h7
-rw-r--r--src/config.c163
-rw-r--r--src/config.h15
-rw-r--r--src/config_file.c144
-rw-r--r--src/config_mem.c18
-rw-r--r--src/config_parse.c38
-rw-r--r--src/crlf.c43
-rw-r--r--src/describe.c46
-rw-r--r--src/diff.c29
-rw-r--r--src/diff.h4
-rw-r--r--src/diff_driver.c52
-rw-r--r--src/diff_driver.h6
-rw-r--r--src/diff_file.c34
-rw-r--r--src/diff_generate.c8
-rw-r--r--src/diff_print.c197
-rw-r--r--src/diff_stats.c67
-rw-r--r--src/diff_stats.h (renamed from src/message.h)13
-rw-r--r--src/diff_tform.c6
-rw-r--r--src/email.c76
-rw-r--r--src/email.h2
-rw-r--r--src/errors.c36
-rw-r--r--src/fetchhead.c38
-rw-r--r--src/filebuf.c34
-rw-r--r--src/filter.c143
-rw-r--r--src/filter.h31
-rw-r--r--src/futils.c82
-rw-r--r--src/futils.h10
-rw-r--r--src/hash.c2
-rw-r--r--src/hash.h4
-rw-r--r--src/ident.c36
-rw-r--r--src/ignore.c44
-rw-r--r--src/ignore.h2
-rw-r--r--src/index.c68
-rw-r--r--src/indexer.c66
-rw-r--r--src/iterator.c82
-rw-r--r--src/iterator.h6
-rw-r--r--src/libgit2.c31
-rw-r--r--src/mailmap.c67
-rw-r--r--src/merge.c38
-rw-r--r--src/merge_driver.c2
-rw-r--r--src/message.c31
-rw-r--r--src/midx.c111
-rw-r--r--src/midx.h4
-rw-r--r--src/net.c128
-rw-r--r--src/net.h4
-rw-r--r--src/netops.c2
-rw-r--r--src/notes.c49
-rw-r--r--src/object.c13
-rw-r--r--src/object.h2
-rw-r--r--src/odb.c34
-rw-r--r--src/odb_loose.c116
-rw-r--r--src/odb_mempack.c23
-rw-r--r--src/odb_pack.c80
-rw-r--r--src/oid.c8
-rw-r--r--src/pack-objects.c45
-rw-r--r--src/pack-objects.h4
-rw-r--r--src/pack.c18
-rw-r--r--src/patch.c6
-rw-r--r--src/patch.h1
-rw-r--r--src/patch_generate.c10
-rw-r--r--src/patch_parse.c40
-rw-r--r--src/path.c194
-rw-r--r--src/path.h64
-rw-r--r--src/pathspec.c12
-rw-r--r--src/pathspec.h2
-rw-r--r--src/push.c14
-rw-r--r--src/reader.c16
-rw-r--r--src/reader.h4
-rw-r--r--src/rebase.c163
-rw-r--r--src/refdb_fs.c264
-rw-r--r--src/refs.c56
-rw-r--r--src/refs.h4
-rw-r--r--src/refspec.c69
-rw-r--r--src/refspec.h7
-rw-r--r--src/remote.c359
-rw-r--r--src/remote.h4
-rw-r--r--src/repository.c524
-rw-r--r--src/repository.h16
-rw-r--r--src/reset.c8
-rw-r--r--src/revert.c20
-rw-r--r--src/revparse.c62
-rw-r--r--src/revwalk.c12
-rw-r--r--src/signature.c4
-rw-r--r--src/signature.h2
-rw-r--r--src/sortedcache.c2
-rw-r--r--src/sortedcache.h2
-rw-r--r--src/stash.c73
-rw-r--r--src/str.c (renamed from src/buffer.c)279
-rw-r--r--src/str.h354
-rw-r--r--src/submodule.c297
-rw-r--r--src/sysdir.c96
-rw-r--r--src/sysdir.h18
-rw-r--r--src/tag.c47
-rw-r--r--src/threadstate.c4
-rw-r--r--src/threadstate.h2
-rw-r--r--src/trace.c2
-rw-r--r--src/trace.h10
-rw-r--r--src/transport.c14
-rw-r--r--src/transports/auth.c16
-rw-r--r--src/transports/auth.h3
-rw-r--r--src/transports/auth_negotiate.c25
-rw-r--r--src/transports/auth_ntlm.c20
-rw-r--r--src/transports/auth_ntlm.h1
-rw-r--r--src/transports/git.c20
-rw-r--r--src/transports/http.c4
-rw-r--r--src/transports/http.h5
-rw-r--r--src/transports/httpclient.c130
-rw-r--r--src/transports/local.c81
-rw-r--r--src/transports/smart.c10
-rw-r--r--src/transports/smart.h10
-rw-r--r--src/transports/smart_pkt.c66
-rw-r--r--src/transports/smart_protocol.c60
-rw-r--r--src/transports/ssh.c24
-rw-r--r--src/transports/winhttp.c70
-rw-r--r--src/tree-cache.c10
-rw-r--r--src/tree-cache.h4
-rw-r--r--src/tree.c54
-rw-r--r--src/tree.h2
-rw-r--r--src/util.c12
-rw-r--r--src/util.h8
-rw-r--r--src/win32/findfile.c44
-rw-r--r--src/win32/findfile.h8
-rw-r--r--src/win32/posix_w32.c9
-rw-r--r--src/win32/w32_buffer.c5
-rw-r--r--src/win32/w32_buffer.h5
-rw-r--r--src/worktree.c150
-rw-r--r--src/zstream.c10
-rw-r--r--src/zstream.h6
148 files changed, 4231 insertions, 3723 deletions
diff --git a/src/apply.c b/src/apply.c
index 7c65cd79d..18304da4d 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -265,7 +265,7 @@ done:
}
static int apply_hunks(
- git_buf *out,
+ git_str *out,
const char *source,
size_t source_len,
git_patch *patch,
@@ -286,7 +286,7 @@ static int apply_hunks(
}
git_vector_foreach(&image.lines, i, line)
- git_buf_put(out, line->content, line->content_len);
+ git_str_put(out, line->content, line->content_len);
done:
patch_image_free(&image);
@@ -295,24 +295,24 @@ done:
}
static int apply_binary_delta(
- git_buf *out,
+ git_str *out,
const char *source,
size_t source_len,
git_diff_binary_file *binary_file)
{
- git_buf inflated = GIT_BUF_INIT;
+ git_str inflated = GIT_STR_INIT;
int error = 0;
/* no diff means identical contents */
if (binary_file->datalen == 0)
- return git_buf_put(out, source, source_len);
+ return git_str_put(out, source, source_len);
error = git_zstream_inflatebuf(&inflated,
binary_file->data, binary_file->datalen);
if (!error && inflated.size != binary_file->inflatedlen) {
error = apply_err("inflated delta does not match expected length");
- git_buf_dispose(out);
+ git_str_dispose(out);
}
if (error < 0)
@@ -330,7 +330,7 @@ static int apply_binary_delta(
out->asize = data_len;
}
else if (binary_file->type == GIT_DIFF_BINARY_LITERAL) {
- git_buf_swap(out, &inflated);
+ git_str_swap(out, &inflated);
}
else {
error = apply_err("unknown binary delta type");
@@ -338,17 +338,17 @@ static int apply_binary_delta(
}
done:
- git_buf_dispose(&inflated);
+ git_str_dispose(&inflated);
return error;
}
static int apply_binary(
- git_buf *out,
+ git_str *out,
const char *source,
size_t source_len,
git_patch *patch)
{
- git_buf reverse = GIT_BUF_INIT;
+ git_str reverse = GIT_STR_INIT;
int error = 0;
if (!patch->binary.contains_data) {
@@ -378,14 +378,14 @@ static int apply_binary(
done:
if (error < 0)
- git_buf_dispose(out);
+ git_str_dispose(out);
- git_buf_dispose(&reverse);
+ git_str_dispose(&reverse);
return error;
}
int git_apply__patch(
- git_buf *contents_out,
+ git_str *contents_out,
char **filename_out,
unsigned int *mode_out,
const char *source,
@@ -423,13 +423,13 @@ int git_apply__patch(
else if (patch->hunks.size)
error = apply_hunks(contents_out, source, source_len, patch, &ctx);
else
- error = git_buf_put(contents_out, source, source_len);
+ error = git_str_put(contents_out, source, source_len);
if (error)
goto done;
if (patch->delta->status == GIT_DELTA_DELETED &&
- git_buf_len(contents_out) > 0) {
+ git_str_len(contents_out) > 0) {
error = apply_err("removal patch leaves file contents");
goto done;
}
@@ -456,7 +456,7 @@ static int apply_one(
const git_apply_options *opts)
{
git_patch *patch = NULL;
- git_buf pre_contents = GIT_BUF_INIT, post_contents = GIT_BUF_INIT;
+ git_str pre_contents = GIT_STR_INIT, post_contents = GIT_STR_INIT;
const git_diff_delta *delta;
char *filename = NULL;
unsigned int mode;
@@ -579,8 +579,8 @@ static int apply_one(
git_strmap_delete(removed_paths, delta->new_file.path);
done:
- git_buf_dispose(&pre_contents);
- git_buf_dispose(&post_contents);
+ git_str_dispose(&pre_contents);
+ git_str_dispose(&post_contents);
git__free(filename);
git_patch_free(patch);
diff --git a/src/apply.h b/src/apply.h
index 11ec75637..e990a7107 100644
--- a/src/apply.h
+++ b/src/apply.h
@@ -11,10 +11,10 @@
#include "git2/patch.h"
#include "git2/apply.h"
-#include "buffer.h"
+#include "str.h"
extern int git_apply__patch(
- git_buf *out,
+ git_str *out,
char **filename,
unsigned int *mode,
const char *source,
diff --git a/src/attr.c b/src/attr.c
index 95b49e3de..5849e701f 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -338,7 +338,7 @@ GIT_INLINE(int) preload_attr_file(
}
static int system_attr_file(
- git_buf *out,
+ git_str *out,
git_attr_session *attr_session)
{
int error;
@@ -366,11 +366,11 @@ static int system_attr_file(
if (attr_session->sysdir.size == 0)
return GIT_ENOTFOUND;
- /* We can safely provide a git_buf with no allocation (asize == 0) to
- * a consumer. This allows them to treat this as a regular `git_buf`,
- * but their call to `git_buf_dispose` will not attempt to free it.
+ /* We can safely provide a git_str with no allocation (asize == 0) to
+ * a consumer. This allows them to treat this as a regular `git_str`,
+ * but their call to `git_str_dispose` will not attempt to free it.
*/
- git_buf_attach_notowned(
+ git_str_attach_notowned(
out, attr_session->sysdir.ptr, attr_session->sysdir.size);
return 0;
}
@@ -380,7 +380,7 @@ static int attr_setup(
git_attr_session *attr_session,
git_attr_options *opts)
{
- git_buf system = GIT_BUF_INIT, info = GIT_BUF_INIT;
+ git_str system = GIT_STR_INIT, info = GIT_STR_INIT;
git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_HEAD, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source commit_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL };
@@ -411,7 +411,7 @@ static int attr_setup(
git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
goto out;
- if ((error = git_repository_item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ if ((error = git_repository__item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = preload_attr_file(repo, attr_session, info.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto out;
@@ -447,8 +447,8 @@ static int attr_setup(
attr_session->init_setup = 1;
out:
- git_buf_dispose(&system);
- git_buf_dispose(&info);
+ git_str_dispose(&system);
+ git_str_dispose(&info);
return error;
}
@@ -625,7 +625,7 @@ static int collect_attr_files(
git_vector *files)
{
int error = 0;
- git_buf dir = GIT_BUF_INIT, attrfile = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT, attrfile = GIT_STR_INIT;
const char *workdir = git_repository_workdir(repo);
attr_walk_up_info info = { NULL };
@@ -653,7 +653,7 @@ static int collect_attr_files(
* - $GIT_PREFIX/etc/gitattributes
*/
- if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ if ((error = git_repository__item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = push_attr_file(repo, attr_session, files, attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto cleanup;
@@ -693,8 +693,8 @@ static int collect_attr_files(
cleanup:
if (error < 0)
release_attr_files(files);
- git_buf_dispose(&attrfile);
- git_buf_dispose(&dir);
+ git_str_dispose(&attrfile);
+ git_str_dispose(&dir);
return error;
}
diff --git a/src/attr_file.c b/src/attr_file.c
index 71bd20a0f..09f0ce1b8 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -117,13 +117,13 @@ int git_attr_file__load(
git_tree *tree = NULL;
git_tree_entry *tree_entry = NULL;
git_blob *blob = NULL;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
const char *content_str;
git_attr_file *file;
struct stat st;
bool nonexistent = false;
int bom_offset;
- git_buf_bom_t bom;
+ git_str_bom_t bom;
git_oid id;
git_object_size_t blobsize;
@@ -143,7 +143,7 @@ int git_attr_file__load(
blobsize = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
- git_buf_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
+ git_str_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
break;
}
case GIT_ATTR_FILE_SOURCE_FILE: {
@@ -198,7 +198,7 @@ int git_attr_file__load(
blobsize = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
- if ((error = git_buf_put(&content,
+ if ((error = git_str_put(&content,
git_blob_rawcontent(blob), (size_t)blobsize)) < 0)
goto cleanup;
@@ -213,10 +213,10 @@ int git_attr_file__load(
goto cleanup;
/* advance over a UTF8 BOM */
- content_str = git_buf_cstr(&content);
- bom_offset = git_buf_detect_bom(&bom, &content);
+ content_str = git_str_cstr(&content);
+ bom_offset = git_str_detect_bom(&bom, &content);
- if (bom == GIT_BUF_BOM_UTF8)
+ if (bom == GIT_STR_BOM_UTF8)
content_str += bom_offset;
/* store the key of the attr_reader; don't bother with cache
@@ -250,7 +250,7 @@ cleanup:
git_tree_entry_free(tree_entry);
git_tree_free(tree);
git_commit_free(commit);
- git_buf_dispose(&content);
+ git_str_dispose(&content);
return error;
}
@@ -435,7 +435,7 @@ int git_attr_file__lookup_one(
int git_attr_file__load_standalone(git_attr_file **out, const char *path)
{
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
git_attr_file_source source = { GIT_ATTR_FILE_SOURCE_FILE };
git_attr_file *file = NULL;
int error;
@@ -457,7 +457,7 @@ int git_attr_file__load_standalone(git_attr_file **out, const char *path)
out:
if (error < 0)
git_attr_file__free(file);
- git_buf_dispose(&content);
+ git_str_dispose(&content);
return error;
}
@@ -558,7 +558,7 @@ int git_attr_path__init(
ssize_t root;
/* build full path as best we can */
- git_buf_init(&info->full, 0);
+ git_str_init(&info->full, 0);
if (git_path_join_unrooted(&info->full, path, base, &root) < 0)
return -1;
@@ -605,7 +605,7 @@ int git_attr_path__init(
void git_attr_path__free(git_attr_path *info)
{
- git_buf_dispose(&info->full);
+ git_str_dispose(&info->full);
info->path = NULL;
info->basename = NULL;
}
@@ -1020,8 +1020,8 @@ void git_attr_session__free(git_attr_session *session)
if (!session)
return;
- git_buf_dispose(&session->sysdir);
- git_buf_dispose(&session->tmp);
+ git_str_dispose(&session->sysdir);
+ git_str_dispose(&session->tmp);
memset(session, 0, sizeof(git_attr_session));
}
diff --git a/src/attr_file.h b/src/attr_file.h
index d634e6da9..08630d1a6 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -13,7 +13,7 @@
#include "git2/attr.h"
#include "vector.h"
#include "pool.h"
-#include "buffer.h"
+#include "str.h"
#include "futils.h"
#define GIT_ATTR_FILE ".gitattributes"
@@ -118,7 +118,7 @@ struct git_attr_file_entry {
};
typedef struct {
- git_buf full;
+ git_str full;
char *path;
char *basename;
int is_dir;
@@ -132,8 +132,8 @@ typedef struct {
int key;
unsigned int init_setup:1,
init_sysdir:1;
- git_buf sysdir;
- git_buf tmp;
+ git_str sysdir;
+ git_str tmp;
} git_attr_session;
extern int git_attr_session__init(git_attr_session *attr_session, git_repository *repo);
diff --git a/src/attrcache.c b/src/attrcache.c
index 2b36b7a9c..98d73cbc3 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -161,7 +161,7 @@ static int attr_cache_lookup(
git_attr_file_source *source)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
const char *wd = git_repository_workdir(repo);
const char *filename;
git_attr_cache *cache = git_repository_attr_cache(repo);
@@ -170,9 +170,9 @@ static int attr_cache_lookup(
/* join base and path as needed */
if (source->base != NULL && git_path_root(source->filename) < 0) {
- git_buf *p = attr_session ? &attr_session->tmp : &path;
+ git_str *p = attr_session ? &attr_session->tmp : &path;
- if (git_buf_joinpath(p, source->base, source->filename) < 0 ||
+ if (git_str_joinpath(p, source->base, source->filename) < 0 ||
git_path_validate_workdir_buf(repo, p) < 0)
return -1;
@@ -203,7 +203,7 @@ cleanup:
*out_file = file;
*out_entry = entry;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -281,7 +281,7 @@ bool git_attr_cache__is_cached(
static int attr_cache__lookup_path(
char **out, git_config *cfg, const char *key, const char *fallback)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
git_config_entry *entry = NULL;
@@ -296,17 +296,17 @@ static int attr_cache__lookup_path(
/* expand leading ~/ as needed */
if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') {
if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2])))
- *out = git_buf_detach(&buf);
+ *out = git_str_detach(&buf);
} else if (cfgval) {
*out = git__strdup(cfgval);
}
}
else if (!git_sysdir_find_xdg_file(&buf, fallback)) {
- *out = git_buf_detach(&buf);
+ *out = git_str_detach(&buf);
}
git_config_entry_free(entry);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/blob.c b/src/blob.c
index 09b5b5d91..6f57d09e4 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -12,6 +12,7 @@
#include "git2/repository.h"
#include "git2/odb_backend.h"
+#include "buf.h"
#include "filebuf.h"
#include "filter.h"
@@ -35,12 +36,12 @@ git_object_size_t git_blob_rawsize(const git_blob *blob)
return (git_object_size_t)git_odb_object_size(blob->data.odb);
}
-int git_blob__getbuf(git_buf *buffer, git_blob *blob)
+int git_blob__getbuf(git_str *buffer, git_blob *blob)
{
git_object_size_t size = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(size);
- return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size);
+ return git_str_set(buffer, git_blob_rawcontent(blob), (size_t)size);
}
void git_blob__free(void *_blob)
@@ -142,9 +143,9 @@ static int write_file_filtered(
git_repository* repo)
{
int error;
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- error = git_filter_list_apply_to_file(&tgt, fl, repo, full_path);
+ error = git_filter_list__apply_to_file(&tgt, fl, repo, full_path);
/* Write the file to disk if it was properly filtered */
if (!error) {
@@ -153,7 +154,7 @@ static int write_file_filtered(
error = git_odb_write(id, odb, tgt.ptr, tgt.size, GIT_OBJECT_BLOB);
}
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
return error;
}
@@ -193,7 +194,7 @@ int git_blob__create_from_paths(
git_odb *odb = NULL;
git_object_size_t size;
mode_t mode;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
GIT_ASSERT_ARG(hint_path || !try_load_filters);
@@ -261,7 +262,7 @@ int git_blob__create_from_paths(
done:
git_odb_free(odb);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -276,11 +277,11 @@ int git_blob_create_from_disk(
git_oid *id, git_repository *repo, const char *path)
{
int error;
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
const char *workdir, *hintpath = NULL;
if ((error = git_path_prettify(&full_path, path, NULL)) < 0) {
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -290,9 +291,9 @@ int git_blob_create_from_disk(
hintpath = full_path.ptr + strlen(workdir);
error = git_blob__create_from_paths(
- id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, !!hintpath);
+ id, NULL, repo, git_str_cstr(&full_path), hintpath, 0, !!hintpath);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -330,7 +331,7 @@ static int blob_writestream_write(git_writestream *_stream, const char *buffer,
int git_blob_create_from_stream(git_writestream **out, git_repository *repo, const char *hintpath)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
blob_writestream *stream;
GIT_ASSERT_ARG(out);
@@ -349,11 +350,11 @@ int git_blob_create_from_stream(git_writestream **out, git_repository *repo, con
stream->parent.close = blob_writestream_close;
stream->parent.free = blob_writestream_free;
- if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
- || (error = git_buf_joinpath(&path, path.ptr, "streamed")) < 0)
+ if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
+ || (error = git_str_joinpath(&path, path.ptr, "streamed")) < 0)
goto cleanup;
- if ((error = git_filebuf_open_withsize(&stream->fbuf, git_buf_cstr(&path), GIT_FILEBUF_TEMPORARY,
+ if ((error = git_filebuf_open_withsize(&stream->fbuf, git_str_cstr(&path), GIT_FILEBUF_TEMPORARY,
0666, 2 * 1024 * 1024)) < 0)
goto cleanup;
@@ -363,7 +364,7 @@ cleanup:
if (error < 0)
blob_writestream_free((git_writestream *) stream);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -391,16 +392,16 @@ cleanup:
int git_blob_is_binary(const git_blob *blob)
{
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
git_object_size_t size;
GIT_ASSERT_ARG(blob);
size = git_blob_rawsize(blob);
- git_buf_attach_notowned(&content, git_blob_rawcontent(blob),
+ git_str_attach_notowned(&content, git_blob_rawcontent(blob),
(size_t)min(size, GIT_FILTER_BYTES_TO_CHECK_NUL));
- return git_buf_is_binary(&content);
+ return git_str_is_binary(&content);
}
int git_blob_filter_options_init(
@@ -418,10 +419,10 @@ int git_blob_filter(
const char *path,
git_blob_filter_options *given_opts)
{
- int error = 0;
- git_filter_list *fl = NULL;
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
+ git_filter_list *fl = NULL;
+ int error = 0;
GIT_ASSERT_ARG(blob);
GIT_ASSERT_ARG(path);
@@ -430,9 +431,6 @@ int git_blob_filter(
GIT_ERROR_CHECK_VERSION(
given_opts, GIT_BLOB_FILTER_OPTIONS_VERSION, "git_blob_filter_options");
- if (git_buf_sanitize(out) < 0)
- return -1;
-
if (given_opts != NULL)
memcpy(&opts, given_opts, sizeof(git_blob_filter_options));
diff --git a/src/blob.h b/src/blob.h
index e5770991e..9a5dda225 100644
--- a/src/blob.h
+++ b/src/blob.h
@@ -38,7 +38,7 @@ struct git_blob {
void git_blob__free(void *blob);
int git_blob__parse(void *blob, git_odb_object *obj);
int git_blob__parse_raw(void *blob, const char *data, size_t size);
-int git_blob__getbuf(git_buf *buffer, git_blob *blob);
+int git_blob__getbuf(git_str *buffer, git_blob *blob);
extern int git_blob__create_from_paths(
git_oid *out_oid,
diff --git a/src/branch.c b/src/branch.c
index e6818a86d..cf985f153 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -7,6 +7,7 @@
#include "branch.h"
+#include "buf.h"
#include "commit.h"
#include "tag.h"
#include "config.h"
@@ -27,11 +28,11 @@ static int retrieve_branch_reference(
git_reference *branch = NULL;
int error = 0;
char *prefix;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
prefix = is_remote ? GIT_REFS_REMOTES_DIR : GIT_REFS_HEADS_DIR;
- if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0)
+ if ((error = git_str_joinpath(&ref_name, prefix, branch_name)) < 0)
/* OOM */;
else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
git_error_set(
@@ -40,7 +41,7 @@ static int retrieve_branch_reference(
*branch_reference_out = branch; /* will be NULL on error */
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
@@ -62,8 +63,8 @@ static int create_branch(
{
int is_unmovable_head = 0;
git_reference *branch = NULL;
- git_buf canonical_branch_name = GIT_BUF_INIT,
- log_message = GIT_BUF_INIT;
+ git_str canonical_branch_name = GIT_STR_INIT,
+ log_message = GIT_STR_INIT;
int error = -1;
int bare = git_repository_is_bare(repository);
@@ -96,22 +97,22 @@ static int create_branch(
goto cleanup;
}
- if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
+ if (git_str_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
- if (git_buf_printf(&log_message, "branch: Created from %s", from) < 0)
+ if (git_str_printf(&log_message, "branch: Created from %s", from) < 0)
goto cleanup;
error = git_reference_create(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force,
- git_buf_cstr(&log_message));
+ git_str_cstr(&canonical_branch_name), git_commit_id(commit), force,
+ git_str_cstr(&log_message));
if (!error)
*ref_out = branch;
cleanup:
- git_buf_dispose(&canonical_branch_name);
- git_buf_dispose(&log_message);
+ git_str_dispose(&canonical_branch_name);
+ git_str_dispose(&log_message);
return error;
}
@@ -174,7 +175,7 @@ int git_branch_is_checked_out(const git_reference *branch)
int git_branch_delete(git_reference *branch)
{
int is_head;
- git_buf config_section = GIT_BUF_INIT;
+ git_str config_section = GIT_STR_INIT;
int error = -1;
GIT_ASSERT_ARG(branch);
@@ -200,18 +201,18 @@ int git_branch_delete(git_reference *branch)
return -1;
}
- if (git_buf_join(&config_section, '.', "branch",
+ if (git_str_join(&config_section, '.', "branch",
git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0)
goto on_error;
if (git_config_rename_section(
- git_reference_owner(branch), git_buf_cstr(&config_section), NULL) < 0)
+ git_reference_owner(branch), git_str_cstr(&config_section), NULL) < 0)
goto on_error;
error = git_reference_delete(branch);
on_error:
- git_buf_dispose(&config_section);
+ git_str_dispose(&config_section);
return error;
}
@@ -286,10 +287,10 @@ int git_branch_move(
const char *new_branch_name,
int force)
{
- git_buf new_reference_name = GIT_BUF_INIT,
- old_config_section = GIT_BUF_INIT,
- new_config_section = GIT_BUF_INIT,
- log_message = GIT_BUF_INIT;
+ git_str new_reference_name = GIT_STR_INIT,
+ old_config_section = GIT_STR_INIT,
+ new_config_section = GIT_STR_INIT,
+ log_message = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(branch);
@@ -298,35 +299,35 @@ int git_branch_move(
if (!git_reference_is_branch(branch))
return not_a_local_branch(git_reference_name(branch));
- if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
+ if ((error = git_str_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
goto done;
- if ((error = git_buf_printf(&log_message, "branch: renamed %s to %s",
- git_reference_name(branch), git_buf_cstr(&new_reference_name))) < 0)
+ if ((error = git_str_printf(&log_message, "branch: renamed %s to %s",
+ git_reference_name(branch), git_str_cstr(&new_reference_name))) < 0)
goto done;
/* first update ref then config so failure won't trash config */
error = git_reference_rename(
- out, branch, git_buf_cstr(&new_reference_name), force,
- git_buf_cstr(&log_message));
+ out, branch, git_str_cstr(&new_reference_name), force,
+ git_str_cstr(&log_message));
if (error < 0)
goto done;
- git_buf_join(&old_config_section, '.', "branch",
+ git_str_join(&old_config_section, '.', "branch",
git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR));
- git_buf_join(&new_config_section, '.', "branch", new_branch_name);
+ git_str_join(&new_config_section, '.', "branch", new_branch_name);
error = git_config_rename_section(
git_reference_owner(branch),
- git_buf_cstr(&old_config_section),
- git_buf_cstr(&new_config_section));
+ git_str_cstr(&old_config_section),
+ git_str_cstr(&new_config_section));
done:
- git_buf_dispose(&new_reference_name);
- git_buf_dispose(&old_config_section);
- git_buf_dispose(&new_config_section);
- git_buf_dispose(&log_message);
+ git_str_dispose(&new_reference_name);
+ git_str_dispose(&old_config_section);
+ git_str_dispose(&new_config_section);
+ git_str_dispose(&log_message);
return error;
}
@@ -384,20 +385,20 @@ int git_branch_name(
}
static int retrieve_upstream_configuration(
- git_buf *out,
+ git_str *out,
const git_config *config,
const char *canonical_branch_name,
const char *format)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
- if (git_buf_printf(&buf, format,
+ if (git_str_printf(&buf, format,
canonical_branch_name + strlen(GIT_REFS_HEADS_DIR)) < 0)
return -1;
- error = git_config_get_string_buf(out, config, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ error = git_config__get_string_buf(out, config, git_str_cstr(&buf));
+ git_str_dispose(&buf);
return error;
}
@@ -406,20 +407,26 @@ int git_branch_upstream_name(
git_repository *repo,
const char *refname)
{
- git_buf remote_name = GIT_BUF_INIT;
- git_buf merge_name = GIT_BUF_INIT;
- git_buf buf = GIT_BUF_INIT;
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_name, repo, refname);
+}
+
+int git_branch__upstream_name(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
+{
+ git_str remote_name = GIT_STR_INIT;
+ git_str merge_name = GIT_STR_INIT;
+ git_str buf = GIT_STR_INIT;
int error = -1;
git_remote *remote = NULL;
const git_refspec *refspec;
git_config *config;
GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(refname);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
if (!git_reference__is_branch(refname))
return not_a_local_branch(refname);
@@ -434,75 +441,109 @@ int git_branch_upstream_name(
&merge_name, config, refname, "branch.%s.merge")) < 0)
goto cleanup;
- if (git_buf_len(&remote_name) == 0 || git_buf_len(&merge_name) == 0) {
+ if (git_str_len(&remote_name) == 0 || git_str_len(&merge_name) == 0) {
git_error_set(GIT_ERROR_REFERENCE,
"branch '%s' does not have an upstream", refname);
error = GIT_ENOTFOUND;
goto cleanup;
}
- if (strcmp(".", git_buf_cstr(&remote_name)) != 0) {
- if ((error = git_remote_lookup(&remote, repo, git_buf_cstr(&remote_name))) < 0)
+ if (strcmp(".", git_str_cstr(&remote_name)) != 0) {
+ if ((error = git_remote_lookup(&remote, repo, git_str_cstr(&remote_name))) < 0)
goto cleanup;
- refspec = git_remote__matching_refspec(remote, git_buf_cstr(&merge_name));
+ refspec = git_remote__matching_refspec(remote, git_str_cstr(&merge_name));
if (!refspec) {
error = GIT_ENOTFOUND;
goto cleanup;
}
- if (git_refspec_transform(&buf, refspec, git_buf_cstr(&merge_name)) < 0)
+ if (git_refspec__transform(&buf, refspec, git_str_cstr(&merge_name)) < 0)
goto cleanup;
} else
- if (git_buf_set(&buf, git_buf_cstr(&merge_name), git_buf_len(&merge_name)) < 0)
+ if (git_str_set(&buf, git_str_cstr(&merge_name), git_str_len(&merge_name)) < 0)
goto cleanup;
- error = git_buf_set(out, git_buf_cstr(&buf), git_buf_len(&buf));
+ git_str_swap(out, &buf);
cleanup:
git_config_free(config);
git_remote_free(remote);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&merge_name);
- git_buf_dispose(&buf);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&merge_name);
+ git_str_dispose(&buf);
return error;
}
-static int git_branch_upstream_with_format(git_buf *buf, git_repository *repo, const char *refname, const char *format, const char *format_name)
+static int git_branch_upstream_with_format(
+ git_str *out,
+ git_repository *repo,
+ const char *refname,
+ const char *format,
+ const char *format_name)
{
- int error;
git_config *cfg;
+ int error;
if (!git_reference__is_branch(refname))
return not_a_local_branch(refname);
- if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
- return error;
-
- if ((error = git_buf_sanitize(buf)) < 0 ||
- (error = retrieve_upstream_configuration(buf, cfg, refname, format)) < 0)
+ if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
+ (error = retrieve_upstream_configuration(out, cfg, refname, format)) < 0)
return error;
- if (git_buf_len(buf) == 0) {
+ if (git_str_len(out) == 0) {
git_error_set(GIT_ERROR_REFERENCE, "branch '%s' does not have an upstream %s", refname, format_name);
error = GIT_ENOTFOUND;
- git_buf_clear(buf);
}
return error;
}
-int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
+int git_branch_upstream_remote(
+ git_buf *out,
+ git_repository *repo,
+ const char *refname)
{
- return git_branch_upstream_with_format(buf, repo, refname, "branch.%s.remote", "remote");
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_remote, repo, refname);
}
-int git_branch_upstream_merge(git_buf *buf, git_repository *repo, const char *refname)
+int git_branch__upstream_remote(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
{
- return git_branch_upstream_with_format(buf, repo, refname, "branch.%s.merge", "merge");
+ return git_branch_upstream_with_format(out, repo, refname, "branch.%s.remote", "remote");
}
-int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
+int git_branch_upstream_merge(
+ git_buf *out,
+ git_repository *repo,
+ const char *refname)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__upstream_merge, repo, refname);
+}
+
+int git_branch__upstream_merge(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
+{
+ return git_branch_upstream_with_format(out, repo, refname, "branch.%s.merge", "merge");
+}
+
+int git_branch_remote_name(
+ git_buf *out,
+ git_repository *repo,
+ const char *refname)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_branch__remote_name, repo, refname);
+}
+
+int git_branch__remote_name(
+ git_str *out,
+ git_repository *repo,
+ const char *refname)
{
git_strarray remote_list = {0};
size_t i;
@@ -511,13 +552,10 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
int error = 0;
char *remote_name = NULL;
- GIT_ASSERT_ARG(buf);
+ GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(refname);
- if ((error = git_buf_sanitize(buf)) < 0)
- return error;
-
/* Verify that this is a remote branch */
if (!git_reference__is_remote(refname)) {
git_error_set(GIT_ERROR_INVALID, "reference '%s' is not a remote branch.",
@@ -557,8 +595,8 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
}
if (remote_name) {
- git_buf_clear(buf);
- error = git_buf_puts(buf, remote_name);
+ git_str_clear(out);
+ error = git_str_puts(out, remote_name);
} else {
git_error_set(GIT_ERROR_REFERENCE,
"could not determine remote for '%s'", refname);
@@ -567,7 +605,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
cleanup:
if (error < 0)
- git_buf_dispose(buf);
+ git_str_dispose(out);
git_strarray_dispose(&remote_list);
return error;
@@ -578,49 +616,49 @@ int git_branch_upstream(
const git_reference *branch)
{
int error;
- git_buf tracking_name = GIT_BUF_INIT;
+ git_str tracking_name = GIT_STR_INIT;
- if ((error = git_branch_upstream_name(&tracking_name,
+ if ((error = git_branch__upstream_name(&tracking_name,
git_reference_owner(branch), git_reference_name(branch))) < 0)
return error;
error = git_reference_lookup(
tracking_out,
git_reference_owner(branch),
- git_buf_cstr(&tracking_name));
+ git_str_cstr(&tracking_name));
- git_buf_dispose(&tracking_name);
+ git_str_dispose(&tracking_name);
return error;
}
static int unset_upstream(git_config *config, const char *shortname)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- if (git_buf_printf(&buf, "branch.%s.remote", shortname) < 0)
+ if (git_str_printf(&buf, "branch.%s.remote", shortname) < 0)
return -1;
- if (git_config_delete_entry(config, git_buf_cstr(&buf)) < 0)
+ if (git_config_delete_entry(config, git_str_cstr(&buf)) < 0)
goto on_error;
- git_buf_clear(&buf);
- if (git_buf_printf(&buf, "branch.%s.merge", shortname) < 0)
+ git_str_clear(&buf);
+ if (git_str_printf(&buf, "branch.%s.merge", shortname) < 0)
goto on_error;
- if (git_config_delete_entry(config, git_buf_cstr(&buf)) < 0)
+ if (git_config_delete_entry(config, git_str_cstr(&buf)) < 0)
goto on_error;
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return 0;
on_error:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return -1;
}
int git_branch_set_upstream(git_reference *branch, const char *branch_name)
{
- git_buf key = GIT_BUF_INIT, remote_name = GIT_BUF_INIT, merge_refspec = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, remote_name = GIT_STR_INIT, merge_refspec = GIT_STR_INIT;
git_reference *upstream;
git_repository *repo;
git_remote *remote = NULL;
@@ -662,31 +700,31 @@ int git_branch_set_upstream(git_reference *branch, const char *branch_name)
* name on the remote is and use that.
*/
if (local)
- error = git_buf_puts(&remote_name, ".");
+ error = git_str_puts(&remote_name, ".");
else
- error = git_branch_remote_name(&remote_name, repo, git_reference_name(upstream));
+ error = git_branch__remote_name(&remote_name, repo, git_reference_name(upstream));
if (error < 0)
goto on_error;
/* Update the upsteam branch config with the new name */
- if (git_buf_printf(&key, "branch.%s.remote", shortname) < 0)
+ if (git_str_printf(&key, "branch.%s.remote", shortname) < 0)
goto on_error;
- if (git_config_set_string(config, git_buf_cstr(&key), git_buf_cstr(&remote_name)) < 0)
+ if (git_config_set_string(config, git_str_cstr(&key), git_str_cstr(&remote_name)) < 0)
goto on_error;
if (local) {
/* A local branch uses the upstream refname directly */
- if (git_buf_puts(&merge_refspec, git_reference_name(upstream)) < 0)
+ if (git_str_puts(&merge_refspec, git_reference_name(upstream)) < 0)
goto on_error;
} else {
/* We transform the upstream branch name according to the remote's refspecs */
- if (git_remote_lookup(&remote, repo, git_buf_cstr(&remote_name)) < 0)
+ if (git_remote_lookup(&remote, repo, git_str_cstr(&remote_name)) < 0)
goto on_error;
fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream));
- if (!fetchspec || git_refspec_rtransform(&merge_refspec, fetchspec, git_reference_name(upstream)) < 0)
+ if (!fetchspec || git_refspec__rtransform(&merge_refspec, fetchspec, git_reference_name(upstream)) < 0)
goto on_error;
git_remote_free(remote);
@@ -694,25 +732,25 @@ int git_branch_set_upstream(git_reference *branch, const char *branch_name)
}
/* Update the merge branch config with the refspec */
- git_buf_clear(&key);
- if (git_buf_printf(&key, "branch.%s.merge", shortname) < 0)
+ git_str_clear(&key);
+ if (git_str_printf(&key, "branch.%s.merge", shortname) < 0)
goto on_error;
- if (git_config_set_string(config, git_buf_cstr(&key), git_buf_cstr(&merge_refspec)) < 0)
+ if (git_config_set_string(config, git_str_cstr(&key), git_str_cstr(&merge_refspec)) < 0)
goto on_error;
git_reference_free(upstream);
- git_buf_dispose(&key);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&merge_refspec);
+ git_str_dispose(&key);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&merge_refspec);
return 0;
on_error:
git_reference_free(upstream);
- git_buf_dispose(&key);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&merge_refspec);
+ git_str_dispose(&key);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&merge_refspec);
git_remote_free(remote);
return -1;
@@ -749,7 +787,7 @@ int git_branch_is_head(
int git_branch_name_is_valid(int *valid, const char *name)
{
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error = 0;
GIT_ASSERT(valid);
@@ -765,13 +803,13 @@ int git_branch_name_is_valid(int *valid, const char *name)
if (!name || name[0] == '-' || !git__strcmp(name, "HEAD"))
goto done;
- if ((error = git_buf_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 ||
- (error = git_buf_puts(&ref_name, name)) < 0)
+ if ((error = git_str_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 ||
+ (error = git_str_puts(&ref_name, name)) < 0)
goto done;
error = git_reference_name_is_valid(valid, ref_name.ptr);
done:
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
diff --git a/src/branch.h b/src/branch.h
index 5ae227c05..b4db42a01 100644
--- a/src/branch.h
+++ b/src/branch.h
@@ -9,10 +9,22 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
-int git_branch_upstream__name(
- git_buf *tracking_name,
+int git_branch__remote_name(
+ git_str *out,
+ git_repository *repo,
+ const char *refname);
+int git_branch__upstream_remote(
+ git_str *out,
+ git_repository *repo,
+ const char *refname);
+int git_branch__upstream_merge(
+ git_str *out,
+ git_repository *repo,
+ const char *refname);
+int git_branch__upstream_name(
+ git_str *tracking_name,
git_repository *repo,
const char *canonical_branch_name);
diff --git a/src/buf.c b/src/buf.c
new file mode 100644
index 000000000..652f5dd52
--- /dev/null
+++ b/src/buf.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "buf.h"
+#include "common.h"
+
+int git_buf_sanitize(git_buf *buf)
+{
+ GIT_ASSERT_ARG(buf);
+
+ if (buf->reserved > 0)
+ buf->ptr[0] = '\0';
+ else
+ buf->ptr = git_str__initstr;
+
+ buf->size = 0;
+ return 0;
+}
+
+int git_buf_tostr(git_str *out, git_buf *buf)
+{
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(buf);
+
+ if (git_buf_sanitize(buf) < 0)
+ return -1;
+
+ out->ptr = buf->ptr;
+ out->asize = buf->reserved;
+ out->size = buf->size;
+
+ buf->ptr = git_str__initstr;
+ buf->reserved = 0;
+ buf->size = 0;
+
+ return 0;
+}
+
+int git_buf_fromstr(git_buf *out, git_str *str)
+{
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(str);
+
+ out->ptr = str->ptr;
+ out->reserved = str->asize;
+ out->size = str->size;
+
+ str->ptr = git_str__initstr;
+ str->asize = 0;
+ str->size = 0;
+
+ return 0;
+}
+
+void git_buf_dispose(git_buf *buf)
+{
+ if (!buf)
+ return;
+
+ if (buf->ptr != git_str__initstr)
+ git__free(buf->ptr);
+
+ buf->ptr = git_str__initstr;
+ buf->reserved = 0;
+ buf->size = 0;
+}
+
+#ifndef GIT_DEPRECATE_HARD
+int git_buf_grow(git_buf *buffer, size_t target_size)
+{
+ char *newptr;
+
+ if (buffer->reserved >= target_size)
+ return 0;
+
+ if (buffer->ptr == git_str__initstr)
+ newptr = git__malloc(target_size);
+ else
+ newptr = git__realloc(buffer->ptr, target_size);
+
+ if (!newptr)
+ return -1;
+
+ buffer->ptr = newptr;
+ buffer->reserved = target_size;
+ return 0;
+}
+
+int git_buf_set(git_buf *buffer, const void *data, size_t datalen)
+{
+ size_t alloclen;
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, datalen, 1);
+
+ if (git_buf_grow(buffer, alloclen) < 0)
+ return -1;
+
+ memmove(buffer->ptr, data, datalen);
+ buffer->size = datalen;
+ buffer->ptr[buffer->size] = '\0';
+
+ return 0;
+}
+
+int git_buf_is_binary(const git_buf *buf)
+{
+ git_str str = GIT_STR_INIT_CONST(buf->ptr, buf->size);
+ return git_str_is_binary(&str);
+}
+
+int git_buf_contains_nul(const git_buf *buf)
+{
+ git_str str = GIT_STR_INIT_CONST(buf->ptr, buf->size);
+ return git_str_contains_nul(&str);
+}
+
+void git_buf_free(git_buf *buffer)
+{
+ git_buf_dispose(buffer);
+}
+
+#endif
diff --git a/src/buf.h b/src/buf.h
new file mode 100644
index 000000000..4bc7f2709
--- /dev/null
+++ b/src/buf.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_buf_h__
+#define INCLUDE_buf_h__
+
+#include "git2/buffer.h"
+#include "common.h"
+
+/*
+ * Adapts a private API that takes a `git_str` into a public API that
+ * takes a `git_buf`.
+ */
+
+#define GIT_BUF_WRAP_PRIVATE(buf, fn, ...) \
+ { \
+ git_str str = GIT_STR_INIT; \
+ int error; \
+ if ((error = git_buf_tostr(&str, buf)) == 0 && \
+ (error = fn(&str, __VA_ARGS__)) == 0) \
+ error = git_buf_fromstr(buf, &str); \
+ git_str_dispose(&str); \
+ return error; \
+}
+
+/**
+ * "Sanitizes" a buffer from user input. This simply ensures that the
+ * `git_buf` has nice defaults if the user didn't set the members to
+ * anything, so that if we return early we don't leave it populated
+ * with nonsense.
+ */
+extern int git_buf_sanitize(git_buf *from_user);
+
+/**
+ * Populate a `git_str` from a `git_buf` for passing to libgit2 internal
+ * functions. Sanitizes the given `git_buf` before proceeding. The
+ * `git_buf` will no longer point to this memory.
+ */
+extern int git_buf_tostr(git_str *out, git_buf *buf);
+
+/**
+ * Populate a `git_buf` from a `git_str` for returning to a user.
+ * The `git_str` will no longer point to this memory.
+ */
+extern int git_buf_fromstr(git_buf *out, git_str *str);
+
+#endif
diff --git a/src/buffer.h b/src/buffer.h
deleted file mode 100644
index 75930e209..000000000
--- a/src/buffer.h
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_buffer_h__
-#define INCLUDE_buffer_h__
-
-#include "common.h"
-#include "git2/strarray.h"
-#include "git2/buffer.h"
-
-/* typedef struct {
- * char *ptr;
- * size_t asize, size;
- * } git_buf;
- */
-
-typedef enum {
- GIT_BUF_BOM_NONE = 0,
- GIT_BUF_BOM_UTF8 = 1,
- GIT_BUF_BOM_UTF16_LE = 2,
- GIT_BUF_BOM_UTF16_BE = 3,
- GIT_BUF_BOM_UTF32_LE = 4,
- GIT_BUF_BOM_UTF32_BE = 5
-} git_buf_bom_t;
-
-typedef struct {
- git_buf_bom_t bom; /* BOM found at head of text */
- unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
- unsigned int printable, nonprintable; /* These are just approximations! */
-} git_buf_text_stats;
-
-extern char git_buf__initbuf[];
-extern char git_buf__oom[];
-
-/* Use to initialize buffer structure when git_buf is on stack */
-#define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
-
-/**
- * Static initializer for git_buf from static buffer
- */
-#ifdef GIT_DEPRECATE_HARD
-# define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
-#endif
-
-GIT_INLINE(bool) git_buf_is_allocated(const git_buf *buf)
-{
- return (buf->ptr != NULL && buf->asize > 0);
-}
-
-/**
- * Initialize a git_buf structure.
- *
- * For the cases where GIT_BUF_INIT cannot be used to do static
- * initialization.
- */
-extern int git_buf_init(git_buf *buf, size_t initial_size);
-
-#ifdef GIT_DEPRECATE_HARD
-
-/**
- * Resize the buffer allocation to make more space.
- *
- * This will attempt to grow the buffer to accommodate the target size.
- *
- * If the buffer refers to memory that was not allocated by libgit2 (i.e.
- * the `asize` field is zero), then `ptr` will be replaced with a newly
- * allocated block of data. Be careful so that memory allocated by the
- * caller is not lost. As a special variant, if you pass `target_size` as
- * 0 and the memory is not allocated by libgit2, this will allocate a new
- * buffer of size `size` and copy the external data into it.
- *
- * Currently, this will never shrink a buffer, only expand it.
- *
- * If the allocation fails, this will return an error and the buffer will be
- * marked as invalid for future operations, invaliding the contents.
- *
- * @param buffer The buffer to be resized; may or may not be allocated yet
- * @param target_size The desired available size
- * @return 0 on success, -1 on allocation failure
- */
-int git_buf_grow(git_buf *buffer, size_t target_size);
-
-#endif
-
-/**
- * Resize the buffer allocation to make more space.
- *
- * This will attempt to grow the buffer to accommodate the additional size.
- * It is similar to `git_buf_grow`, but performs the new size calculation,
- * checking for overflow.
- *
- * Like `git_buf_grow`, if this is a user-supplied buffer, this will allocate
- * a new buffer.
- */
-extern int git_buf_grow_by(git_buf *buffer, size_t additional_size);
-
-/**
- * Attempt to grow the buffer to hold at least `target_size` bytes.
- *
- * If the allocation fails, this will return an error. If `mark_oom` is true,
- * this will mark the buffer as invalid for future operations; if false,
- * existing buffer content will be preserved, but calling code must handle
- * that buffer was not expanded. If `preserve_external` is true, then any
- * existing data pointed to be `ptr` even if `asize` is zero will be copied
- * into the newly allocated buffer.
- */
-extern int git_buf_try_grow(
- git_buf *buf, size_t target_size, bool mark_oom);
-
-/**
- * Sanitizes git_buf structures provided from user input. Users of the
- * library, when providing git_buf's, may wish to provide a NULL ptr for
- * ease of handling. The buffer routines, however, expect a non-NULL ptr
- * always. This helper method simply handles NULL input, converting to a
- * git_buf__initbuf. If a buffer with a non-NULL ptr is passed in, this method
- * assures that the buffer is '\0'-terminated.
- */
-extern int git_buf_sanitize(git_buf *buf);
-
-extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
-extern char *git_buf_detach(git_buf *buf);
-extern int git_buf_attach(git_buf *buf, char *ptr, size_t asize);
-
-/* Populates a `git_buf` where the contents are not "owned" by the
- * buffer, and calls to `git_buf_dispose` will not free the given buf.
- */
-extern void git_buf_attach_notowned(
- git_buf *buf, const char *ptr, size_t size);
-
-/**
- * Test if there have been any reallocation failures with this git_buf.
- *
- * Any function that writes to a git_buf can fail due to memory allocation
- * issues. If one fails, the git_buf will be marked with an OOM error and
- * further calls to modify the buffer will fail. Check git_buf_oom() at the
- * end of your sequence and it will be true if you ran out of memory at any
- * point with that buffer.
- *
- * @return false if no error, true if allocation error
- */
-GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
-{
- return (buf->ptr == git_buf__oom);
-}
-
-/*
- * Functions below that return int value error codes will return 0 on
- * success or -1 on failure (which generally means an allocation failed).
- * Using a git_buf where the allocation has failed with result in -1 from
- * all further calls using that buffer. As a result, you can ignore the
- * return code of these functions and call them in a series then just call
- * git_buf_oom at the end.
- */
-
-#ifdef GIT_DEPRECATE_HARD
-int git_buf_set(git_buf *buffer, const void *data, size_t datalen);
-#endif
-
-int git_buf_sets(git_buf *buf, const char *string);
-int git_buf_putc(git_buf *buf, char c);
-int git_buf_putcn(git_buf *buf, char c, size_t len);
-int git_buf_put(git_buf *buf, const char *data, size_t len);
-int git_buf_puts(git_buf *buf, const char *string);
-int git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
-int git_buf_vprintf(git_buf *buf, const char *format, va_list ap);
-void git_buf_clear(git_buf *buf);
-void git_buf_consume_bytes(git_buf *buf, size_t len);
-void git_buf_consume(git_buf *buf, const char *end);
-void git_buf_truncate(git_buf *buf, size_t len);
-void git_buf_shorten(git_buf *buf, size_t amount);
-void git_buf_truncate_at_char(git_buf *buf, char separator);
-void git_buf_rtruncate_at_char(git_buf *path, char separator);
-
-/** General join with separator */
-int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...);
-/** Fast join of two strings - first may legally point into `buf` data */
-int git_buf_join(git_buf *buf, char separator, const char *str_a, const char *str_b);
-/** Fast join of three strings - cannot reference `buf` data */
-int git_buf_join3(git_buf *buf, char separator, const char *str_a, const char *str_b, const char *str_c);
-
-/**
- * Join two strings as paths, inserting a slash between as needed.
- * @return 0 on success, -1 on failure
- */
-GIT_INLINE(int) git_buf_joinpath(git_buf *buf, const char *a, const char *b)
-{
- return git_buf_join(buf, '/', a, b);
-}
-
-GIT_INLINE(const char *) git_buf_cstr(const git_buf *buf)
-{
- return buf->ptr;
-}
-
-GIT_INLINE(size_t) git_buf_len(const git_buf *buf)
-{
- return buf->size;
-}
-
-int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
-
-#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
-
-GIT_INLINE(ssize_t) git_buf_rfind_next(const git_buf *buf, char ch)
-{
- ssize_t idx = (ssize_t)buf->size - 1;
- while (idx >= 0 && buf->ptr[idx] == ch) idx--;
- while (idx >= 0 && buf->ptr[idx] != ch) idx--;
- return idx;
-}
-
-GIT_INLINE(ssize_t) git_buf_rfind(const git_buf *buf, char ch)
-{
- ssize_t idx = (ssize_t)buf->size - 1;
- while (idx >= 0 && buf->ptr[idx] != ch) idx--;
- return idx;
-}
-
-GIT_INLINE(ssize_t) git_buf_find(const git_buf *buf, char ch)
-{
- void *found = memchr(buf->ptr, ch, buf->size);
- return found ? (ssize_t)((const char *)found - buf->ptr) : -1;
-}
-
-/* Remove whitespace from the end of the buffer */
-void git_buf_rtrim(git_buf *buf);
-
-int git_buf_cmp(const git_buf *a, const git_buf *b);
-
-/* Quote and unquote a buffer as specified in
- * http://marc.info/?l=git&m=112927316408690&w=2
- */
-int git_buf_quote(git_buf *buf);
-int git_buf_unquote(git_buf *buf);
-
-/* Write data as base64 encoded in buffer */
-int git_buf_encode_base64(git_buf *buf, const char *data, size_t len);
-/* Decode the given bas64 and write the result to the buffer */
-int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len);
-
-/* Write data as "base85" encoded in buffer */
-int git_buf_encode_base85(git_buf *buf, const char *data, size_t len);
-/* Decode the given "base85" and write the result to the buffer */
-int git_buf_decode_base85(git_buf *buf, const char *base64, size_t len, size_t output_len);
-
-/* Decode the given percent-encoded string and write the result to the buffer */
-int git_buf_decode_percent(git_buf *buf, const char *str, size_t len);
-
-/*
- * Insert, remove or replace a portion of the buffer.
- *
- * @param buf The buffer to work with
- *
- * @param where The location in the buffer where the transformation
- * should be applied.
- *
- * @param nb_to_remove The number of chars to be removed. 0 to not
- * remove any character in the buffer.
- *
- * @param data A pointer to the data which should be inserted.
- *
- * @param nb_to_insert The number of chars to be inserted. 0 to not
- * insert any character from the buffer.
- *
- * @return 0 or an error code.
- */
-int git_buf_splice(
- git_buf *buf,
- size_t where,
- size_t nb_to_remove,
- const char *data,
- size_t nb_to_insert);
-
-/**
- * Append string to buffer, prefixing each character from `esc_chars` with
- * `esc_with` string.
- *
- * @param buf Buffer to append data to
- * @param string String to escape and append
- * @param esc_chars Characters to be escaped
- * @param esc_with String to insert in from of each found character
- * @return 0 on success, <0 on failure (probably allocation problem)
- */
-extern int git_buf_puts_escaped(
- git_buf *buf,
- const char *string,
- const char *esc_chars,
- const char *esc_with);
-
-/**
- * Append string escaping characters that are regex special
- */
-GIT_INLINE(int) git_buf_puts_escape_regex(git_buf *buf, const char *string)
-{
- return git_buf_puts_escaped(buf, string, "^.[]$()|*+?{}\\", "\\");
-}
-
-/**
- * Unescape all characters in a buffer in place
- *
- * I.e. remove backslashes
- */
-extern void git_buf_unescape(git_buf *buf);
-
-/**
- * Replace all \r\n with \n.
- *
- * @return 0 on success, -1 on memory error
- */
-extern int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src);
-
-/**
- * Replace all \n with \r\n. Does not modify existing \r\n.
- *
- * @return 0 on success, -1 on memory error
- */
-extern int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src);
-
-/**
- * Fill buffer with the common prefix of a array of strings
- *
- * Buffer will be set to empty if there is no common prefix
- */
-extern int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count);
-
-/**
- * Check if a buffer begins with a UTF BOM
- *
- * @param bom Set to the type of BOM detected or GIT_BOM_NONE
- * @param buf Buffer in which to check the first bytes for a BOM
- * @return Number of bytes of BOM data (or 0 if no BOM found)
- */
-extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
-
-/**
- * Gather stats for a piece of text
- *
- * Fill the `stats` structure with counts of unreadable characters, carriage
- * returns, etc, so it can be used in heuristics. This automatically skips
- * a trailing EOF (\032 character). Also it will look for a BOM at the
- * start of the text and can be told to skip that as well.
- *
- * @param stats Structure to be filled in
- * @param buf Text to process
- * @param skip_bom Exclude leading BOM from stats if true
- * @return Does the buffer heuristically look like binary data
- */
-extern bool git_buf_gather_text_stats(
- git_buf_text_stats *stats, const git_buf *buf, bool skip_bom);
-
-#ifdef GIT_DEPRECATE_HARD
-
-/**
-* Check quickly if buffer looks like it contains binary data
-*
-* @param buf Buffer to check
-* @return 1 if buffer looks like non-text data
-*/
-int git_buf_is_binary(const git_buf *buf);
-
-/**
-* Check quickly if buffer contains a NUL byte
-*
-* @param buf Buffer to check
-* @return 1 if buffer contains a NUL byte
-*/
-int git_buf_contains_nul(const git_buf *buf);
-
-#endif
-
-#endif
diff --git a/src/checkout.c b/src/checkout.c
index 3a171066b..b31918fc8 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -61,9 +61,9 @@ typedef struct {
git_vector update_conflicts;
git_vector *update_reuc;
git_vector *update_names;
- git_buf target_path;
+ git_str target_path;
size_t target_len;
- git_buf tmp;
+ git_str tmp;
unsigned int strategy;
int can_symlink;
int respect_filemode;
@@ -321,11 +321,11 @@ static int checkout_action_no_wd(
}
static int checkout_target_fullpath(
- git_buf **out, checkout_data *data, const char *path)
+ git_str **out, checkout_data *data, const char *path)
{
- git_buf_truncate(&data->target_path, data->target_len);
+ git_str_truncate(&data->target_path, data->target_len);
- if (path && git_buf_puts(&data->target_path, path) < 0)
+ if (path && git_str_puts(&data->target_path, path) < 0)
return -1;
if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
@@ -339,7 +339,7 @@ static int checkout_target_fullpath(
static bool wd_item_is_removable(
checkout_data *data, const git_index_entry *wd)
{
- git_buf *full;
+ git_str *full;
if (wd->mode != GIT_FILEMODE_TREE)
return true;
@@ -423,7 +423,7 @@ static int checkout_action_wd_only(
/* copy the entry for issuing notification callback later */
git_index_entry saved_wd = *wd;
- git_buf_sets(&data->tmp, wd->path);
+ git_str_sets(&data->tmp, wd->path);
saved_wd.path = data->tmp.ptr;
error = git_iterator_advance_over(
@@ -476,7 +476,7 @@ static bool submodule_is_config_only(
static bool checkout_is_empty_dir(checkout_data *data, const char *path)
{
- git_buf *fullpath;
+ git_str *fullpath;
if (checkout_target_fullpath(&fullpath, data, path) < 0)
return false;
@@ -1584,7 +1584,7 @@ static int blob_content_to_link(
git_blob *blob,
const char *path)
{
- git_buf linktarget = GIT_BUF_INIT;
+ git_str linktarget = GIT_STR_INIT;
int error;
if ((error = mkpath2file(data, path, data->opts.dir_mode)) < 0)
@@ -1594,10 +1594,10 @@ static int blob_content_to_link(
return error;
if (data->can_symlink) {
- if ((error = p_symlink(git_buf_cstr(&linktarget), path)) < 0)
+ if ((error = p_symlink(git_str_cstr(&linktarget), path)) < 0)
git_error_set(GIT_ERROR_OS, "could not create symlink %s", path);
} else {
- error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path);
+ error = git_futils_fake_symlink(git_str_cstr(&linktarget), path);
}
if (!error) {
@@ -1609,7 +1609,7 @@ static int blob_content_to_link(
st->st_mode = GIT_FILEMODE_LINK;
}
- git_buf_dispose(&linktarget);
+ git_str_dispose(&linktarget);
return error;
}
@@ -1636,7 +1636,7 @@ static int checkout_submodule_update_index(
checkout_data *data,
const git_diff_file *file)
{
- git_buf *fullpath;
+ git_str *fullpath;
struct stat st;
/* update the index unless prevented */
@@ -1772,7 +1772,7 @@ static int checkout_blob(
checkout_data *data,
const git_diff_file *file)
{
- git_buf *fullpath;
+ git_str *fullpath;
struct stat st;
int error = 0;
@@ -1809,7 +1809,7 @@ static int checkout_remove_the_old(
git_diff_delta *delta;
const char *str;
size_t i;
- git_buf *fullpath;
+ git_str *fullpath;
uint32_t flg = GIT_RMDIR_EMPTY_PARENTS |
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS;
@@ -1927,40 +1927,40 @@ static int checkout_lookup_head_tree(git_tree **out, git_repository *repo)
static int conflict_entry_name(
- git_buf *out,
+ git_str *out,
const char *side_name,
const char *filename)
{
- if (git_buf_puts(out, side_name) < 0 ||
- git_buf_putc(out, ':') < 0 ||
- git_buf_puts(out, filename) < 0)
+ if (git_str_puts(out, side_name) < 0 ||
+ git_str_putc(out, ':') < 0 ||
+ git_str_puts(out, filename) < 0)
return -1;
return 0;
}
-static int checkout_path_suffixed(git_buf *path, const char *suffix)
+static int checkout_path_suffixed(git_str *path, const char *suffix)
{
size_t path_len;
int i = 0, error = 0;
- if ((error = git_buf_putc(path, '~')) < 0 || (error = git_buf_puts(path, suffix)) < 0)
+ if ((error = git_str_putc(path, '~')) < 0 || (error = git_str_puts(path, suffix)) < 0)
return -1;
- path_len = git_buf_len(path);
+ path_len = git_str_len(path);
- while (git_path_exists(git_buf_cstr(path)) && i < INT_MAX) {
- git_buf_truncate(path, path_len);
+ while (git_path_exists(git_str_cstr(path)) && i < INT_MAX) {
+ git_str_truncate(path, path_len);
- if ((error = git_buf_putc(path, '_')) < 0 ||
- (error = git_buf_printf(path, "%d", i)) < 0)
+ if ((error = git_str_putc(path, '_')) < 0 ||
+ (error = git_str_printf(path, "%d", i)) < 0)
return error;
i++;
}
if (i == INT_MAX) {
- git_buf_truncate(path, path_len);
+ git_str_truncate(path, path_len);
git_error_set(GIT_ERROR_CHECKOUT, "could not write '%s': working directory file exists", path->ptr);
return GIT_EEXISTS;
@@ -1974,8 +1974,8 @@ static int checkout_write_entry(
checkout_conflictdata *conflict,
const git_index_entry *side)
{
- const char *hint_path, *suffix;
- git_buf *fullpath;
+ const char *hint_path = NULL, *suffix;
+ git_str *fullpath;
struct stat st;
int error;
@@ -2025,7 +2025,7 @@ static int checkout_write_entries(
}
static int checkout_merge_path(
- git_buf *out,
+ git_str *out,
checkout_data *data,
checkout_conflictdata *conflict,
git_merge_file_result *result)
@@ -2033,7 +2033,7 @@ static int checkout_merge_path(
const char *our_label_raw, *their_label_raw, *suffix;
int error = 0;
- if ((error = git_buf_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
+ if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
(error = git_path_validate_workdir_buf(data->repo, out)) < 0)
return error;
@@ -2056,9 +2056,9 @@ static int checkout_write_merge(
checkout_data *data,
checkout_conflictdata *conflict)
{
- git_buf our_label = GIT_BUF_INIT, their_label = GIT_BUF_INIT,
- path_suffixed = GIT_BUF_INIT, path_workdir = GIT_BUF_INIT,
- in_data = GIT_BUF_INIT, out_data = GIT_BUF_INIT;
+ git_str our_label = GIT_STR_INIT, their_label = GIT_STR_INIT,
+ path_suffixed = GIT_STR_INIT, path_workdir = GIT_STR_INIT,
+ in_data = GIT_STR_INIT, out_data = GIT_STR_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
git_filebuf output = GIT_FILEBUF_INIT;
@@ -2088,8 +2088,8 @@ static int checkout_write_merge(
&their_label, opts.their_label, conflict->theirs->path)) < 0)
goto done;
- opts.our_label = git_buf_cstr(&our_label);
- opts.their_label = git_buf_cstr(&their_label);
+ opts.our_label = git_str_cstr(&our_label);
+ opts.their_label = git_str_cstr(&their_label);
}
if ((error = git_merge_file_from_index(&result, data->repo,
@@ -2106,7 +2106,7 @@ static int checkout_write_merge(
goto done;
if ((data->strategy & GIT_CHECKOUT_UPDATE_ONLY) != 0 &&
- (error = checkout_safe_for_update_only(data, git_buf_cstr(&path_workdir), result.mode)) <= 0)
+ (error = checkout_safe_for_update_only(data, git_str_cstr(&path_workdir), result.mode)) <= 0)
goto done;
if (!data->opts.disable_filters) {
@@ -2127,7 +2127,7 @@ static int checkout_write_merge(
}
if ((error = mkpath2file(data, path_workdir.ptr, data->opts.dir_mode)) < 0 ||
- (error = git_filebuf_open(&output, git_buf_cstr(&path_workdir), GIT_FILEBUF_DO_NOT_BUFFER, result.mode)) < 0 ||
+ (error = git_filebuf_open(&output, git_str_cstr(&path_workdir), GIT_FILEBUF_DO_NOT_BUFFER, result.mode)) < 0 ||
(error = git_filebuf_write(&output, out_data.ptr, out_data.size)) < 0 ||
(error = git_filebuf_commit(&output)) < 0)
goto done;
@@ -2135,13 +2135,13 @@ static int checkout_write_merge(
done:
git_filter_list_free(fl);
- git_buf_dispose(&out_data);
- git_buf_dispose(&our_label);
- git_buf_dispose(&their_label);
+ git_str_dispose(&out_data);
+ git_str_dispose(&our_label);
+ git_str_dispose(&their_label);
git_merge_file_result_free(&result);
- git_buf_dispose(&path_workdir);
- git_buf_dispose(&path_suffixed);
+ git_str_dispose(&path_workdir);
+ git_str_dispose(&path_suffixed);
return error;
}
@@ -2321,8 +2321,8 @@ static void checkout_data_clear(checkout_data *data)
git__free(data->pfx);
data->pfx = NULL;
- git_buf_dispose(&data->target_path);
- git_buf_dispose(&data->tmp);
+ git_str_dispose(&data->target_path);
+ git_str_dispose(&data->tmp);
git_index_free(data->index);
data->index = NULL;
@@ -2506,12 +2506,12 @@ static int checkout_data_init(
(error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
(error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
(error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
- (error = git_buf_puts(&data->target_path, data->opts.target_directory)) < 0 ||
+ (error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 ||
(error = git_path_to_dir(&data->target_path)) < 0 ||
(error = git_strmap_new(&data->mkdir_map)) < 0)
goto cleanup;
- data->target_len = git_buf_len(&data->target_path);
+ data->target_len = git_str_len(&data->target_path);
git_attr_session__init(&data->attr_session, data->repo);
@@ -2623,7 +2623,7 @@ int git_checkout_iterator(
if (data.strategy & GIT_CHECKOUT_DRY_RUN)
goto cleanup;
-
+
data.total_steps = counts[CHECKOUT_ACTION__REMOVE] +
counts[CHECKOUT_ACTION__REMOVE_CONFLICT] +
counts[CHECKOUT_ACTION__UPDATE_BLOB] +
diff --git a/src/cherrypick.c b/src/cherrypick.c
index 4287956c9..9ec4962b9 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -26,10 +26,10 @@ static int write_cherrypick_head(
const char *commit_oidstr)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);
@@ -37,7 +37,7 @@ static int write_cherrypick_head(
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -47,10 +47,10 @@ static int write_merge_msg(
const char *commit_msg)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 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_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
(error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
goto cleanup;
@@ -61,7 +61,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -175,7 +175,7 @@ int git_cherrypick(
git_commit *our_commit = NULL;
char commit_oidstr[GIT_OID_HEXSZ + 1];
const char *commit_msg, *commit_summary;
- git_buf their_label = GIT_BUF_INIT;
+ git_str their_label = GIT_STR_INIT;
git_index *index = NULL;
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
int error = 0;
@@ -197,8 +197,8 @@ int git_cherrypick(
git_oid_nfmt(commit_oidstr, sizeof(commit_oidstr), git_commit_id(commit));
if ((error = write_merge_msg(repo, commit_msg)) < 0 ||
- (error = git_buf_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
- (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
+ (error = git_str_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
+ (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 ||
(error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 ||
(error = write_cherrypick_head(repo, commit_oidstr)) < 0 ||
(error = git_repository_head(&our_ref, repo)) < 0 ||
@@ -220,7 +220,7 @@ done:
git_index_free(index);
git_commit_free(our_commit);
git_reference_free(our_ref);
- git_buf_dispose(&their_label);
+ git_str_dispose(&their_label);
return error;
}
diff --git a/src/clone.c b/src/clone.c
index 752df3b92..cf4cc3c7f 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -34,7 +34,7 @@ static int create_branch(
{
git_commit *head_obj = NULL;
git_reference *branch_ref = NULL;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
int error;
/* Find the target commit */
@@ -42,11 +42,11 @@ static int create_branch(
return error;
/* Create the new branch */
- if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
+ if ((error = git_str_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
return error;
- error = git_reference_create(&branch_ref, repo, git_buf_cstr(&refname), target, 0, log_message);
- git_buf_dispose(&refname);
+ error = git_reference_create(&branch_ref, repo, git_str_cstr(&refname), target, 0, log_message);
+ git_str_dispose(&refname);
git_commit_free(head_obj);
if (!error)
@@ -64,29 +64,29 @@ static int setup_tracking_config(
const char *merge_target)
{
git_config *cfg;
- git_buf remote_key = GIT_BUF_INIT, merge_key = GIT_BUF_INIT;
+ git_str remote_key = GIT_STR_INIT, merge_key = GIT_STR_INIT;
int error = -1;
if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1;
- if (git_buf_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
+ if (git_str_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
goto cleanup;
- if (git_buf_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
+ if (git_str_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
goto cleanup;
- if (git_config_set_string(cfg, git_buf_cstr(&remote_key), remote_name) < 0)
+ if (git_config_set_string(cfg, git_str_cstr(&remote_key), remote_name) < 0)
goto cleanup;
- if (git_config_set_string(cfg, git_buf_cstr(&merge_key), merge_target) < 0)
+ if (git_config_set_string(cfg, git_str_cstr(&merge_key), merge_target) < 0)
goto cleanup;
error = 0;
cleanup:
- git_buf_dispose(&remote_key);
- git_buf_dispose(&merge_key);
+ git_str_dispose(&remote_key);
+ git_str_dispose(&merge_key);
return error;
}
@@ -139,7 +139,7 @@ static int update_head_to_new_branch(
static int update_head_to_default(git_repository *repo)
{
- git_buf initialbranch = GIT_BUF_INIT;
+ git_str initialbranch = GIT_STR_INIT;
const char *branch_name;
int error = 0;
@@ -158,24 +158,24 @@ static int update_head_to_default(git_repository *repo)
initialbranch.ptr);
done:
- git_buf_dispose(&initialbranch);
+ git_str_dispose(&initialbranch);
return error;
}
static int update_remote_head(
git_repository *repo,
git_remote *remote,
- git_buf *target,
+ git_str *target,
const char *reflog_message)
{
git_refspec *refspec;
git_reference *remote_head = NULL;
- git_buf remote_head_name = GIT_BUF_INIT;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_str remote_head_name = GIT_STR_INIT;
+ git_str remote_branch_name = GIT_STR_INIT;
int error;
/* Determine the remote tracking ref name from the local branch */
- refspec = git_remote__matching_refspec(remote, git_buf_cstr(target));
+ refspec = git_remote__matching_refspec(remote, git_str_cstr(target));
if (refspec == NULL) {
git_error_set(GIT_ERROR_NET, "the remote's default branch does not fit the refspec configuration");
@@ -183,13 +183,13 @@ static int update_remote_head(
goto cleanup;
}
- if ((error = git_refspec_transform(
+ if ((error = git_refspec__transform(
&remote_branch_name,
refspec,
- git_buf_cstr(target))) < 0)
+ git_str_cstr(target))) < 0)
goto cleanup;
- if ((error = git_buf_printf(&remote_head_name,
+ if ((error = git_str_printf(&remote_head_name,
"%s%s/%s",
GIT_REFS_REMOTES_DIR,
git_remote_name(remote),
@@ -199,15 +199,15 @@ static int update_remote_head(
error = git_reference_symbolic_create(
&remote_head,
repo,
- git_buf_cstr(&remote_head_name),
- git_buf_cstr(&remote_branch_name),
+ git_str_cstr(&remote_head_name),
+ git_str_cstr(&remote_branch_name),
true,
reflog_message);
cleanup:
git_reference_free(remote_head);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&remote_head_name);
+ git_str_dispose(&remote_branch_name);
+ git_str_dispose(&remote_head_name);
return error;
}
@@ -220,7 +220,7 @@ static int update_head_to_remote(
size_t refs_len;
const git_remote_head *remote_head, **refs;
const git_oid *remote_head_id;
- git_buf branch = GIT_BUF_INIT;
+ git_str branch = GIT_STR_INIT;
if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0)
return error;
@@ -235,7 +235,7 @@ static int update_head_to_remote(
remote_head_id = &remote_head->oid;
- error = git_remote_default_branch(&branch, remote);
+ error = git_remote__default_branch(&branch, remote);
if (error == GIT_ENOTFOUND) {
error = git_repository_set_head_detached(
repo, remote_head_id);
@@ -248,11 +248,11 @@ static int update_head_to_remote(
error = update_head_to_new_branch(
repo,
remote_head_id,
- git_buf_cstr(&branch),
+ git_str_cstr(&branch),
reflog_message);
cleanup:
- git_buf_dispose(&branch);
+ git_str_dispose(&branch);
return error;
}
@@ -264,36 +264,36 @@ static int update_head_to_branch(
const char *reflog_message)
{
int retcode;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_str remote_branch_name = GIT_STR_INIT;
git_reference *remote_ref = NULL;
- git_buf default_branch = GIT_BUF_INIT;
+ git_str default_branch = GIT_STR_INIT;
GIT_ASSERT_ARG(remote);
GIT_ASSERT_ARG(branch);
- if ((retcode = git_buf_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
+ if ((retcode = git_str_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
git_remote_name(remote), branch)) < 0 )
goto cleanup;
- if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0)
+ if ((retcode = git_reference_lookup(&remote_ref, repo, git_str_cstr(&remote_branch_name))) < 0)
goto cleanup;
if ((retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
reflog_message)) < 0)
goto cleanup;
- if ((retcode = git_remote_default_branch(&default_branch, remote)) < 0)
+ if ((retcode = git_remote__default_branch(&default_branch, remote)) < 0)
goto cleanup;
- if (!git_remote__matching_refspec(remote, git_buf_cstr(&default_branch)))
+ if (!git_remote__matching_refspec(remote, git_str_cstr(&default_branch)))
goto cleanup;
retcode = update_remote_head(repo, remote, &default_branch, reflog_message);
cleanup:
git_reference_free(remote_ref);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&default_branch);
+ git_str_dispose(&remote_branch_name);
+ git_str_dispose(&default_branch);
return retcode;
}
@@ -392,7 +392,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch)
{
int error;
- git_buf reflog_message = GIT_BUF_INIT;
+ git_str reflog_message = GIT_STR_INIT;
git_fetch_options fetch_opts;
git_remote *remote;
@@ -410,23 +410,23 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
memcpy(&fetch_opts, opts, sizeof(git_fetch_options));
fetch_opts.update_fetchhead = 0;
fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
- git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
+ git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
cleanup:
git_remote_free(remote);
- git_buf_dispose(&reflog_message);
+ git_str_dispose(&reflog_message);
return error;
}
int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local)
{
- git_buf fromurl = GIT_BUF_INIT;
+ git_str fromurl = GIT_STR_INIT;
const char *path = url_or_path;
bool is_url, is_local;
@@ -446,7 +446,7 @@ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t loc
git_path_isdir(path);
done:
- git_buf_dispose(&fromurl);
+ git_str_dispose(&fromurl);
return is_local;
}
@@ -586,8 +586,8 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
{
int error, flags;
git_repository *src;
- git_buf src_odb = GIT_BUF_INIT, dst_odb = GIT_BUF_INIT, src_path = GIT_BUF_INIT;
- git_buf reflog_message = GIT_BUF_INIT;
+ git_str src_odb = GIT_STR_INIT, dst_odb = GIT_STR_INIT, src_path = GIT_STR_INIT;
+ git_str reflog_message = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(remote);
@@ -606,13 +606,13 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
return error;
/* Copy .git/objects/ from the source to the target */
- if ((error = git_repository_open(&src, git_buf_cstr(&src_path))) < 0) {
- git_buf_dispose(&src_path);
+ if ((error = git_repository_open(&src, git_str_cstr(&src_path))) < 0) {
+ git_str_dispose(&src_path);
return error;
}
- if (git_repository_item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0
- || git_repository_item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) {
+ if (git_repository__item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0 ||
+ git_repository__item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) {
error = -1;
goto cleanup;
}
@@ -621,7 +621,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
if (can_link(git_repository_path(src), git_repository_path(repo), link))
flags |= GIT_CPDIR_LINK_FILES;
- error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
+ error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
/*
@@ -631,25 +631,25 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
*/
if (error < 0 && link) {
flags &= ~GIT_CPDIR_LINK_FILES;
- error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
+ error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
}
if (error < 0)
goto cleanup;
- git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
+ git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_str_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
cleanup:
- git_buf_dispose(&reflog_message);
- git_buf_dispose(&src_path);
- git_buf_dispose(&src_odb);
- git_buf_dispose(&dst_odb);
+ git_str_dispose(&reflog_message);
+ git_str_dispose(&src_path);
+ git_str_dispose(&src_odb);
+ git_str_dispose(&dst_odb);
git_repository_free(src);
return error;
}
diff --git a/src/commit.c b/src/commit.c
index 96259d5bb..752d98b02 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -14,10 +14,10 @@
#include "git2/mailmap.h"
#include "git2/sys/commit.h"
+#include "buf.h"
#include "odb.h"
#include "commit.h"
#include "signature.h"
-#include "message.h"
#include "refs.h"
#include "object.h"
#include "array.h"
@@ -42,7 +42,7 @@ void git_commit__free(void *_commit)
}
static int git_commit__create_buffer_internal(
- git_buf *out,
+ git_str *out,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
@@ -67,17 +67,17 @@ static int git_commit__create_buffer_internal(
git_signature__writebuf(out, "committer ", committer);
if (message_encoding != NULL)
- git_buf_printf(out, "encoding %s\n", message_encoding);
+ git_str_printf(out, "encoding %s\n", message_encoding);
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
- if (git_buf_puts(out, message) < 0)
+ if (git_str_puts(out, message) < 0)
goto on_error;
return 0;
on_error:
- git_buf_dispose(out);
+ git_str_dispose(out);
return -1;
}
@@ -136,7 +136,7 @@ static int git_commit__create_internal(
int error;
git_odb *odb;
git_reference *ref = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
const git_oid *current_id = NULL;
git_array_oid_t parents = GIT_ARRAY_INIT;
@@ -179,7 +179,7 @@ static int git_commit__create_internal(
cleanup:
git_array_clear(parents);
git_reference_free(ref);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -545,7 +545,7 @@ const char *git_commit_message(const git_commit *commit)
const char *git_commit_summary(git_commit *commit)
{
- git_buf summary = GIT_BUF_INIT;
+ git_str summary = GIT_STR_INIT;
const char *msg, *space;
bool space_contains_newline = false;
@@ -570,17 +570,17 @@ const char *git_commit_summary(git_commit *commit)
/* process any recorded whitespace */
if (space) {
if(space_contains_newline)
- git_buf_putc(&summary, ' '); /* if the space contains a newline, collapse to ' ' */
+ git_str_putc(&summary, ' '); /* if the space contains a newline, collapse to ' ' */
else
- git_buf_put(&summary, space, (msg - space)); /* otherwise copy it */
+ git_str_put(&summary, space, (msg - space)); /* otherwise copy it */
space = NULL;
}
/* copy the next character */
- git_buf_putc(&summary, next_character);
+ git_str_putc(&summary, next_character);
}
}
- commit->summary = git_buf_detach(&summary);
+ commit->summary = git_str_detach(&summary);
if (!commit->summary)
commit->summary = git__strdup("");
}
@@ -678,11 +678,22 @@ int git_commit_nth_gen_ancestor(
return 0;
}
-int git_commit_header_field(git_buf *out, const git_commit *commit, const char *field)
+int git_commit_header_field(
+ git_buf *out,
+ const git_commit *commit,
+ const char *field)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_commit__header_field, commit, field);
+}
+
+int git_commit__header_field(
+ git_str *out,
+ const git_commit *commit,
+ const char *field)
{
const char *eol, *buf = commit->raw_header;
- git_buf_clear(out);
+ git_str_clear(out);
while ((eol = strchr(buf, '\n'))) {
/* We can skip continuations here */
@@ -706,22 +717,22 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
buf++; /* skip the SP */
- git_buf_put(out, buf, eol - buf);
- if (git_buf_oom(out))
+ git_str_put(out, buf, eol - buf);
+ if (git_str_oom(out))
goto oom;
/* If the next line starts with SP, it's multi-line, we must continue */
while (eol[1] == ' ') {
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
buf = eol + 2;
eol = strchr(buf, '\n');
if (!eol)
goto malformed;
- git_buf_put(out, buf, eol - buf);
+ git_str_put(out, buf, eol - buf);
}
- if (git_buf_oom(out))
+ if (git_str_oom(out))
goto oom;
return 0;
@@ -738,7 +749,35 @@ oom:
return -1;
}
-int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_repository *repo, git_oid *commit_id, const char *field)
+int git_commit_extract_signature(
+ git_buf *signature_out,
+ git_buf *signed_data_out,
+ git_repository *repo,
+ git_oid *commit_id,
+ const char *field)
+{
+ git_str signature = GIT_STR_INIT, signed_data = GIT_STR_INIT;
+ int error;
+
+ if ((error = git_buf_tostr(&signature, signature_out)) < 0 ||
+ (error = git_buf_tostr(&signed_data, signed_data_out)) < 0 ||
+ (error = git_commit__extract_signature(&signature, &signed_data, repo, commit_id, field)) < 0 ||
+ (error = git_buf_fromstr(signature_out, &signature)) < 0 ||
+ (error = git_buf_fromstr(signed_data_out, &signed_data)) < 0)
+ goto done;
+
+done:
+ git_str_dispose(&signature);
+ git_str_dispose(&signed_data);
+ return error;
+}
+
+int git_commit__extract_signature(
+ git_str *signature,
+ git_str *signed_data,
+ git_repository *repo,
+ git_oid *commit_id,
+ const char *field)
{
git_odb_object *obj;
git_odb *odb;
@@ -746,8 +785,8 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
const char *h, *eol;
int error;
- git_buf_clear(signature);
- git_buf_clear(signed_data);
+ git_str_clear(signature);
+ git_str_clear(signed_data);
if (!field)
field = "gpgsig";
@@ -769,7 +808,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
while ((h = strchr(buf, '\n')) && h[1] != '\0') {
h++;
if (git__prefixcmp(buf, field)) {
- if (git_buf_put(signed_data, buf, h - buf) < 0)
+ if (git_str_put(signed_data, buf, h - buf) < 0)
return -1;
buf = h;
@@ -788,25 +827,25 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
h++; /* skip the SP */
- git_buf_put(signature, h, eol - h);
- if (git_buf_oom(signature))
+ git_str_put(signature, h, eol - h);
+ if (git_str_oom(signature))
goto oom;
/* If the next line starts with SP, it's multi-line, we must continue */
while (eol[1] == ' ') {
- git_buf_putc(signature, '\n');
+ git_str_putc(signature, '\n');
h = eol + 2;
eol = strchr(h, '\n');
if (!eol)
goto malformed;
- git_buf_put(signature, h, eol - h);
+ git_str_put(signature, h, eol - h);
}
- if (git_buf_oom(signature))
+ if (git_str_oom(signature))
goto oom;
- error = git_buf_puts(signed_data, eol+1);
+ error = git_str_puts(signed_data, eol+1);
git_odb_object_free(obj);
return error;
}
@@ -826,12 +865,29 @@ oom:
cleanup:
git_odb_object_free(obj);
- git_buf_clear(signature);
- git_buf_clear(signed_data);
+ git_str_clear(signature);
+ git_str_clear(signed_data);
return error;
}
-int git_commit_create_buffer(git_buf *out,
+int git_commit_create_buffer(
+ git_buf *out,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message,
+ const git_tree *tree,
+ size_t parent_count,
+ const git_commit *parents[])
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_commit__create_buffer, repo,
+ author, committer, message_encoding, message,
+ tree, parent_count, parents);
+}
+
+int git_commit__create_buffer(
+ git_str *out,
git_repository *repo,
const git_signature *author,
const git_signature *committer,
@@ -866,7 +922,7 @@ int git_commit_create_buffer(git_buf *out,
/**
* Append to 'out' properly marking continuations when there's a newline in 'content'
*/
-static int format_header_field(git_buf *out, const char *field, const char *content)
+static int format_header_field(git_str *out, const char *field, const char *content)
{
const char *lf;
@@ -874,19 +930,19 @@ static int format_header_field(git_buf *out, const char *field, const char *cont
GIT_ASSERT_ARG(field);
GIT_ASSERT_ARG(content);
- git_buf_puts(out, field);
- git_buf_putc(out, ' ');
+ git_str_puts(out, field);
+ git_str_putc(out, ' ');
while ((lf = strchr(content, '\n')) != NULL) {
- git_buf_put(out, content, lf - content);
- git_buf_puts(out, "\n ");
+ git_str_put(out, content, lf - content);
+ git_str_puts(out, "\n ");
content = lf + 1;
}
- git_buf_puts(out, content);
- git_buf_putc(out, '\n');
+ git_str_puts(out, content);
+ git_str_putc(out, '\n');
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static const git_oid *commit_parent_from_commit(size_t n, void *payload)
@@ -908,7 +964,7 @@ int git_commit_create_with_signature(
int error = 0;
const char *field;
const char *header_end;
- git_buf commit = GIT_BUF_INIT;
+ git_str commit = GIT_STR_INIT;
git_commit *parsed;
git_array_oid_t parents = GIT_ARRAY_INIT;
@@ -933,7 +989,7 @@ int git_commit_create_with_signature(
/* The header ends after the first LF */
header_end++;
- git_buf_put(&commit, commit_content, header_end - commit_content);
+ git_str_put(&commit, commit_content, header_end - commit_content);
if (signature != NULL) {
field = signature_field ? signature_field : "gpgsig";
@@ -942,9 +998,9 @@ int git_commit_create_with_signature(
goto cleanup;
}
- git_buf_puts(&commit, header_end);
+ git_str_puts(&commit, header_end);
- if (git_buf_oom(&commit))
+ if (git_str_oom(&commit))
return -1;
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
@@ -955,7 +1011,7 @@ int git_commit_create_with_signature(
cleanup:
git_commit__free(parsed);
- git_buf_dispose(&commit);
+ git_str_dispose(&commit);
return error;
}
diff --git a/src/commit.h b/src/commit.h
index 318ce5cba..9378eab2d 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -33,6 +33,29 @@ struct git_commit {
char *body;
};
+int git_commit__header_field(
+ git_str *out,
+ const git_commit *commit,
+ const char *field);
+
+int git_commit__extract_signature(
+ git_str *signature,
+ git_str *signed_data,
+ git_repository *repo,
+ git_oid *commit_id,
+ const char *field);
+
+int git_commit__create_buffer(
+ git_str *out,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message,
+ const git_tree *tree,
+ size_t parent_count,
+ const git_commit *parents[]);
+
void git_commit__free(void *commit);
int git_commit__parse(void *commit, git_odb_object *obj);
int git_commit__parse_raw(void *commit, const char *data, size_t size);
diff --git a/src/commit_graph.c b/src/commit_graph.c
index df760b5f8..f9a4bd2b2 100644
--- a/src/commit_graph.c
+++ b/src/commit_graph.c
@@ -8,6 +8,7 @@
#include "commit_graph.h"
#include "array.h"
+#include "buf.h"
#include "filebuf.h"
#include "futils.h"
#include "hash.h"
@@ -308,12 +309,12 @@ int git_commit_graph_new(git_commit_graph **cgraph_out, const char *objects_dir,
cgraph = git__calloc(1, sizeof(git_commit_graph));
GIT_ERROR_CHECK_ALLOC(cgraph);
- error = git_buf_joinpath(&cgraph->filename, objects_dir, "info/commit-graph");
+ error = git_str_joinpath(&cgraph->filename, objects_dir, "info/commit-graph");
if (error < 0)
goto error;
if (open_file) {
- error = git_commit_graph_file_open(&cgraph->file, git_buf_cstr(&cgraph->filename));
+ error = git_commit_graph_file_open(&cgraph->file, git_str_cstr(&cgraph->filename));
if (error < 0)
goto error;
cgraph->checked = 1;
@@ -387,7 +388,7 @@ int git_commit_graph_get_file(git_commit_graph_file **file_out, git_commit_graph
cgraph->checked = 1;
/* Best effort */
- error = git_commit_graph_file_open(&result, git_buf_cstr(&cgraph->filename));
+ error = git_commit_graph_file_open(&result, git_str_cstr(&cgraph->filename));
if (error < 0)
return error;
@@ -407,7 +408,7 @@ void git_commit_graph_refresh(git_commit_graph *cgraph)
return;
if (cgraph->file
- && git_commit_graph_file_needs_refresh(cgraph->file, git_buf_cstr(&cgraph->filename))) {
+ && git_commit_graph_file_needs_refresh(cgraph->file, git_str_cstr(&cgraph->filename))) {
/* We just free the commit graph. The next time it is requested, it will be
* re-loaded. */
git_commit_graph_file_free(cgraph->file);
@@ -597,7 +598,7 @@ void git_commit_graph_free(git_commit_graph *cgraph)
if (!cgraph)
return;
- git_buf_dispose(&cgraph->filename);
+ git_str_dispose(&cgraph->filename);
git_commit_graph_file_free(cgraph->file);
git__free(cgraph);
}
@@ -623,13 +624,13 @@ int git_commit_graph_writer_new(git_commit_graph_writer **out, const char *objec
git_commit_graph_writer *w = git__calloc(1, sizeof(git_commit_graph_writer));
GIT_ERROR_CHECK_ALLOC(w);
- if (git_buf_sets(&w->objects_info_dir, objects_info_dir) < 0) {
+ if (git_str_sets(&w->objects_info_dir, objects_info_dir) < 0) {
git__free(w);
return -1;
}
if (git_vector_init(&w->commits, 0, packed_commit__cmp) < 0) {
- git_buf_dispose(&w->objects_info_dir);
+ git_str_dispose(&w->objects_info_dir);
git__free(w);
return -1;
}
@@ -649,7 +650,7 @@ void git_commit_graph_writer_free(git_commit_graph_writer *w)
git_vector_foreach (&w->commits, i, packed_commit)
packed_commit_free(packed_commit);
git_vector_free(&w->commits);
- git_buf_dispose(&w->objects_info_dir);
+ git_str_dispose(&w->objects_info_dir);
git__free(w);
}
@@ -931,8 +932,8 @@ static int write_chunk_header(
static int commit_graph_write_buf(const char *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
struct commit_graph_write_hash_context {
@@ -971,8 +972,8 @@ static int commit_graph_write(
uint32_t extra_edge_list_count;
uint32_t oid_fanout[256];
off64_t offset;
- git_buf oid_lookup = GIT_BUF_INIT, commit_data = GIT_BUF_INIT,
- extra_edge_list = GIT_BUF_INIT;
+ git_str oid_lookup = GIT_STR_INIT, commit_data = GIT_STR_INIT,
+ extra_edge_list = GIT_STR_INIT;
git_oid cgraph_checksum = {{0}};
git_hash_ctx ctx;
struct commit_graph_write_hash_context hash_cb_data = {0};
@@ -1011,7 +1012,7 @@ static int commit_graph_write(
/* Fill the OID Lookup table. */
git_vector_foreach (&w->commits, i, packed_commit) {
- error = git_buf_put(&oid_lookup,
+ error = git_str_put(&oid_lookup,
(const char *)&packed_commit->sha1, sizeof(git_oid));
if (error < 0)
goto cleanup;
@@ -1026,7 +1027,7 @@ static int commit_graph_write(
size_t *packed_index;
unsigned int parentcount = (unsigned int)git_array_size(packed_commit->parents);
- error = git_buf_put(&commit_data,
+ error = git_str_put(&commit_data,
(const char *)&packed_commit->tree_oid,
sizeof(git_oid));
if (error < 0)
@@ -1038,7 +1039,7 @@ static int commit_graph_write(
packed_index = git_array_get(packed_commit->parent_indices, 0);
word = htonl((uint32_t)*packed_index);
}
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
@@ -1050,7 +1051,7 @@ static int commit_graph_write(
} else {
word = htonl(0x80000000u | extra_edge_list_count);
}
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
@@ -1061,7 +1062,7 @@ static int commit_graph_write(
packed_commit->parent_indices, parent_i);
word = htonl((uint32_t)(*packed_index | (parent_i + 1 == parentcount ? 0x80000000u : 0)));
- error = git_buf_put(&extra_edge_list,
+ error = git_str_put(&extra_edge_list,
(const char *)&word,
sizeof(word));
if (error < 0)
@@ -1075,18 +1076,18 @@ static int commit_graph_write(
if (generation > GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX)
generation = GIT_COMMIT_GRAPH_GENERATION_NUMBER_MAX;
word = ntohl((uint32_t)((generation << 2) | ((commit_time >> 32ull) & 0x3ull)));
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
word = ntohl((uint32_t)(commit_time & 0xffffffffull));
- error = git_buf_put(&commit_data, (const char *)&word, sizeof(word));
+ error = git_str_put(&commit_data, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
}
/* Write the header. */
hdr.chunks = 3;
- if (git_buf_len(&extra_edge_list) > 0)
+ if (git_str_len(&extra_edge_list) > 0)
hdr.chunks++;
error = write_cb((const char *)&hdr, sizeof(hdr), cb_data);
if (error < 0)
@@ -1101,17 +1102,17 @@ static int commit_graph_write(
error = write_chunk_header(COMMIT_GRAPH_OID_LOOKUP_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&oid_lookup);
+ offset += git_str_len(&oid_lookup);
error = write_chunk_header(COMMIT_GRAPH_COMMIT_DATA_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&commit_data);
- if (git_buf_len(&extra_edge_list) > 0) {
+ offset += git_str_len(&commit_data);
+ if (git_str_len(&extra_edge_list) > 0) {
error = write_chunk_header(
COMMIT_GRAPH_EXTRA_EDGE_LIST_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&extra_edge_list);
+ offset += git_str_len(&extra_edge_list);
}
error = write_chunk_header(0, offset, write_cb, cb_data);
if (error < 0)
@@ -1121,13 +1122,13 @@ static int commit_graph_write(
error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&oid_lookup), git_buf_len(&oid_lookup), cb_data);
+ error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&commit_data), git_buf_len(&commit_data), cb_data);
+ error = write_cb(git_str_cstr(&commit_data), git_str_len(&commit_data), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&extra_edge_list), git_buf_len(&extra_edge_list), cb_data);
+ error = write_cb(git_str_cstr(&extra_edge_list), git_str_len(&extra_edge_list), cb_data);
if (error < 0)
goto cleanup;
@@ -1140,9 +1141,9 @@ static int commit_graph_write(
goto cleanup;
cleanup:
- git_buf_dispose(&oid_lookup);
- git_buf_dispose(&commit_data);
- git_buf_dispose(&extra_edge_list);
+ git_str_dispose(&oid_lookup);
+ git_str_dispose(&commit_data);
+ git_str_dispose(&extra_edge_list);
git_hash_ctx_cleanup(&ctx);
return error;
}
@@ -1171,21 +1172,21 @@ int git_commit_graph_writer_commit(
{
int error;
int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER;
- git_buf commit_graph_path = GIT_BUF_INIT;
+ git_str commit_graph_path = GIT_STR_INIT;
git_filebuf output = GIT_FILEBUF_INIT;
/* TODO: support options and fill in defaults. */
GIT_UNUSED(opts);
- error = git_buf_joinpath(
- &commit_graph_path, git_buf_cstr(&w->objects_info_dir), "commit-graph");
+ error = git_str_joinpath(
+ &commit_graph_path, git_str_cstr(&w->objects_info_dir), "commit-graph");
if (error < 0)
return error;
if (git_repository__fsync_gitdir)
filebuf_flags |= GIT_FILEBUF_FSYNC;
- error = git_filebuf_open(&output, git_buf_cstr(&commit_graph_path), filebuf_flags, 0644);
- git_buf_dispose(&commit_graph_path);
+ error = git_filebuf_open(&output, git_str_cstr(&commit_graph_path), filebuf_flags, 0644);
+ git_str_dispose(&commit_graph_path);
if (error < 0)
return error;
@@ -1199,9 +1200,17 @@ int git_commit_graph_writer_commit(
}
int git_commit_graph_writer_dump(
- git_buf *cgraph,
- git_commit_graph_writer *w,
- git_commit_graph_writer_options *opts)
+ git_buf *cgraph,
+ git_commit_graph_writer *w,
+ git_commit_graph_writer_options *opts)
+{
+ GIT_BUF_WRAP_PRIVATE(cgraph, git_commit_graph__writer_dump, w, opts);
+}
+
+int git_commit_graph__writer_dump(
+ git_str *cgraph,
+ git_commit_graph_writer *w,
+ git_commit_graph_writer_options *opts)
{
/* TODO: support options. */
GIT_UNUSED(opts);
diff --git a/src/commit_graph.h b/src/commit_graph.h
index 9d0a827de..4d2be431c 100644
--- a/src/commit_graph.h
+++ b/src/commit_graph.h
@@ -92,7 +92,7 @@ typedef struct git_commit_graph_entry {
/* A wrapper for git_commit_graph_file to enable lazy loading in the ODB. */
struct git_commit_graph {
/* The path to the commit-graph file. Something like ".git/objects/info/commit-graph". */
- git_buf filename;
+ git_str filename;
/* The underlying commit-graph file. */
git_commit_graph_file *file;
@@ -127,12 +127,17 @@ struct git_commit_graph_writer {
* The path of the `objects/info` directory where the `commit-graph` will be
* stored.
*/
- git_buf objects_info_dir;
+ git_str objects_info_dir;
/* The list of packed commits. */
git_vector commits;
};
+int git_commit_graph__writer_dump(
+ git_str *cgraph,
+ git_commit_graph_writer *w,
+ git_commit_graph_writer_options *opts);
+
/*
* Returns whether the git_commit_graph_file needs to be reloaded since the
* contents of the commit-graph file have changed on disk.
diff --git a/src/common.h b/src/common.h
index 9bb1116b5..640f94806 100644
--- a/src/common.h
+++ b/src/common.h
@@ -124,9 +124,9 @@
#define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
/**
- * Check a buffer allocation result, returning -1 if it failed.
+ * Check a string buffer allocation result, returning -1 if it failed.
*/
-#define GIT_ERROR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; }
+#define GIT_ERROR_CHECK_ALLOC_STR(buf) if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; }
/**
* Check a return value and propagate result if non-zero.
@@ -202,6 +202,9 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v
/* NOTE: other git_error functions are in the public errors.h header file */
+/* Forward declare git_str */
+typedef struct git_str git_str;
+
#include "util.h"
#endif
diff --git a/src/config.c b/src/config.c
index 3251cd51f..9033a92c5 100644
--- a/src/config.c
+++ b/src/config.c
@@ -10,6 +10,7 @@
#include "git2/config.h"
#include "git2/sys/config.h"
+#include "buf.h"
#include "config_backend.h"
#include "regexp.h"
#include "sysdir.h"
@@ -848,7 +849,40 @@ static int is_readonly(const git_config *cfg)
return 1;
}
-int git_config_get_path(git_buf *out, const git_config *cfg, const char *name)
+static int git_config__parse_path(git_str *out, const char *value)
+{
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(value);
+
+ if (value[0] == '~') {
+ if (value[1] != '\0' && value[1] != '/') {
+ git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported");
+ return -1;
+ }
+
+ return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
+ }
+
+ return git_str_sets(out, value);
+}
+
+int git_config_parse_path(git_buf *out, const char *value)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_config__parse_path, value);
+}
+
+int git_config_get_path(
+ git_buf *out,
+ const git_config *cfg,
+ const char *name)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_config__get_path, cfg, name);
+}
+
+int git_config__get_path(
+ git_str *out,
+ const git_config *cfg,
+ const char *name)
{
git_config_entry *entry;
int error;
@@ -856,7 +890,7 @@ int git_config_get_path(git_buf *out, const git_config *cfg, const char *name)
if ((error = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
return error;
- error = git_config_parse_path(out, entry->value);
+ error = git_config__parse_path(out, entry->value);
git_config_entry_free(entry);
return error;
@@ -884,18 +918,24 @@ int git_config_get_string(
int git_config_get_string_buf(
git_buf *out, const git_config *cfg, const char *name)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_config__get_string_buf, cfg, name);
+}
+
+int git_config__get_string_buf(
+ git_str *out, const git_config *cfg, const char *name)
+{
git_config_entry *entry;
int ret;
const char *str;
- if ((ret = git_buf_sanitize(out)) < 0)
- return ret;
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(cfg);
ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
str = !ret ? (entry->value ? entry->value : "") : NULL;
if (str)
- ret = git_buf_puts(out, str);
+ ret = git_str_puts(out, str);
git_config_entry_free(entry);
@@ -1087,101 +1127,112 @@ void git_config_iterator_free(git_config_iterator *iter)
int git_config_find_global(git_buf *path)
{
- int error;
-
- if ((error = git_buf_sanitize(path)) < 0)
- return error;
+ GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_GLOBAL);
+}
+int git_config__find_global(git_str *path)
+{
return git_sysdir_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL);
}
int git_config_find_xdg(git_buf *path)
{
- int error;
-
- if ((error = git_buf_sanitize(path)) < 0)
- return error;
+ GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_XDG);
+}
+int git_config__find_xdg(git_str *path)
+{
return git_sysdir_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG);
}
int git_config_find_system(git_buf *path)
{
- int error;
-
- if ((error = git_buf_sanitize(path)) < 0)
- return error;
+ GIT_BUF_WRAP_PRIVATE(path, git_sysdir_find_global_file, GIT_CONFIG_FILENAME_SYSTEM);
+}
+int git_config__find_system(git_str *path)
+{
return git_sysdir_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM);
}
int git_config_find_programdata(git_buf *path)
{
+ git_str str = GIT_STR_INIT;
+ int error;
+
+ if ((error = git_buf_tostr(&str, path)) == 0 &&
+ (error = git_config__find_programdata(&str)) == 0)
+ error = git_buf_fromstr(path, &str);
+
+ git_str_dispose(&str);
+ return error;
+}
+
+int git_config__find_programdata(git_str *path)
+{
int ret;
- if ((ret = git_buf_sanitize(path)) < 0)
- return ret;
+ ret = git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA);
- ret = git_sysdir_find_programdata_file(path,
- GIT_CONFIG_FILENAME_PROGRAMDATA);
if (ret != GIT_OK)
return ret;
return git_path_validate_system_file_ownership(path->ptr);
}
-int git_config__global_location(git_buf *buf)
+int git_config__global_location(git_str *buf)
{
- const git_buf *paths;
+ const git_str *paths;
const char *sep, *start;
if (git_sysdir_get(&paths, GIT_SYSDIR_GLOBAL) < 0)
return -1;
/* no paths, so give up */
- if (!paths || !git_buf_len(paths))
+ if (!paths || !git_str_len(paths))
return -1;
/* find unescaped separator or end of string */
- for (sep = start = git_buf_cstr(paths); *sep; ++sep) {
+ for (sep = start = git_str_cstr(paths); *sep; ++sep) {
if (*sep == GIT_PATH_LIST_SEPARATOR &&
(sep <= start || sep[-1] != '\\'))
break;
}
- if (git_buf_set(buf, start, (size_t)(sep - start)) < 0)
+ if (git_str_set(buf, start, (size_t)(sep - start)) < 0)
return -1;
- return git_buf_joinpath(buf, buf->ptr, GIT_CONFIG_FILENAME_GLOBAL);
+ return git_str_joinpath(buf, buf->ptr, GIT_CONFIG_FILENAME_GLOBAL);
}
int git_config_open_default(git_config **out)
{
int error;
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
if ((error = git_config_new(&cfg)) < 0)
return error;
- if (!git_config_find_global(&buf) || !git_config__global_location(&buf)) {
+ if (!git_config__find_global(&buf) ||
+ !git_config__global_location(&buf)) {
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0);
}
- if (!error && !git_config_find_xdg(&buf))
+ if (!error && !git_config__find_xdg(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_XDG, NULL, 0);
- if (!error && !git_config_find_system(&buf))
+ if (!error && !git_config__find_system(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0);
- if (!error && !git_config_find_programdata(&buf))
+ if (!error && !git_config__find_programdata(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_PROGRAMDATA, NULL, 0);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error) {
git_config_free(cfg);
@@ -1375,28 +1426,6 @@ fail_parse:
return -1;
}
-int git_config_parse_path(git_buf *out, const char *value)
-{
- int error;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(value);
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- if (value[0] == '~') {
- if (value[1] != '\0' && value[1] != '/') {
- git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported");
- return -1;
- }
-
- return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
- }
-
- return git_buf_sets(out, value);
-}
-
static int normalize_section(char *start, char *end)
{
char *scan;
@@ -1459,7 +1488,7 @@ invalid:
struct rename_data {
git_config *config;
- git_buf *name;
+ git_str *name;
size_t old_len;
};
@@ -1469,15 +1498,15 @@ static int rename_config_entries_cb(
{
int error = 0;
struct rename_data *data = (struct rename_data *)payload;
- size_t base_len = git_buf_len(data->name);
+ size_t base_len = git_str_len(data->name);
if (base_len > 0 &&
- !(error = git_buf_puts(data->name, entry->name + data->old_len)))
+ !(error = git_str_puts(data->name, entry->name + data->old_len)))
{
error = git_config_set_string(
- data->config, git_buf_cstr(data->name), entry->value);
+ data->config, git_str_cstr(data->name), entry->value);
- git_buf_truncate(data->name, base_len);
+ git_str_truncate(data->name, base_len);
}
if (!error)
@@ -1492,13 +1521,13 @@ int git_config_rename_section(
const char *new_section_name)
{
git_config *config;
- git_buf pattern = GIT_BUF_INIT, replace = GIT_BUF_INIT;
+ git_str pattern = GIT_STR_INIT, replace = GIT_STR_INIT;
int error = 0;
struct rename_data data;
- git_buf_puts_escape_regex(&pattern, old_section_name);
+ git_str_puts_escape_regex(&pattern, old_section_name);
- if ((error = git_buf_puts(&pattern, "\\..+")) < 0)
+ if ((error = git_str_puts(&pattern, "\\..+")) < 0)
goto cleanup;
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
@@ -1508,7 +1537,7 @@ int git_config_rename_section(
data.name = &replace;
data.old_len = strlen(old_section_name) + 1;
- if ((error = git_buf_join(&replace, '.', new_section_name, "")) < 0)
+ if ((error = git_str_join(&replace, '.', new_section_name, "")) < 0)
goto cleanup;
if (new_section_name != NULL &&
@@ -1520,11 +1549,11 @@ int git_config_rename_section(
}
error = git_config_foreach_match(
- config, git_buf_cstr(&pattern), rename_config_entries_cb, &data);
+ config, git_str_cstr(&pattern), rename_config_entries_cb, &data);
cleanup:
- git_buf_dispose(&pattern);
- git_buf_dispose(&replace);
+ git_str_dispose(&pattern);
+ git_str_dispose(&replace);
return error;
}
diff --git a/src/config.h b/src/config.h
index a1d8f7d23..5dfc9da71 100644
--- a/src/config.h
+++ b/src/config.h
@@ -27,7 +27,12 @@ struct git_config {
git_vector backends;
};
-extern int git_config__global_location(git_buf *buf);
+extern int git_config__global_location(git_str *buf);
+
+extern int git_config__find_global(git_str *path);
+extern int git_config__find_xdg(git_str *path);
+extern int git_config__find_system(git_str *path);
+extern int git_config__find_programdata(git_str *path);
extern int git_config_rename_section(
git_repository *repo,
@@ -51,6 +56,14 @@ extern int git_config__update_entry(
bool overwrite_existing,
bool only_if_existing);
+int git_config__get_path(
+ git_str *out,
+ const git_config *cfg,
+ const char *name);
+
+int git_config__get_string_buf(
+ git_str *out, const git_config *cfg, const char *name);
+
/*
* Lookup functions that cannot fail. These functions look up a config
* value and return a fallback value if the value is missing or if any
diff --git a/src/config_file.c b/src/config_file.c
index 2f83a4070..9c3d2ceb8 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -11,7 +11,7 @@
#include "git2/sys/config.h"
#include "array.h"
-#include "buffer.h"
+#include "str.h"
#include "config_backend.h"
#include "config_entries.h"
#include "config_parse.h"
@@ -41,7 +41,7 @@ typedef struct {
bool locked;
git_filebuf locked_buf;
- git_buf locked_content;
+ git_str locked_content;
config_file file;
} config_file_backend;
@@ -131,7 +131,7 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
static int config_file_is_modified(int *modified, config_file *file)
{
config_file *include;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_oid hash;
uint32_t i;
int error = 0;
@@ -159,7 +159,7 @@ check_includes:
}
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -486,7 +486,7 @@ static int config_file_unlock(git_config_backend *_cfg, int success)
}
git_filebuf_cleanup(&cfg->locked_buf);
- git_buf_dispose(&cfg->locked_content);
+ git_str_dispose(&cfg->locked_content);
cfg->locked = false;
return error;
@@ -523,7 +523,7 @@ int git_config_backend_from_file(git_config_backend **out, const char *path)
return 0;
}
-static int included_path(git_buf *out, const char *dir, const char *path)
+static int included_path(git_str *out, const char *dir, const char *path)
{
/* From the user's home */
if (path[0] == '~' && path[1] == '/')
@@ -535,7 +535,7 @@ static int included_path(git_buf *out, const char *dir, const char *path)
/* Escape the values to write them to the file */
static char *escape_value(const char *ptr)
{
- git_buf buf;
+ git_str buf;
size_t len;
const char *esc;
@@ -545,29 +545,29 @@ static char *escape_value(const char *ptr)
if (!len)
return git__calloc(1, sizeof(char));
- if (git_buf_init(&buf, len) < 0)
+ if (git_str_init(&buf, len) < 0)
return NULL;
while (*ptr != '\0') {
if ((esc = strchr(git_config_escaped, *ptr)) != NULL) {
- git_buf_putc(&buf, '\\');
- git_buf_putc(&buf, git_config_escapes[esc - git_config_escaped]);
+ git_str_putc(&buf, '\\');
+ git_str_putc(&buf, git_config_escapes[esc - git_config_escaped]);
} else {
- git_buf_putc(&buf, *ptr);
+ git_str_putc(&buf, *ptr);
}
ptr++;
}
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return NULL;
- return git_buf_detach(&buf);
+ return git_str_detach(&buf);
}
static int parse_include(config_file_parse_data *parse_data, const char *file)
{
config_file *include;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *dir;
int result;
@@ -577,7 +577,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
if ((result = git_path_dirname_r(&path, parse_data->file->path)) < 0)
return result;
- dir = git_buf_detach(&path);
+ dir = git_str_detach(&path);
result = included_path(&path, dir, file);
git__free(dir);
@@ -588,7 +588,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
GIT_ERROR_CHECK_ALLOC(include);
memset(include, 0, sizeof(*include));
git_array_init(include->includes);
- include->path = git_buf_detach(&path);
+ include->path = git_str_detach(&path);
result = config_file_read(parse_data->entries, parse_data->repo, include,
parse_data->level, parse_data->depth+1);
@@ -608,38 +608,38 @@ static int do_match_gitdir(
const char *condition,
bool case_insensitive)
{
- git_buf pattern = GIT_BUF_INIT, gitdir = GIT_BUF_INIT;
+ git_str pattern = GIT_STR_INIT, gitdir = GIT_STR_INIT;
int error;
if (condition[0] == '.' && git_path_is_dirsep(condition[1])) {
git_path_dirname_r(&pattern, cfg_file);
- git_buf_joinpath(&pattern, pattern.ptr, condition + 2);
+ git_str_joinpath(&pattern, pattern.ptr, condition + 2);
} else if (condition[0] == '~' && git_path_is_dirsep(condition[1]))
git_sysdir_expand_global_file(&pattern, condition + 1);
else if (!git_path_is_absolute(condition))
- git_buf_joinpath(&pattern, "**", condition);
+ git_str_joinpath(&pattern, "**", condition);
else
- git_buf_sets(&pattern, condition);
+ git_str_sets(&pattern, condition);
if (git_path_is_dirsep(condition[strlen(condition) - 1]))
- git_buf_puts(&pattern, "**");
+ git_str_puts(&pattern, "**");
- if (git_buf_oom(&pattern)) {
+ if (git_str_oom(&pattern)) {
error = -1;
goto out;
}
- if ((error = git_repository_item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
+ if ((error = git_repository__item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
goto out;
if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1]))
- git_buf_truncate(&gitdir, gitdir.size - 1);
+ git_str_truncate(&gitdir, gitdir.size - 1);
*matches = wildmatch(pattern.ptr, gitdir.ptr,
WM_PATHNAME | (case_insensitive ? WM_CASEFOLD : 0)) == WM_MATCH;
out:
- git_buf_dispose(&pattern);
- git_buf_dispose(&gitdir);
+ git_str_dispose(&pattern);
+ git_str_dispose(&gitdir);
return error;
}
@@ -667,7 +667,7 @@ static int conditional_match_onbranch(
const char *cfg_file,
const char *condition)
{
- git_buf reference = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str reference = GIT_STR_INIT, buf = GIT_STR_INIT;
int error;
GIT_UNUSED(cfg_file);
@@ -680,33 +680,33 @@ static int conditional_match_onbranch(
* an endless recursion.
*/
- if ((error = git_buf_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
(error = git_futils_readbuffer(&reference, buf.ptr)) < 0)
goto out;
- git_buf_rtrim(&reference);
+ git_str_rtrim(&reference);
if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF)))
goto out;
- git_buf_consume(&reference, reference.ptr + strlen(GIT_SYMREF));
+ git_str_consume(&reference, reference.ptr + strlen(GIT_SYMREF));
if (git__strncmp(reference.ptr, GIT_REFS_HEADS_DIR, strlen(GIT_REFS_HEADS_DIR)))
goto out;
- git_buf_consume(&reference, reference.ptr + strlen(GIT_REFS_HEADS_DIR));
+ git_str_consume(&reference, reference.ptr + strlen(GIT_REFS_HEADS_DIR));
/*
* If the condition ends with a '/', then we should treat it as if
* it had '**' appended.
*/
- if ((error = git_buf_sets(&buf, condition)) < 0)
+ if ((error = git_str_sets(&buf, condition)) < 0)
goto out;
if (git_path_is_dirsep(condition[strlen(condition) - 1]) &&
- (error = git_buf_puts(&buf, "**")) < 0)
+ (error = git_str_puts(&buf, "**")) < 0)
goto out;
*matches = wildmatch(buf.ptr, reference.ptr, WM_PATHNAME) == WM_MATCH;
out:
- git_buf_dispose(&reference);
- git_buf_dispose(&buf);
+ git_str_dispose(&reference);
+ git_str_dispose(&buf);
return error;
@@ -763,7 +763,7 @@ static int read_on_variable(
void *data)
{
config_file_parse_data *parse_data = (config_file_parse_data *)data;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_config_entry *entry;
const char *c;
int result = 0;
@@ -777,19 +777,19 @@ static int read_on_variable(
* here. Git appears to warn in most cases if it sees
* un-namespaced config options.
*/
- git_buf_puts(&buf, current_section);
- git_buf_putc(&buf, '.');
+ git_str_puts(&buf, current_section);
+ git_str_putc(&buf, '.');
}
for (c = var_name; *c; c++)
- git_buf_putc(&buf, git__tolower(*c));
+ git_str_putc(&buf, git__tolower(*c));
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
entry = git__calloc(1, sizeof(git_config_entry));
GIT_ERROR_CHECK_ALLOC(entry);
- entry->name = git_buf_detach(&buf);
+ entry->name = git_str_detach(&buf);
entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level;
entry->include_depth = parse_data->depth;
@@ -856,7 +856,7 @@ static int config_file_read(
git_config_level_t level,
int depth)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
struct stat st;
int error;
@@ -877,36 +877,36 @@ static int config_file_read(
goto out;
out:
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
return error;
}
-static int write_section(git_buf *fbuf, const char *key)
+static int write_section(git_str *fbuf, const char *key)
{
int result;
const char *dot;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* All of this just for [section "subsection"] */
dot = strchr(key, '.');
- git_buf_putc(&buf, '[');
+ git_str_putc(&buf, '[');
if (dot == NULL) {
- git_buf_puts(&buf, key);
+ git_str_puts(&buf, key);
} else {
char *escaped;
- git_buf_put(&buf, key, dot - key);
+ git_str_put(&buf, key, dot - key);
escaped = escape_value(dot + 1);
GIT_ERROR_CHECK_ALLOC(escaped);
- git_buf_printf(&buf, " \"%s\"", escaped);
+ git_str_printf(&buf, " \"%s\"", escaped);
git__free(escaped);
}
- git_buf_puts(&buf, "]\n");
+ git_str_puts(&buf, "]\n");
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
- result = git_buf_put(fbuf, git_buf_cstr(&buf), buf.size);
- git_buf_dispose(&buf);
+ result = git_str_put(fbuf, git_str_cstr(&buf), buf.size);
+ git_str_dispose(&buf);
return result;
}
@@ -930,8 +930,8 @@ static const char *quotes_for_value(const char *value)
}
struct write_data {
- git_buf *buf;
- git_buf buffered_comment;
+ git_str *buf;
+ git_str buffered_comment;
unsigned int in_section : 1,
preg_replaced : 1;
const char *orig_section;
@@ -942,12 +942,12 @@ struct write_data {
const char *value;
};
-static int write_line_to(git_buf *buf, const char *line, size_t line_len)
+static int write_line_to(git_str *buf, const char *line, size_t line_len)
{
- int result = git_buf_put(buf, line, line_len);
+ int result = git_str_put(buf, line, line_len);
if (!result && line_len && line[line_len-1] != '\n')
- result = git_buf_printf(buf, "\n");
+ result = git_str_printf(buf, "\n");
return result;
}
@@ -963,7 +963,7 @@ static int write_value(struct write_data *write_data)
int result;
q = quotes_for_value(write_data->value);
- result = git_buf_printf(write_data->buf,
+ result = git_str_printf(write_data->buf,
"\t%s = %s%s%s\n", write_data->orig_name, q, write_data->value, q);
/* If we are updating a single name/value, we're done. Setting `value`
@@ -1002,8 +1002,8 @@ static int write_on_section(
* If there were comments just before this section, dump them as well.
*/
if (!result) {
- result = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size);
- git_buf_clear(&write_data->buffered_comment);
+ result = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size);
+ git_str_clear(&write_data->buffered_comment);
}
if (!result)
@@ -1031,10 +1031,10 @@ static int write_on_variable(
/*
* If there were comments just before this variable, let's dump them as well.
*/
- if ((error = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
+ if ((error = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
return error;
- git_buf_clear(&write_data->buffered_comment);
+ git_str_clear(&write_data->buffered_comment);
/* See if we are to update this name/value pair; first examine name */
if (write_data->in_section &&
@@ -1081,7 +1081,7 @@ static int write_on_eof(
/*
* If we've buffered comments when reaching EOF, make sure to dump them.
*/
- if ((result = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
+ if ((result = git_str_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
return result;
/* If we are at the EOF and have not written our value (again, for a
@@ -1108,7 +1108,7 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
{
char *orig_section = NULL, *section = NULL, *orig_name, *name, *ldot;
- git_buf buf = GIT_BUF_INIT, contents = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, contents = GIT_STR_INIT;
git_config_parser parser = GIT_CONFIG_PARSER_INIT;
git_filebuf file = GIT_FILEBUF_INIT;
struct write_data write_data;
@@ -1117,7 +1117,7 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
memset(&write_data, 0, sizeof(write_data));
if (cfg->locked) {
- error = git_buf_puts(&contents, git_buf_cstr(&cfg->locked_content) == NULL ? "" : git_buf_cstr(&cfg->locked_content));
+ error = git_str_puts(&contents, git_str_cstr(&cfg->locked_content) == NULL ? "" : git_str_cstr(&cfg->locked_content));
} else {
if ((error = git_filebuf_open(&file, cfg->file.path, GIT_FILEBUF_HASH_CONTENTS,
GIT_CONFIG_FILE_MODE)) < 0)
@@ -1157,10 +1157,10 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
if (cfg->locked) {
size_t len = buf.asize;
/* Update our copy with the modified contents */
- git_buf_dispose(&cfg->locked_content);
- git_buf_attach(&cfg->locked_content, git_buf_detach(&buf), len);
+ git_str_dispose(&cfg->locked_content);
+ git_str_attach(&cfg->locked_content, git_str_detach(&buf), len);
} else {
- git_filebuf_write(&file, git_buf_cstr(&buf), git_buf_len(&buf));
+ git_filebuf_write(&file, git_str_cstr(&buf), git_str_len(&buf));
if ((error = git_filebuf_commit(&file)) < 0)
goto done;
@@ -1172,9 +1172,9 @@ static int config_file_write(config_file_backend *cfg, const char *orig_key, con
done:
git__free(section);
git__free(orig_section);
- git_buf_dispose(&write_data.buffered_comment);
- git_buf_dispose(&buf);
- git_buf_dispose(&contents);
+ git_str_dispose(&write_data.buffered_comment);
+ git_str_dispose(&buf);
+ git_str_dispose(&contents);
git_filebuf_cleanup(&file);
git_config_parser_dispose(&parser);
diff --git a/src/config_mem.c b/src/config_mem.c
index 5b573a995..560229cf5 100644
--- a/src/config_mem.c
+++ b/src/config_mem.c
@@ -14,7 +14,7 @@
typedef struct {
git_config_backend parent;
git_config_entries *entries;
- git_buf cfg;
+ git_str cfg;
} config_memory_backend;
typedef struct {
@@ -38,7 +38,7 @@ static int read_variable_cb(
void *payload)
{
config_memory_parse_data *parse_data = (config_memory_parse_data *) payload;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_config_entry *entry;
const char *c;
int result;
@@ -52,19 +52,19 @@ static int read_variable_cb(
* here. Git appears to warn in most cases if it sees
* un-namespaced config options.
*/
- git_buf_puts(&buf, current_section);
- git_buf_putc(&buf, '.');
+ git_str_puts(&buf, current_section);
+ git_str_putc(&buf, '.');
}
for (c = var_name; *c; c++)
- git_buf_putc(&buf, git__tolower(*c));
+ git_str_putc(&buf, git__tolower(*c));
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
entry = git__calloc(1, sizeof(git_config_entry));
GIT_ERROR_CHECK_ALLOC(entry);
- entry->name = git_buf_detach(&buf);
+ entry->name = git_str_detach(&buf);
entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level;
entry->include_depth = 0;
@@ -178,7 +178,7 @@ static void config_memory_free(git_config_backend *_backend)
return;
git_config_entries_free(backend->entries);
- git_buf_dispose(&backend->cfg);
+ git_str_dispose(&backend->cfg);
git__free(backend);
}
@@ -194,7 +194,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si
return -1;
}
- if (git_buf_set(&backend->cfg, cfg, len) < 0) {
+ if (git_str_set(&backend->cfg, cfg, len) < 0) {
git_config_entries_free(backend->entries);
git__free(backend);
return -1;
diff --git a/src/config_parse.c b/src/config_parse.c
index 9f95e67d7..3159cbef7 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -67,7 +67,7 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
int c, rpos;
const char *first_quote, *last_quote;
const char *line_start = line;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t quoted_len, alloc_len, base_name_len = strlen(base_name);
/* Skip any additional whitespace before our section name */
@@ -97,8 +97,8 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
- if (git_buf_grow(&buf, alloc_len) < 0 ||
- git_buf_printf(&buf, "%s.", base_name) < 0)
+ if (git_str_grow(&buf, alloc_len) < 0 ||
+ git_str_printf(&buf, "%s.", base_name) < 0)
goto end_error;
rpos = 0;
@@ -132,25 +132,25 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
break;
}
- git_buf_putc(&buf, (char)c);
+ git_str_putc(&buf, (char)c);
c = line[++rpos];
} while (line + rpos < last_quote);
end_parse:
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
goto end_error;
if (line[rpos] != '"' || line[rpos + 1] != ']') {
set_parse_error(reader, rpos, "unexpected text after closing quotes");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return -1;
}
- *section_name = git_buf_detach(&buf);
+ *section_name = git_str_detach(&buf);
return (int)(&line[rpos + 2] - line_start); /* rpos is at the closing quote */
end_error:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return -1;
}
@@ -227,11 +227,11 @@ fail_parse:
static int skip_bom(git_parse_ctx *parser)
{
- git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len);
- git_buf_bom_t bom;
- int bom_offset = git_buf_detect_bom(&bom, &buf);
+ git_str buf = GIT_STR_INIT_CONST(parser->content, parser->content_len);
+ git_str_bom_t bom;
+ int bom_offset = git_str_detect_bom(&bom, &buf);
- if (bom == GIT_BUF_BOM_UTF8)
+ if (bom == GIT_STR_BOM_UTF8)
git_parse_advance_chars(parser, bom_offset);
/* TODO: reference implementation is pretty stupid with BoM */
@@ -325,7 +325,7 @@ done:
return 0;
}
-static int parse_multiline_variable(git_config_parser *reader, git_buf *value, int in_quotes)
+static int parse_multiline_variable(git_config_parser *reader, git_str *value, int in_quotes)
{
int quote_count;
bool multiline = true;
@@ -358,7 +358,7 @@ static int parse_multiline_variable(git_config_parser *reader, git_buf *value, i
goto out;
/* Add this line to the multiline var */
- if ((error = git_buf_puts(value, proc_line)) < 0)
+ if ((error = git_str_puts(value, proc_line)) < 0)
goto out;
next:
@@ -445,18 +445,18 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
goto out;
if (multiline) {
- git_buf multi_value = GIT_BUF_INIT;
- git_buf_attach(&multi_value, value, 0);
+ git_str multi_value = GIT_STR_INIT;
+ git_str_attach(&multi_value, value, 0);
value = NULL;
if (parse_multiline_variable(reader, &multi_value, quote_count % 2) < 0 ||
- git_buf_oom(&multi_value)) {
+ git_str_oom(&multi_value)) {
error = -1;
- git_buf_dispose(&multi_value);
+ git_str_dispose(&multi_value);
goto out;
}
- value = git_buf_detach(&multi_value);
+ value = git_str_detach(&multi_value);
}
}
diff --git a/src/crlf.c b/src/crlf.c
index 406f7140f..7895ddec2 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -12,6 +12,7 @@
#include "git2/index.h"
#include "git2/sys/filter.h"
+#include "buf.h"
#include "futils.h"
#include "hash.h"
#include "filter.h"
@@ -152,7 +153,7 @@ static git_configmap_value output_eol(struct crlf_attrs *ca)
GIT_INLINE(int) check_safecrlf(
struct crlf_attrs *ca,
const git_filter_source *src,
- git_buf_text_stats *stats)
+ git_str_text_stats *stats)
{
const char *filename = git_filter_source_path(src);
@@ -206,19 +207,19 @@ GIT_INLINE(int) check_safecrlf(
static int crlf_apply_to_odb(
struct crlf_attrs *ca,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *src)
{
- git_buf_text_stats stats;
+ git_str_text_stats stats;
bool is_binary;
int error;
/* Binary attribute? Empty file? Nothing to do */
- if (ca->crlf_action == GIT_CRLF_BINARY || !git_buf_len(from))
+ if (ca->crlf_action == GIT_CRLF_BINARY || from->size == 0)
return GIT_PASSTHROUGH;
- is_binary = git_buf_gather_text_stats(&stats, from, false);
+ is_binary = git_str_gather_text_stats(&stats, from, false);
/* Heuristics to see if we can skip the conversion.
* Straight from Core Git.
@@ -246,22 +247,22 @@ static int crlf_apply_to_odb(
return GIT_PASSTHROUGH;
/* Actually drop the carriage returns */
- return git_buf_crlf_to_lf(to, from);
+ return git_str_crlf_to_lf(to, from);
}
static int crlf_apply_to_workdir(
struct crlf_attrs *ca,
- git_buf *to,
- const git_buf *from)
+ git_str *to,
+ const git_str *from)
{
- git_buf_text_stats stats;
+ git_str_text_stats stats;
bool is_binary;
/* Empty file? Nothing to do. */
- if (git_buf_len(from) == 0 || output_eol(ca) != GIT_EOL_CRLF)
+ if (git_str_len(from) == 0 || output_eol(ca) != GIT_EOL_CRLF)
return GIT_PASSTHROUGH;
- is_binary = git_buf_gather_text_stats(&stats, from, false);
+ is_binary = git_str_gather_text_stats(&stats, from, false);
/* If there are no LFs, or all LFs are part of a CRLF, nothing to do */
if (stats.lf == 0 || stats.lf == stats.crlf)
@@ -280,7 +281,7 @@ static int crlf_apply_to_workdir(
return GIT_PASSTHROUGH;
}
- return git_buf_lf_to_crlf(to, from);
+ return git_str_lf_to_crlf(to, from);
}
static int convert_attrs(
@@ -368,22 +369,24 @@ static int crlf_check(
static int crlf_apply(
git_filter *self,
void **payload, /* may be read and/or set */
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *src)
{
+ int error = 0;
+
/* initialize payload in case `check` was bypassed */
if (!*payload) {
- int error = crlf_check(self, payload, src, NULL);
-
- if (error < 0)
+ if ((error = crlf_check(self, payload, src, NULL)) < 0)
return error;
}
if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
- return crlf_apply_to_workdir(*payload, to, from);
+ error = crlf_apply_to_workdir(*payload, to, from);
else
- return crlf_apply_to_odb(*payload, to, from, src);
+ error = crlf_apply_to_odb(*payload, to, from, src);
+
+ return error;
}
static int crlf_stream(
diff --git a/src/describe.c b/src/describe.c
index 103d0da5c..1033eac50 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -12,6 +12,7 @@
#include "git2/diff.h"
#include "git2/status.h"
+#include "buf.h"
#include "commit.h"
#include "commit_list.h"
#include "oidmap.h"
@@ -322,7 +323,7 @@ static unsigned long finish_depth_computation(
return seen_commits;
}
-static int display_name(git_buf *buf, git_repository *repo, struct commit_name *n)
+static int display_name(git_str *buf, git_repository *repo, struct commit_name *n)
{
if (n->prio == 2 && !n->tag) {
if (git_tag_lookup(&n->tag, repo, &n->sha1) < 0) {
@@ -346,9 +347,9 @@ static int display_name(git_buf *buf, git_repository *repo, struct commit_name *
}
if (n->tag)
- git_buf_printf(buf, "%s", git_tag_name(n->tag));
+ git_str_printf(buf, "%s", git_tag_name(n->tag));
else
- git_buf_printf(buf, "%s", n->path);
+ git_str_printf(buf, "%s", n->path);
return 0;
}
@@ -388,7 +389,7 @@ static int find_unique_abbrev_size(
}
static int show_suffix(
- git_buf *buf,
+ git_str *buf,
int depth,
git_repository *repo,
const git_oid *id,
@@ -403,11 +404,11 @@ static int show_suffix(
git_oid_fmt(hex_oid, id);
- git_buf_printf(buf, "-%d-g", depth);
+ git_str_printf(buf, "-%d-g", depth);
- git_buf_put(buf, hex_oid, size);
+ git_str_put(buf, hex_oid, size);
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
#define MAX_CANDIDATES_TAGS FLAG_BITS - 1
@@ -769,7 +770,10 @@ static int normalize_format_options(
return 0;
}
-int git_describe_format(git_buf *out, const git_describe_result *result, const git_describe_format_options *given)
+static int git_describe__format(
+ git_str *out,
+ const git_describe_result *result,
+ const git_describe_format_options *given)
{
int error;
git_repository *repo;
@@ -782,10 +786,6 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
GIT_ERROR_CHECK_VERSION(given, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, "git_describe_format_options");
normalize_format_options(&opts, given);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
-
if (opts.always_use_long_format && opts.abbreviated_size == 0) {
git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - "
"'always_use_long_format' is incompatible with a zero"
@@ -809,9 +809,9 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
}
if (result->dirty && opts.dirty_suffix)
- git_buf_puts(out, opts.dirty_suffix);
+ git_str_puts(out, opts.dirty_suffix);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
/* If we didn't find *any* tags, we fall back to the commit's id */
@@ -824,12 +824,12 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
return -1;
git_oid_fmt(hex_oid, &result->commit_id);
- git_buf_put(out, hex_oid, size);
+ git_str_put(out, hex_oid, size);
if (result->dirty && opts.dirty_suffix)
- git_buf_puts(out, opts.dirty_suffix);
+ git_str_puts(out, opts.dirty_suffix);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
/* Lastly, if we found a matching tag, we show that */
@@ -845,10 +845,18 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
}
if (result->dirty && opts.dirty_suffix) {
- git_buf_puts(out, opts.dirty_suffix);
+ git_str_puts(out, opts.dirty_suffix);
}
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
+}
+
+int git_describe_format(
+ git_buf *out,
+ const git_describe_result *result,
+ const git_describe_format_options *given)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_describe__format, result, given);
}
void git_describe_result_free(git_describe_result *result)
diff --git a/src/diff.c b/src/diff.c
index 44b67ee06..9840d6050 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -8,6 +8,7 @@
#include "diff.h"
#include "common.h"
+#include "buf.h"
#include "patch.h"
#include "email.h"
#include "commit.h"
@@ -162,6 +163,7 @@ int git_diff_format_email(
const git_diff_format_email_options *opts)
{
git_email_create_options email_create_opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
+ git_str email = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
@@ -172,14 +174,29 @@ int git_diff_format_email(
GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION,
"git_format_email_options");
+ /* This is a `git_buf` special case; subsequent calls append. */
+ email.ptr = out->ptr;
+ email.asize = out->reserved;
+ email.size = out->size;
+
+ out->ptr = git_str__initstr;
+ out->reserved = 0;
+ out->size = 0;
+
if ((opts->flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0)
email_create_opts.subject_prefix = "";
-
- error = git_email__append_from_diff(out, diff, opts->patch_no,
+ error = git_email__append_from_diff(&email, diff, opts->patch_no,
opts->total_patches, opts->id, opts->summary, opts->body,
opts->author, &email_create_opts);
+ if (error < 0)
+ goto done;
+
+ error = git_buf_fromstr(out, &email);
+
+done:
+ git_str_dispose(&email);
return error;
}
@@ -282,7 +299,7 @@ static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
return 0;
}
-static void strip_spaces(git_buf *buf)
+static void strip_spaces(git_str *buf)
{
char *src = buf->ptr, *dst = buf->ptr;
char c;
@@ -295,7 +312,7 @@ static void strip_spaces(git_buf *buf)
}
}
- git_buf_truncate(buf, len);
+ git_str_truncate(buf, len);
}
static int diff_patchid_print_callback_to_buf(
@@ -305,7 +322,7 @@ static int diff_patchid_print_callback_to_buf(
void *payload)
{
struct patch_id_args *args = (struct patch_id_args *) payload;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
if (line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL ||
@@ -331,7 +348,7 @@ static int diff_patchid_print_callback_to_buf(
args->first_file = 0;
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/diff.h b/src/diff.h
index 69233b39f..4b0339809 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -14,9 +14,7 @@
#include "git2/sys/diff.h"
#include "git2/oid.h"
-#include <stdio.h>
#include "vector.h"
-#include "buffer.h"
#include "iterator.h"
#include "repository.h"
#include "pool.h"
@@ -53,7 +51,7 @@ struct git_diff {
};
extern int git_diff_delta__format_file_header(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const char *oldpfx,
const char *newpfx,
diff --git a/src/diff_driver.c b/src/diff_driver.c
index a3892d35e..f6b51d8ba 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -90,7 +90,7 @@ static int diff_driver_add_patterns(
int error = 0;
const char *scan, *end;
git_diff_driver_pattern *pat = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
for (scan = regex_str; scan; scan = end) {
/* get pattern to fill in */
@@ -105,10 +105,10 @@ static int diff_driver_add_patterns(
}
if ((end = strchr(scan, '\n')) != NULL) {
- error = git_buf_set(&buf, scan, end - scan);
+ error = git_str_set(&buf, scan, end - scan);
end++;
} else {
- error = git_buf_sets(&buf, scan);
+ error = git_str_sets(&buf, scan);
}
if (error < 0)
break;
@@ -122,7 +122,7 @@ static int diff_driver_add_patterns(
if (error && pat != NULL)
(void)git_array_pop(drv->fn_patterns); /* release last item */
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* We want to ignore bad patterns, so return success regardless */
return 0;
@@ -237,7 +237,7 @@ static int git_diff_driver_load(
git_diff_driver *drv;
size_t namelen;
git_config *cfg = NULL;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
git_config_entry *ce = NULL;
bool found_driver = false;
@@ -260,7 +260,7 @@ static int git_diff_driver_load(
goto done;
}
- if ((error = git_buf_printf(&name, "diff.%s.binary", driver_name)) < 0)
+ if ((error = git_str_printf(&name, "diff.%s.binary", driver_name)) < 0)
goto done;
switch (git_config__get_bool_force(cfg, name.ptr, -1)) {
@@ -281,8 +281,8 @@ static int git_diff_driver_load(
/* TODO: warn if diff.<name>.command or diff.<name>.textconv are set */
- git_buf_truncate(&name, namelen + strlen("diff.."));
- if ((error = git_buf_PUTS(&name, "xfuncname")) < 0)
+ git_str_truncate(&name, namelen + strlen("diff.."));
+ if ((error = git_str_PUTS(&name, "xfuncname")) < 0)
goto done;
if ((error = git_config_get_multivar_foreach(
@@ -292,8 +292,8 @@ static int git_diff_driver_load(
git_error_clear(); /* no diff.<driver>.xfuncname, so just continue */
}
- git_buf_truncate(&name, namelen + strlen("diff.."));
- if ((error = git_buf_PUTS(&name, "funcname")) < 0)
+ git_str_truncate(&name, namelen + strlen("diff.."));
+ if ((error = git_str_PUTS(&name, "funcname")) < 0)
goto done;
if ((error = git_config_get_multivar_foreach(
@@ -309,8 +309,8 @@ static int git_diff_driver_load(
found_driver = true;
}
- git_buf_truncate(&name, namelen + strlen("diff.."));
- if ((error = git_buf_PUTS(&name, "wordregex")) < 0)
+ git_str_truncate(&name, namelen + strlen("diff.."));
+ if ((error = git_str_PUTS(&name, "wordregex")) < 0)
goto done;
if ((error = git_config__lookup_entry(&ce, cfg, name.ptr, false)) < 0)
@@ -340,7 +340,7 @@ static int git_diff_driver_load(
done:
git_config_entry_free(ce);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
git_config_free(cfg);
if (!*out) {
@@ -420,11 +420,11 @@ void git_diff_driver_update_options(
int git_diff_driver_content_is_binary(
git_diff_driver *driver, const char *content, size_t content_len)
{
- git_buf search = GIT_BUF_INIT;
+ git_str search = GIT_STR_INIT;
GIT_UNUSED(driver);
- git_buf_attach_notowned(&search, content,
+ git_str_attach_notowned(&search, content,
min(content_len, GIT_FILTER_BYTES_TO_CHECK_NUL));
/* TODO: provide encoding / binary detection callbacks that can
@@ -432,15 +432,15 @@ int git_diff_driver_content_is_binary(
* let's just use the simple NUL-byte detection that core git uses.
*/
- /* previously was: if (git_buf_is_binary(&search)) */
- if (git_buf_contains_nul(&search))
+ /* previously was: if (git_str_is_binary(&search)) */
+ if (git_str_contains_nul(&search))
return 1;
return 0;
}
static int diff_context_line__simple(
- git_diff_driver *driver, git_buf *line)
+ git_diff_driver *driver, git_str *line)
{
char firstch = line->ptr[0];
GIT_UNUSED(driver);
@@ -448,7 +448,7 @@ static int diff_context_line__simple(
}
static int diff_context_line__pattern_match(
- git_diff_driver *driver, git_buf *line)
+ git_diff_driver *driver, git_str *line)
{
size_t i, maxi = git_array_size(driver->fn_patterns);
git_regmatch pmatch[2];
@@ -462,9 +462,9 @@ static int diff_context_line__pattern_match(
/* use pmatch data to trim line data */
i = (pmatch[1].start >= 0) ? 1 : 0;
- git_buf_consume(line, git_buf_cstr(line) + pmatch[i].start);
- git_buf_truncate(line, pmatch[i].end - pmatch[i].start);
- git_buf_rtrim(line);
+ git_str_consume(line, git_str_cstr(line) + pmatch[i].start);
+ git_str_truncate(line, pmatch[i].end - pmatch[i].start);
+ git_str_rtrim(line);
return true;
}
@@ -482,9 +482,9 @@ static long diff_context_find(
{
git_diff_find_context_payload *ctxt = payload;
- if (git_buf_set(&ctxt->line, line, (size_t)line_len) < 0)
+ if (git_str_set(&ctxt->line, line, (size_t)line_len) < 0)
return -1;
- git_buf_rtrim(&ctxt->line);
+ git_str_rtrim(&ctxt->line);
if (!ctxt->line.size)
return -1;
@@ -511,14 +511,14 @@ void git_diff_find_context_init(
payload_out->driver = driver;
payload_out->match_line = (driver->type == DIFF_DRIVER_PATTERNLIST) ?
diff_context_line__pattern_match : diff_context_line__simple;
- git_buf_init(&payload_out->line, 0);
+ git_str_init(&payload_out->line, 0);
}
}
void git_diff_find_context_clear(git_diff_find_context_payload *payload)
{
if (payload) {
- git_buf_dispose(&payload->line);
+ git_str_dispose(&payload->line);
payload->driver = NULL;
}
}
diff --git a/src/diff_driver.h b/src/diff_driver.h
index a03a67e67..03711e89e 100644
--- a/src/diff_driver.h
+++ b/src/diff_driver.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "attr_file.h"
-#include "buffer.h"
+#include "str.h"
typedef struct git_diff_driver_registry git_diff_driver_registry;
@@ -34,12 +34,12 @@ typedef long (*git_diff_find_context_fn)(
const char *, long, char *, long, void *);
typedef int (*git_diff_find_context_line)(
- git_diff_driver *, git_buf *);
+ git_diff_driver *, git_str *);
typedef struct {
git_diff_driver *driver;
git_diff_find_context_line match_line;
- git_buf line;
+ git_str line;
} git_diff_find_context_payload;
void git_diff_find_context_init(
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;
}
diff --git a/src/diff_generate.c b/src/diff_generate.c
index aba9e52ba..dc690aa9b 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -586,7 +586,7 @@ int git_diff__oid_for_entry(
const git_oid *update_match)
{
git_diff_generated *diff;
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
git_index_entry entry = *src;
git_filter_list *fl = NULL;
int error = 0;
@@ -606,7 +606,7 @@ int git_diff__oid_for_entry(
if (p_stat(full_path.ptr, &st) < 0) {
error = git_path_set_error(errno, entry.path, "stat");
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -669,7 +669,7 @@ int git_diff__oid_for_entry(
}
}
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
return error;
}
@@ -1023,7 +1023,7 @@ static int handle_unmatched_new_item(
/* do not advance into directories that contain a .git file */
if (recurse_into_dir && !contains_oitem) {
- git_buf *full = NULL;
+ git_str *full = NULL;
if (git_iterator_current_workdir_path(&full, info->new_iter) < 0)
return -1;
if (full && git_path_contains(full, DOT_GIT)) {
diff --git a/src/diff_print.c b/src/diff_print.c
index 062e267b0..03d25b087 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -7,6 +7,7 @@
#include "common.h"
+#include "buf.h"
#include "diff.h"
#include "diff_file.h"
#include "patch_generate.h"
@@ -21,7 +22,7 @@ typedef struct {
git_diff_line_cb print_cb;
void *payload;
- git_buf *buf;
+ git_str *buf;
git_diff_line line;
const char *old_prefix;
@@ -34,7 +35,7 @@ typedef struct {
static int diff_print_info_init__common(
diff_print_info *pi,
- git_buf *out,
+ git_str *out,
git_repository *repo,
git_diff_format_t format,
git_diff_line_cb cb,
@@ -65,7 +66,7 @@ static int diff_print_info_init__common(
static int diff_print_info_init_fromdiff(
diff_print_info *pi,
- git_buf *out,
+ git_str *out,
git_diff *diff,
git_diff_format_t format,
git_diff_line_cb cb,
@@ -89,7 +90,7 @@ static int diff_print_info_init_fromdiff(
static int diff_print_info_init_frompatch(
diff_print_info *pi,
- git_buf *out,
+ git_str *out,
git_patch *patch,
git_diff_format_t format,
git_diff_line_cb cb,
@@ -142,7 +143,7 @@ static int diff_print_one_name_only(
const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
- git_buf *out = pi->buf;
+ git_str *out = pi->buf;
GIT_UNUSED(progress);
@@ -150,15 +151,15 @@ static int diff_print_one_name_only(
delta->status == GIT_DELTA_UNMODIFIED)
return 0;
- git_buf_clear(out);
- git_buf_puts(out, delta->new_file.path);
- git_buf_putc(out, '\n');
- if (git_buf_oom(out))
+ git_str_clear(out);
+ git_str_puts(out, delta->new_file.path);
+ git_str_putc(out, '\n');
+ if (git_str_oom(out))
return -1;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(out);
- pi->line.content_len = git_buf_len(out);
+ pi->line.content = git_str_cstr(out);
+ pi->line.content_len = git_str_len(out);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -167,7 +168,7 @@ static int diff_print_one_name_status(
const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
- git_buf *out = pi->buf;
+ git_str *out = pi->buf;
char old_suffix, new_suffix, code = git_diff_status_char(delta->status);
int(*strcomp)(const char *, const char *) = pi->strcomp ?
pi->strcomp : git__strcmp;
@@ -180,26 +181,26 @@ static int diff_print_one_name_status(
old_suffix = diff_pick_suffix(delta->old_file.mode);
new_suffix = diff_pick_suffix(delta->new_file.mode);
- git_buf_clear(out);
+ git_str_clear(out);
if (delta->old_file.path != delta->new_file.path &&
strcomp(delta->old_file.path,delta->new_file.path) != 0)
- git_buf_printf(out, "%c\t%s%c %s%c\n", code,
+ git_str_printf(out, "%c\t%s%c %s%c\n", code,
delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (delta->old_file.mode != delta->new_file.mode &&
delta->old_file.mode != 0 && delta->new_file.mode != 0)
- git_buf_printf(out, "%c\t%s%c %s%c\n", code,
+ git_str_printf(out, "%c\t%s%c %s%c\n", code,
delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (old_suffix != ' ')
- git_buf_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
+ git_str_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
else
- git_buf_printf(out, "%c\t%s\n", code, delta->old_file.path);
- if (git_buf_oom(out))
+ git_str_printf(out, "%c\t%s\n", code, delta->old_file.path);
+ if (git_str_oom(out))
return -1;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(out);
- pi->line.content_len = git_buf_len(out);
+ pi->line.content = git_str_cstr(out);
+ pi->line.content_len = git_str_len(out);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -208,7 +209,7 @@ static int diff_print_one_raw(
const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
- git_buf *out = pi->buf;
+ git_str *out = pi->buf;
int id_abbrev;
char code = git_diff_status_char(delta->status);
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
@@ -218,7 +219,7 @@ static int diff_print_one_raw(
if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ')
return 0;
- git_buf_clear(out);
+ git_str_clear(out);
id_abbrev = delta->old_file.mode ? delta->old_file.id_abbrev :
delta->new_file.id_abbrev;
@@ -233,43 +234,43 @@ static int diff_print_one_raw(
git_oid_tostr(start_oid, pi->id_strlen + 1, &delta->old_file.id);
git_oid_tostr(end_oid, pi->id_strlen + 1, &delta->new_file.id);
- git_buf_printf(
+ git_str_printf(
out, (pi->id_strlen <= GIT_OID_HEXSZ) ?
":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);
if (delta->similarity > 0)
- git_buf_printf(out, "%03u", delta->similarity);
+ git_str_printf(out, "%03u", delta->similarity);
if (delta->old_file.path != delta->new_file.path)
- git_buf_printf(
+ git_str_printf(
out, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
else
- git_buf_printf(
+ git_str_printf(
out, "\t%s\n", delta->old_file.path ?
delta->old_file.path : delta->new_file.path);
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(out);
- pi->line.content_len = git_buf_len(out);
+ pi->line.content = git_str_cstr(out);
+ pi->line.content_len = git_str_len(out);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
static int diff_print_modes(
- git_buf *out, const git_diff_delta *delta)
+ git_str *out, const git_diff_delta *delta)
{
- git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
- git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
+ git_str_printf(out, "old mode %o\n", delta->old_file.mode);
+ git_str_printf(out, "new mode %o\n", delta->new_file.mode);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int diff_print_oid_range(
- git_buf *out, const git_diff_delta *delta, int id_strlen,
+ git_str *out, const git_diff_delta *delta, int id_strlen,
bool print_index)
{
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
@@ -295,34 +296,34 @@ static int diff_print_oid_range(
if (delta->old_file.mode == delta->new_file.mode) {
if (print_index)
- git_buf_printf(out, "index %s..%s %o\n",
+ git_str_printf(out, "index %s..%s %o\n",
start_oid, end_oid, delta->old_file.mode);
} else {
if (delta->old_file.mode == 0)
- git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
+ git_str_printf(out, "new file mode %o\n", delta->new_file.mode);
else if (delta->new_file.mode == 0)
- git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
+ git_str_printf(out, "deleted file mode %o\n", delta->old_file.mode);
else
diff_print_modes(out, delta);
if (print_index)
- git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
+ git_str_printf(out, "index %s..%s\n", start_oid, end_oid);
}
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int diff_delta_format_path(
- git_buf *out, const char *prefix, const char *filename)
+ git_str *out, const char *prefix, const char *filename)
{
- if (git_buf_joinpath(out, prefix, filename) < 0)
+ if (git_str_joinpath(out, prefix, filename) < 0)
return -1;
- return git_buf_quote(out);
+ return git_str_quote(out);
}
static int diff_delta_format_with_paths(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const char *template,
const char *oldpath,
@@ -334,14 +335,14 @@ static int diff_delta_format_with_paths(
if (git_oid_is_zero(&delta->new_file.id))
newpath = "/dev/null";
- return git_buf_printf(out, template, oldpath, newpath);
+ return git_str_printf(out, template, oldpath, newpath);
}
static int diff_delta_format_similarity_header(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta)
{
- git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT;
const char *type;
int error = 0;
@@ -357,13 +358,13 @@ static int diff_delta_format_similarity_header(
else
type = "copy";
- if ((error = git_buf_puts(&old_path, delta->old_file.path)) < 0 ||
- (error = git_buf_puts(&new_path, delta->new_file.path)) < 0 ||
- (error = git_buf_quote(&old_path)) < 0 ||
- (error = git_buf_quote(&new_path)) < 0)
+ if ((error = git_str_puts(&old_path, delta->old_file.path)) < 0 ||
+ (error = git_str_puts(&new_path, delta->new_file.path)) < 0 ||
+ (error = git_str_quote(&old_path)) < 0 ||
+ (error = git_str_quote(&new_path)) < 0)
goto done;
- git_buf_printf(out,
+ git_str_printf(out,
"similarity index %d%%\n"
"%s from %s\n"
"%s to %s\n",
@@ -371,12 +372,12 @@ static int diff_delta_format_similarity_header(
type, old_path.ptr,
type, new_path.ptr);
- if (git_buf_oom(out))
+ if (git_str_oom(out))
error = -1;
done:
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -398,14 +399,14 @@ static bool delta_is_unchanged(const git_diff_delta *delta)
}
int git_diff_delta__format_file_header(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const char *oldpfx,
const char *newpfx,
int id_strlen,
bool print_index)
{
- git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT;
bool unchanged = delta_is_unchanged(delta);
int error = 0;
@@ -422,9 +423,9 @@ int git_diff_delta__format_file_header(
&new_path, newpfx, delta->new_file.path)) < 0)
goto done;
- git_buf_clear(out);
+ git_str_clear(out);
- git_buf_printf(out, "diff --git %s %s\n",
+ git_str_printf(out, "diff --git %s %s\n",
old_path.ptr, new_path.ptr);
if (unchanged && delta->old_file.mode != delta->new_file.mode)
@@ -446,12 +447,12 @@ int git_diff_delta__format_file_header(
"--- %s\n+++ %s\n", old_path.ptr, new_path.ptr);
}
- if (git_buf_oom(out))
+ if (git_str_oom(out))
error = -1;
done:
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -467,7 +468,7 @@ static int format_binary(
"delta" : "literal";
const char *scan, *end;
- git_buf_printf(pi->buf, "%s %" PRIuZ "\n", typename, inflatedlen);
+ git_str_printf(pi->buf, "%s %" PRIuZ "\n", typename, inflatedlen);
pi->line.num_lines++;
for (scan = data, end = data + datalen; scan < end; ) {
@@ -476,22 +477,22 @@ static int format_binary(
chunk_len = 52;
if (chunk_len <= 26)
- git_buf_putc(pi->buf, (char)chunk_len + 'A' - 1);
+ git_str_putc(pi->buf, (char)chunk_len + 'A' - 1);
else
- git_buf_putc(pi->buf, (char)chunk_len - 26 + 'a' - 1);
+ git_str_putc(pi->buf, (char)chunk_len - 26 + 'a' - 1);
- git_buf_encode_base85(pi->buf, scan, chunk_len);
- git_buf_putc(pi->buf, '\n');
+ git_str_encode_base85(pi->buf, scan, chunk_len);
+ git_str_putc(pi->buf, '\n');
- if (git_buf_oom(pi->buf))
+ if (git_str_oom(pi->buf))
return -1;
scan += chunk_len;
pi->line.num_lines++;
}
- git_buf_putc(pi->buf, '\n');
+ git_str_putc(pi->buf, '\n');
- if (git_buf_oom(pi->buf))
+ if (git_str_oom(pi->buf))
return -1;
return 0;
@@ -501,7 +502,7 @@ static int diff_print_patch_file_binary_noshow(
diff_print_info *pi, git_diff_delta *delta,
const char *old_pfx, const char *new_pfx)
{
- git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT, new_path = GIT_STR_INIT;
int error;
if ((error = diff_delta_format_path(&old_path, old_pfx, delta->old_file.path)) < 0 ||
@@ -513,8 +514,8 @@ static int diff_print_patch_file_binary_noshow(
pi->line.num_lines = 1;
done:
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -534,7 +535,7 @@ static int diff_print_patch_file_binary(
pi, delta, old_pfx, new_pfx);
pre_binary_size = pi->buf->size;
- git_buf_printf(pi->buf, "GIT binary patch\n");
+ git_str_printf(pi->buf, "GIT binary patch\n");
pi->line.num_lines++;
if ((error = format_binary(pi, binary->new_file.type, binary->new_file.data,
@@ -543,7 +544,7 @@ static int diff_print_patch_file_binary(
binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) {
if (error == GIT_EBUFS) {
git_error_clear();
- git_buf_truncate(pi->buf, pre_binary_size);
+ git_str_truncate(pi->buf, pre_binary_size);
return diff_print_patch_file_binary_noshow(
pi, delta, old_pfx, new_pfx);
@@ -589,8 +590,8 @@ static int diff_print_patch_file(
return error;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
- pi->line.content = git_buf_cstr(pi->buf);
- pi->line.content_len = git_buf_len(pi->buf);
+ pi->line.content = git_str_cstr(pi->buf);
+ pi->line.content_len = git_str_len(pi->buf);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -607,15 +608,15 @@ static int diff_print_patch_binary(
pi->new_prefix ? pi->new_prefix : DIFF_NEW_PREFIX_DEFAULT;
int error;
- git_buf_clear(pi->buf);
+ git_str_clear(pi->buf);
if ((error = diff_print_patch_file_binary(
pi, (git_diff_delta *)delta, old_pfx, new_pfx, binary)) < 0)
return error;
pi->line.origin = GIT_DIFF_LINE_BINARY;
- pi->line.content = git_buf_cstr(pi->buf);
- pi->line.content_len = git_buf_len(pi->buf);
+ pi->line.content = git_str_cstr(pi->buf);
+ pi->line.content_len = git_str_len(pi->buf);
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
@@ -659,7 +660,7 @@ int git_diff_print(
void *payload)
{
int error;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
diff_print_info pi;
git_diff_file_cb print_file = NULL;
git_diff_binary_cb print_binary = NULL;
@@ -704,7 +705,7 @@ int git_diff_print(
}
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -714,7 +715,7 @@ int git_diff_print_callback__to_buf(
const git_diff_line *line,
void *payload)
{
- git_buf *output = payload;
+ git_str *output = payload;
GIT_UNUSED(delta); GIT_UNUSED(hunk);
if (!output) {
@@ -725,9 +726,9 @@ int git_diff_print_callback__to_buf(
if (line->origin == GIT_DIFF_LINE_ADDITION ||
line->origin == GIT_DIFF_LINE_DELETION ||
line->origin == GIT_DIFF_LINE_CONTEXT)
- git_buf_putc(output, line->origin);
+ git_str_putc(output, line->origin);
- return git_buf_put(output, line->content, line->content_len);
+ return git_str_put(output, line->content, line->content_len);
}
int git_diff_print_callback__to_file_handle(
@@ -761,18 +762,24 @@ int git_diff_print_callback__to_file_handle(
return 0;
}
-/* print a git_diff to a git_buf */
+/* print a git_diff to a git_str */
int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format)
{
+ git_str str = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(diff);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = git_diff_print(diff, format, git_diff_print_callback__to_buf, &str)) < 0)
+ goto done;
+
+ error = git_buf_fromstr(out, &str);
- return git_diff_print(diff, format, git_diff_print_callback__to_buf, out);
+done:
+ git_str_dispose(&str);
+ return error;
}
/* print a git_patch to an output callback */
@@ -781,7 +788,7 @@ int git_patch_print(
git_diff_line_cb print_cb,
void *payload)
{
- git_buf temp = GIT_BUF_INIT;
+ git_str temp = GIT_STR_INIT;
diff_print_info pi;
int error;
@@ -799,20 +806,20 @@ int git_patch_print(
}
out:
- git_buf_dispose(&temp);
+ git_str_dispose(&temp);
return error;
}
-/* print a git_patch to a git_buf */
+/* print a git_patch to a git_str */
int git_patch_to_buf(git_buf *out, git_patch *patch)
{
- int error;
+ GIT_BUF_WRAP_PRIVATE(out, git_patch__to_buf, patch);
+}
+int git_patch__to_buf(git_str *out, git_patch *patch)
+{
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(patch);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
return git_patch_print(patch, git_diff_print_callback__to_buf, out);
}
diff --git a/src/diff_stats.c b/src/diff_stats.c
index 41a25bf8a..228f6f892 100644
--- a/src/diff_stats.c
+++ b/src/diff_stats.c
@@ -5,8 +5,10 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "diff_stats.h"
+#include "buf.h"
+#include "common.h"
#include "vector.h"
#include "diff.h"
#include "patch_generate.h"
@@ -47,7 +49,7 @@ static int digits_for_value(size_t val)
}
static int diff_file_stats_full_to_buf(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const diff_file_stats *filestat,
const git_diff_stats *stats,
@@ -70,12 +72,12 @@ static int diff_file_stats_full_to_buf(
if ((common_dirlen = git_path_common_dirlen(old_path, new_path)) &&
common_dirlen <= INT_MAX) {
- error = git_buf_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}",
+ error = git_str_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}",
(int) common_dirlen, old_path,
old_path + common_dirlen,
new_path + common_dirlen);
} else {
- error = git_buf_printf(out, " %s" DIFF_RENAME_FILE_SEPARATOR "%s",
+ error = git_str_printf(out, " %s" DIFF_RENAME_FILE_SEPARATOR "%s",
old_path, new_path);
}
@@ -83,7 +85,7 @@ static int diff_file_stats_full_to_buf(
goto on_error;
} else {
adddel_path = new_path ? new_path : old_path;
- if (git_buf_printf(out, " %s", adddel_path) < 0)
+ if (git_str_printf(out, " %s", adddel_path) < 0)
goto on_error;
padding = stats->max_name - strlen(adddel_path);
@@ -92,28 +94,28 @@ static int diff_file_stats_full_to_buf(
padding += strlen(DIFF_RENAME_FILE_SEPARATOR);
}
- if (git_buf_putcn(out, ' ', padding) < 0 ||
- git_buf_puts(out, " | ") < 0)
+ if (git_str_putcn(out, ' ', padding) < 0 ||
+ git_str_puts(out, " | ") < 0)
goto on_error;
if (delta->flags & GIT_DIFF_FLAG_BINARY) {
- if (git_buf_printf(out,
+ if (git_str_printf(out,
"Bin %" PRId64 " -> %" PRId64 " bytes", old_size, new_size) < 0)
goto on_error;
}
else {
- if (git_buf_printf(out,
+ if (git_str_printf(out,
"%*" PRIuZ, stats->max_digits,
filestat->insertions + filestat->deletions) < 0)
goto on_error;
if (filestat->insertions || filestat->deletions) {
- if (git_buf_putc(out, ' ') < 0)
+ if (git_str_putc(out, ' ') < 0)
goto on_error;
if (!width) {
- if (git_buf_putcn(out, '+', filestat->insertions) < 0 ||
- git_buf_putcn(out, '-', filestat->deletions) < 0)
+ if (git_str_putcn(out, '+', filestat->insertions) < 0 ||
+ git_str_putcn(out, '-', filestat->deletions) < 0)
goto on_error;
} else {
size_t total = filestat->insertions + filestat->deletions;
@@ -122,21 +124,21 @@ static int diff_file_stats_full_to_buf(
size_t plus = full * filestat->insertions / total;
size_t minus = full - plus;
- if (git_buf_putcn(out, '+', max(plus, 1)) < 0 ||
- git_buf_putcn(out, '-', max(minus, 1)) < 0)
+ if (git_str_putcn(out, '+', max(plus, 1)) < 0 ||
+ git_str_putcn(out, '-', max(minus, 1)) < 0)
goto on_error;
}
}
}
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
on_error:
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
static int diff_file_stats_number_to_buf(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta,
const diff_file_stats *filestats)
{
@@ -144,29 +146,29 @@ static int diff_file_stats_number_to_buf(
const char *path = delta->new_file.path;
if (delta->flags & GIT_DIFF_FLAG_BINARY)
- error = git_buf_printf(out, "%-8c" "%-8c" "%s\n", '-', '-', path);
+ error = git_str_printf(out, "%-8c" "%-8c" "%s\n", '-', '-', path);
else
- error = git_buf_printf(out, "%-8" PRIuZ "%-8" PRIuZ "%s\n",
+ error = git_str_printf(out, "%-8" PRIuZ "%-8" PRIuZ "%s\n",
filestats->insertions, filestats->deletions, path);
return error;
}
static int diff_file_stats_summary_to_buf(
- git_buf *out,
+ git_str *out,
const git_diff_delta *delta)
{
if (delta->old_file.mode != delta->new_file.mode) {
if (delta->old_file.mode == 0) {
- git_buf_printf(out, " create mode %06o %s\n",
+ git_str_printf(out, " create mode %06o %s\n",
delta->new_file.mode, delta->new_file.path);
}
else if (delta->new_file.mode == 0) {
- git_buf_printf(out, " delete mode %06o %s\n",
+ git_str_printf(out, " delete mode %06o %s\n",
delta->old_file.mode, delta->old_file.path);
}
else {
- git_buf_printf(out, " mode change %06o => %06o %s\n",
+ git_str_printf(out, " mode change %06o => %06o %s\n",
delta->old_file.mode, delta->new_file.mode, delta->new_file.path);
}
}
@@ -279,6 +281,15 @@ int git_diff_stats_to_buf(
git_diff_stats_format_t format,
size_t width)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_diff__stats_to_buf, stats, format, width);
+}
+
+int git_diff__stats_to_buf(
+ git_str *out,
+ const git_diff_stats *stats,
+ git_diff_stats_format_t format,
+ size_t width)
+{
int error = 0;
size_t i;
const git_diff_delta *delta;
@@ -320,23 +331,23 @@ int git_diff_stats_to_buf(
}
if (format & GIT_DIFF_STATS_FULL || format & GIT_DIFF_STATS_SHORT) {
- git_buf_printf(
+ git_str_printf(
out, " %" PRIuZ " file%s changed",
stats->files_changed, stats->files_changed != 1 ? "s" : "");
if (stats->insertions || stats->deletions == 0)
- git_buf_printf(
+ git_str_printf(
out, ", %" PRIuZ " insertion%s(+)",
stats->insertions, stats->insertions != 1 ? "s" : "");
if (stats->deletions || stats->insertions == 0)
- git_buf_printf(
+ git_str_printf(
out, ", %" PRIuZ " deletion%s(-)",
stats->deletions, stats->deletions != 1 ? "s" : "");
- git_buf_putc(out, '\n');
+ git_str_putc(out, '\n');
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
}
diff --git a/src/message.h b/src/diff_stats.h
index 251727b22..c71862b4e 100644
--- a/src/message.h
+++ b/src/diff_stats.h
@@ -4,14 +4,15 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
-#ifndef INCLUDE_message_h__
-#define INCLUDE_message_h__
+#ifndef INCLUDE_diff_stats_h__
+#define INCLUDE_diff_stats_h__
#include "common.h"
-#include "git2/message.h"
-#include "buffer.h"
-
-int git_message__prettify(git_buf *message_out, const char *message, int strip_comments);
+int git_diff__stats_to_buf(
+ git_str *out,
+ const git_diff_stats *stats,
+ git_diff_stats_format_t format,
+ size_t width);
#endif
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 597e64e45..be55de6c3 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -444,7 +444,7 @@ typedef struct {
git_iterator_t src;
git_repository *repo;
git_diff_file *file;
- git_buf data;
+ git_str data;
git_odb_object *odb_obj;
git_blob *blob;
} similarity_info;
@@ -458,7 +458,7 @@ static int similarity_init(
info->file = similarity_get_file(diff, file_idx);
info->odb_obj = NULL;
info->blob = NULL;
- git_buf_init(&info->data, 0);
+ git_str_init(&info->data, 0);
if (info->file->size > 0 || info->src == GIT_ITERATOR_WORKDIR)
return 0;
@@ -529,7 +529,7 @@ static void similarity_unload(similarity_info *info)
if (info->blob)
git_blob_free(info->blob);
else
- git_buf_dispose(&info->data);
+ git_str_dispose(&info->data);
}
#define FLAG_SET(opts,flag_name) (((opts)->flags & flag_name) != 0)
diff --git a/src/email.c b/src/email.c
index df63b6ec3..3459c0540 100644
--- a/src/email.c
+++ b/src/email.c
@@ -7,9 +7,11 @@
#include "email.h"
-#include "buffer.h"
#include "common.h"
+#include "buf.h"
#include "diff_generate.h"
+#include "diff_stats.h"
+#include "patch.h"
#include "git2/email.h"
#include "git2/patch.h"
@@ -32,7 +34,7 @@ GIT_INLINE(int) include_prefix(
}
static int append_prefix(
- git_buf *out,
+ git_str *out,
size_t patch_idx,
size_t patch_count,
git_email_create_options *opts)
@@ -40,16 +42,16 @@ static int append_prefix(
const char *subject_prefix = opts->subject_prefix ?
opts->subject_prefix : "PATCH";
- git_buf_putc(out, '[');
+ git_str_putc(out, '[');
if (*subject_prefix)
- git_buf_puts(out, subject_prefix);
+ git_str_puts(out, subject_prefix);
if (opts->reroll_number) {
if (*subject_prefix)
- git_buf_putc(out, ' ');
+ git_str_putc(out, ' ');
- git_buf_printf(out, "v%" PRIuZ, opts->reroll_number);
+ git_str_printf(out, "v%" PRIuZ, opts->reroll_number);
}
if ((opts->flags & GIT_EMAIL_CREATE_ALWAYS_NUMBER) != 0 ||
@@ -58,20 +60,20 @@ static int append_prefix(
opts->start_number : 1;
if (*subject_prefix || opts->reroll_number)
- git_buf_putc(out, ' ');
+ git_str_putc(out, ' ');
- git_buf_printf(out, "%" PRIuZ "/%" PRIuZ,
+ git_str_printf(out, "%" PRIuZ "/%" PRIuZ,
patch_idx + (start_number - 1),
patch_count + (start_number - 1));
}
- git_buf_puts(out, "]");
+ git_str_puts(out, "]");
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int append_subject(
- git_buf *out,
+ git_str *out,
size_t patch_idx,
size_t patch_count,
const char *summary,
@@ -88,25 +90,25 @@ static int append_subject(
summary_len = (nl - summary);
}
- if ((error = git_buf_puts(out, "Subject: ")) < 0)
+ if ((error = git_str_puts(out, "Subject: ")) < 0)
return error;
if (prefix &&
(error = append_prefix(out, patch_idx, patch_count, opts)) < 0)
return error;
- if (prefix && summary_len && (error = git_buf_putc(out, ' ')) < 0)
+ if (prefix && summary_len && (error = git_str_putc(out, ' ')) < 0)
return error;
if (summary_len &&
- (error = git_buf_put(out, summary, summary_len)) < 0)
+ (error = git_str_put(out, summary, summary_len)) < 0)
return error;
- return git_buf_putc(out, '\n');
+ return git_str_putc(out, '\n');
}
static int append_header(
- git_buf *out,
+ git_str *out,
size_t patch_idx,
size_t patch_count,
const git_oid *commit_id,
@@ -119,20 +121,20 @@ static int append_header(
int error;
if ((error = git_oid_fmt(id, commit_id)) < 0 ||
- (error = git_buf_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
- (error = git_buf_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
+ (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
+ (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
(error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
- (error = git_buf_printf(out, "Date: %s\n", date)) < 0 ||
+ (error = git_str_printf(out, "Date: %s\n", date)) < 0 ||
(error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
return error;
- if ((error = git_buf_putc(out, '\n')) < 0)
+ if ((error = git_str_putc(out, '\n')) < 0)
return error;
return 0;
}
-static int append_body(git_buf *out, const char *body)
+static int append_body(git_str *out, const char *body)
{
size_t body_len;
int error;
@@ -142,16 +144,16 @@ static int append_body(git_buf *out, const char *body)
body_len = strlen(body);
- if ((error = git_buf_puts(out, body)) < 0)
+ if ((error = git_str_puts(out, body)) < 0)
return error;
if (body_len && body[body_len - 1] != '\n')
- error = git_buf_putc(out, '\n');
+ error = git_str_putc(out, '\n');
return error;
}
-static int append_diffstat(git_buf *out, git_diff *diff)
+static int append_diffstat(git_str *out, git_diff *diff)
{
git_diff_stats *stats = NULL;
unsigned int format_flags;
@@ -160,14 +162,14 @@ static int append_diffstat(git_buf *out, git_diff *diff)
format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY;
if ((error = git_diff_get_stats(&stats, diff)) == 0 &&
- (error = git_diff_stats_to_buf(out, stats, format_flags, 0)) == 0)
- error = git_buf_putc(out, '\n');
+ (error = git_diff__stats_to_buf(out, stats, format_flags, 0)) == 0)
+ error = git_str_putc(out, '\n');
git_diff_stats_free(stats);
return error;
}
-static int append_patches(git_buf *out, git_diff *diff)
+static int append_patches(git_str *out, git_diff *diff)
{
size_t i, deltas;
int error = 0;
@@ -178,7 +180,7 @@ static int append_patches(git_buf *out, git_diff *diff)
git_patch *patch = NULL;
if ((error = git_patch_from_diff(&patch, diff, i)) >= 0)
- error = git_patch_to_buf(out, patch);
+ error = git_patch__to_buf(out, patch);
git_patch_free(patch);
@@ -190,7 +192,7 @@ static int append_patches(git_buf *out, git_diff *diff)
}
int git_email__append_from_diff(
- git_buf *out,
+ git_str *out,
git_diff *diff,
size_t patch_idx,
size_t patch_count,
@@ -216,14 +218,12 @@ int git_email__append_from_diff(
if (given_opts)
memcpy(&opts, given_opts, sizeof(git_email_create_options));
- git_buf_sanitize(out);
-
if ((error = append_header(out, patch_idx, patch_count, commit_id, summary, author, &opts)) == 0 &&
(error = append_body(out, body)) == 0 &&
- (error = git_buf_puts(out, "---\n")) == 0 &&
+ (error = git_str_puts(out, "---\n")) == 0 &&
(error = append_diffstat(out, diff)) == 0 &&
(error = append_patches(out, diff)) == 0)
- error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
+ error = git_str_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
return error;
}
@@ -239,15 +239,19 @@ int git_email_create_from_diff(
const git_signature *author,
const git_email_create_options *given_opts)
{
+ git_str email = GIT_STR_INIT;
int error;
- git_buf_sanitize(out);
- git_buf_clear(out);
+ git_buf_tostr(&email, out);
- error = git_email__append_from_diff(out, diff, patch_idx,
+ error = git_email__append_from_diff(&email, diff, patch_idx,
patch_count, commit_id, summary, body, author,
given_opts);
+ if (error == 0)
+ error = git_buf_fromstr(out, &email);
+
+ git_str_dispose(&email);
return error;
}
diff --git a/src/email.h b/src/email.h
index 7aeb462ab..083e56d5c 100644
--- a/src/email.h
+++ b/src/email.h
@@ -12,7 +12,7 @@
#include "git2/email.h"
extern int git_email__append_from_diff(
- git_buf *out,
+ git_str *out,
git_diff *diff,
size_t patch_idx,
size_t patch_count,
diff --git a/src/errors.c b/src/errors.c
index ce883b2da..3614b9ce5 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -9,7 +9,7 @@
#include "threadstate.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "libgit2.h"
/********************************************
@@ -29,7 +29,7 @@ static git_error g_git_uninitialized_error = {
static void set_error_from_buffer(int error_class)
{
git_error *error = &GIT_THREADSTATE->error_t;
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
error->message = buf->ptr;
error->klass = error_class;
@@ -39,11 +39,11 @@ static void set_error_from_buffer(int error_class)
static void set_error(int error_class, char *string)
{
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (string) {
- git_buf_puts(buf, string);
+ git_str_puts(buf, string);
git__free(string);
}
@@ -70,20 +70,20 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
#endif
int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (fmt) {
- git_buf_vprintf(buf, fmt, ap);
+ git_str_vprintf(buf, fmt, ap);
if (error_class == GIT_ERROR_OS)
- git_buf_PUTS(buf, ": ");
+ git_str_PUTS(buf, ": ");
}
if (error_class == GIT_ERROR_OS) {
#ifdef GIT_WIN32
char * win32_error = git_win32_get_error_message(win32_error_code);
if (win32_error) {
- git_buf_puts(buf, win32_error);
+ git_str_puts(buf, win32_error);
git__free(win32_error);
SetLastError(0);
@@ -91,26 +91,26 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
else
#endif
if (error_code)
- git_buf_puts(buf, strerror(error_code));
+ git_str_puts(buf, strerror(error_code));
if (error_code)
errno = 0;
}
- if (!git_buf_oom(buf))
+ if (!git_str_oom(buf))
set_error_from_buffer(error_class);
}
int git_error_set_str(int error_class, const char *string)
{
- git_buf *buf = &GIT_THREADSTATE->error_buf;
+ git_str *buf = &GIT_THREADSTATE->error_buf;
GIT_ASSERT_ARG(string);
- git_buf_clear(buf);
- git_buf_puts(buf, string);
+ git_str_clear(buf);
+ git_str_puts(buf, string);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
return -1;
set_error_from_buffer(error_class);
@@ -142,7 +142,7 @@ const git_error *git_error_last(void)
int git_error_state_capture(git_error_state *state, int error_code)
{
git_error *error = GIT_THREADSTATE->last_error;
- git_buf *error_buf = &GIT_THREADSTATE->error_buf;
+ git_str *error_buf = &GIT_THREADSTATE->error_buf;
memset(state, 0, sizeof(git_error_state));
@@ -158,7 +158,7 @@ int git_error_state_capture(git_error_state *state, int error_code)
if (state->oom)
state->error_msg.message = g_git_oom_error.message;
else
- state->error_msg.message = git_buf_detach(error_buf);
+ state->error_msg.message = git_str_detach(error_buf);
}
git_error_clear();
diff --git a/src/fetchhead.c b/src/fetchhead.c
index 88c567e48..6511124ef 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -10,7 +10,7 @@
#include "git2/types.h"
#include "git2/oid.h"
-#include "buffer.h"
+#include "str.h"
#include "futils.h"
#include "filebuf.h"
#include "refs.h"
@@ -44,7 +44,7 @@ static char *sanitized_remote_url(const char *remote_url)
int error;
if (git_net_url_parse(&url, remote_url) == 0) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git__free(url.username);
git__free(url.password);
@@ -53,7 +53,7 @@ static char *sanitized_remote_url(const char *remote_url)
if ((error = git_net_url_fmt(&buf, &url)) < 0)
goto fallback;
- sanitized = git_buf_detach(&buf);
+ sanitized = git_str_detach(&buf);
}
fallback:
@@ -143,22 +143,22 @@ static int fetchhead_ref_write(
int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned int i;
git_fetchhead_ref *fetchhead_ref;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(fetchhead_refs);
- if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_APPEND, GIT_REFS_FILE_MODE) < 0) {
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return -1;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_vector_sort(fetchhead_refs);
@@ -171,7 +171,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
static int fetchhead_ref_parse(
git_oid *oid,
unsigned int *is_merge,
- git_buf *ref_name,
+ git_str *ref_name,
const char **remote_url,
char *line,
size_t line_num)
@@ -259,12 +259,12 @@ static int fetchhead_ref_parse(
*remote_url = desc;
}
- git_buf_clear(ref_name);
+ git_str_clear(ref_name);
if (type)
- git_buf_join(ref_name, '/', type, name);
+ git_str_join(ref_name, '/', type, name);
else if(name)
- git_buf_puts(ref_name, name);
+ git_str_puts(ref_name, name);
return error;
}
@@ -273,7 +273,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
git_repository_fetchhead_foreach_cb cb,
void *payload)
{
- git_buf path = GIT_BUF_INIT, file = GIT_BUF_INIT, name = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, file = GIT_STR_INIT, name = GIT_STR_INIT;
const char *ref_name;
git_oid oid;
const char *remote_url;
@@ -285,10 +285,10 @@ int git_repository_fetchhead_foreach(git_repository *repo,
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(cb);
- if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
- if ((error = git_futils_readbuffer(&file, git_buf_cstr(&path))) < 0)
+ if ((error = git_futils_readbuffer(&file, git_str_cstr(&path))) < 0)
goto done;
buffer = file.ptr;
@@ -300,8 +300,8 @@ int git_repository_fetchhead_foreach(git_repository *repo,
&oid, &is_merge, &name, &remote_url, line, line_num)) < 0)
goto done;
- if (git_buf_len(&name) > 0)
- ref_name = git_buf_cstr(&name);
+ if (git_str_len(&name) > 0)
+ ref_name = git_str_cstr(&name);
else
ref_name = NULL;
@@ -319,9 +319,9 @@ int git_repository_fetchhead_foreach(git_repository *repo,
}
done:
- git_buf_dispose(&file);
- git_buf_dispose(&path);
- git_buf_dispose(&name);
+ git_str_dispose(&file);
+ git_str_dispose(&path);
+ git_str_dispose(&name);
return error;
}
diff --git a/src/filebuf.c b/src/filebuf.c
index 4296b2226..10f8c5813 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -195,21 +195,21 @@ static int write_deflate(git_filebuf *file, void *source, size_t len)
#define MAX_SYMLINK_DEPTH 5
-static int resolve_symlink(git_buf *out, const char *path)
+static int resolve_symlink(git_str *out, const char *path)
{
int i, error, root;
ssize_t ret;
struct stat st;
- git_buf curpath = GIT_BUF_INIT, target = GIT_BUF_INIT;
+ git_str curpath = GIT_STR_INIT, target = GIT_STR_INIT;
- if ((error = git_buf_grow(&target, GIT_PATH_MAX + 1)) < 0 ||
- (error = git_buf_puts(&curpath, path)) < 0)
+ if ((error = git_str_grow(&target, GIT_PATH_MAX + 1)) < 0 ||
+ (error = git_str_puts(&curpath, path)) < 0)
return error;
for (i = 0; i < MAX_SYMLINK_DEPTH; i++) {
error = p_lstat(curpath.ptr, &st);
if (error < 0 && errno == ENOENT) {
- error = git_buf_puts(out, curpath.ptr);
+ error = git_str_puts(out, curpath.ptr);
goto cleanup;
}
@@ -220,7 +220,7 @@ static int resolve_symlink(git_buf *out, const char *path)
}
if (!S_ISLNK(st.st_mode)) {
- error = git_buf_puts(out, curpath.ptr);
+ error = git_str_puts(out, curpath.ptr);
goto cleanup;
}
@@ -243,16 +243,16 @@ static int resolve_symlink(git_buf *out, const char *path)
root = git_path_root(target.ptr);
if (root >= 0) {
- if ((error = git_buf_sets(&curpath, target.ptr)) < 0)
+ if ((error = git_str_sets(&curpath, target.ptr)) < 0)
goto cleanup;
} else {
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
if ((error = git_path_dirname_r(&dir, curpath.ptr)) < 0)
goto cleanup;
- git_buf_swap(&curpath, &dir);
- git_buf_dispose(&dir);
+ git_str_swap(&curpath, &dir);
+ git_str_dispose(&dir);
if ((error = git_path_apply_relative(&curpath, target.ptr)) < 0)
goto cleanup;
@@ -263,8 +263,8 @@ static int resolve_symlink(git_buf *out, const char *path)
error = -1;
cleanup:
- git_buf_dispose(&curpath);
- git_buf_dispose(&target);
+ git_str_dispose(&curpath);
+ git_str_dispose(&target);
return error;
}
@@ -332,13 +332,13 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
/* If we are writing to a temp file */
if (flags & GIT_FILEBUF_TEMPORARY) {
- git_buf tmp_path = GIT_BUF_INIT;
+ git_str tmp_path = GIT_STR_INIT;
/* Open the file as temporary for locking */
file->fd = git_futils_mktmp(&tmp_path, path, mode);
if (file->fd < 0) {
- git_buf_dispose(&tmp_path);
+ git_str_dispose(&tmp_path);
goto cleanup;
}
file->fd_is_open = true;
@@ -346,17 +346,17 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
/* No original path */
file->path_original = NULL;
- file->path_lock = git_buf_detach(&tmp_path);
+ file->path_lock = git_str_detach(&tmp_path);
GIT_ERROR_CHECK_ALLOC(file->path_lock);
} else {
- git_buf resolved_path = GIT_BUF_INIT;
+ git_str resolved_path = GIT_STR_INIT;
if ((error = resolve_symlink(&resolved_path, path)) < 0)
goto cleanup;
/* Save the original path of the file */
path_len = resolved_path.size;
- file->path_original = git_buf_detach(&resolved_path);
+ file->path_original = git_str_detach(&resolved_path);
/* create the locking path by appending ".lock" to the original */
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, path_len, GIT_FILELOCK_EXTLENGTH);
diff --git a/src/filter.c b/src/filter.c
index 73497cb30..417d9cb8b 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -7,6 +7,7 @@
#include "filter.h"
+#include "buf.h"
#include "common.h"
#include "futils.h"
#include "hash.h"
@@ -36,7 +37,7 @@ typedef struct {
struct git_filter_list {
git_array_t(git_filter_entry) filters;
git_filter_source source;
- git_buf *temp_buf;
+ git_str *temp_buf;
char path[GIT_FLEX_ARRAY];
};
@@ -68,7 +69,7 @@ static void git_filter_global_shutdown(void);
static int filter_def_scan_attrs(
- git_buf *attrs, size_t *nattr, size_t *nmatch, const char *attr_str)
+ git_str *attrs, size_t *nattr, size_t *nmatch, const char *attr_str)
{
const char *start, *scan = attr_str;
int has_eq;
@@ -92,9 +93,9 @@ static int filter_def_scan_attrs(
(*nmatch)++;
if (has_eq)
- git_buf_putc(attrs, '=');
- git_buf_put(attrs, start, scan - start);
- git_buf_putc(attrs, '\0');
+ git_str_putc(attrs, '=');
+ git_str_put(attrs, start, scan - start);
+ git_str_putc(attrs, '\0');
}
}
@@ -152,7 +153,7 @@ static int filter_registry_insert(
{
git_filter_def *fdef;
size_t nattr = 0, nmatch = 0, alloc_len;
- git_buf attrs = GIT_BUF_INIT;
+ git_str attrs = GIT_STR_INIT;
if (filter_def_scan_attrs(&attrs, &nattr, &nmatch, filter->attributes) < 0)
return -1;
@@ -171,7 +172,7 @@ static int filter_registry_insert(
fdef->priority = priority;
fdef->nattrs = nattr;
fdef->nmatches = nmatch;
- fdef->attrdata = git_buf_detach(&attrs);
+ fdef->attrdata = git_str_detach(&attrs);
filter_def_set_attrs(fdef);
@@ -710,7 +711,7 @@ size_t git_filter_list_length(const git_filter_list *fl)
struct buf_stream {
git_writestream parent;
- git_buf *target;
+ git_str *target;
bool complete;
};
@@ -721,7 +722,7 @@ static int buf_stream_write(
GIT_ASSERT_ARG(buf_stream);
GIT_ASSERT(buf_stream->complete == 0);
- return git_buf_put(buf_stream->target, buffer, len);
+ return git_str_put(buf_stream->target, buffer, len);
}
static int buf_stream_close(git_writestream *s)
@@ -740,7 +741,7 @@ static void buf_stream_free(git_writestream *s)
GIT_UNUSED(s);
}
-static void buf_stream_init(struct buf_stream *writer, git_buf *target)
+static void buf_stream_init(struct buf_stream *writer, git_str *target)
{
memset(writer, 0, sizeof(struct buf_stream));
@@ -749,7 +750,7 @@ static void buf_stream_init(struct buf_stream *writer, git_buf *target)
writer->parent.free = buf_stream_free;
writer->target = target;
- git_buf_clear(target);
+ git_str_clear(target);
}
int git_filter_list_apply_to_buffer(
@@ -758,12 +759,18 @@ int git_filter_list_apply_to_buffer(
const char *in,
size_t in_len)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_buffer, filters, in, in_len);
+}
+
+int git_filter_list__apply_to_buffer(
+ git_str *out,
+ git_filter_list *filters,
+ const char *in,
+ size_t in_len)
+{
struct buf_stream writer;
int error;
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
buf_stream_init(&writer, out);
if ((error = git_filter_list_stream_buffer(filters,
@@ -775,23 +782,23 @@ int git_filter_list_apply_to_buffer(
}
int git_filter_list__convert_buf(
- git_buf *out,
+ git_str *out,
git_filter_list *filters,
- git_buf *in)
+ git_str *in)
{
int error;
if (!filters || git_filter_list_length(filters) == 0) {
- git_buf_swap(out, in);
- git_buf_dispose(in);
+ git_str_swap(out, in);
+ git_str_dispose(in);
return 0;
}
- error = git_filter_list_apply_to_buffer(out, filters,
+ error = git_filter_list__apply_to_buffer(out, filters,
in->ptr, in->size);
if (!error)
- git_buf_dispose(in);
+ git_str_dispose(in);
return error;
}
@@ -802,6 +809,15 @@ int git_filter_list_apply_to_file(
git_repository *repo,
const char *path)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_file, filters, repo, path);
+}
+
+int git_filter_list__apply_to_file(
+ git_str *out,
+ git_filter_list *filters,
+ git_repository *repo,
+ const char *path)
+{
struct buf_stream writer;
int error;
@@ -815,7 +831,7 @@ int git_filter_list_apply_to_file(
return error;
}
-static int buf_from_blob(git_buf *out, git_blob *blob)
+static int buf_from_blob(git_str *out, git_blob *blob)
{
git_object_size_t rawsize = git_blob_rawsize(blob);
@@ -824,7 +840,7 @@ static int buf_from_blob(git_buf *out, git_blob *blob)
return -1;
}
- git_buf_attach_notowned(out, git_blob_rawcontent(blob), (size_t)rawsize);
+ git_str_attach_notowned(out, git_blob_rawcontent(blob), (size_t)rawsize);
return 0;
}
@@ -833,6 +849,14 @@ int git_filter_list_apply_to_blob(
git_filter_list *filters,
git_blob *blob)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_filter_list__apply_to_blob, filters, blob);
+}
+
+int git_filter_list__apply_to_blob(
+ git_str *out,
+ git_filter_list *filters,
+ git_blob *blob)
+{
struct buf_stream writer;
int error;
@@ -849,12 +873,13 @@ int git_filter_list_apply_to_blob(
struct buffered_stream {
git_writestream parent;
git_filter *filter;
- int (*write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *);
+ int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *);
+ int (*legacy_write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *);
const git_filter_source *source;
void **payload;
- git_buf input;
- git_buf temp_buf;
- git_buf *output;
+ git_str input;
+ git_str temp_buf;
+ git_str *output;
git_writestream *target;
};
@@ -864,13 +889,13 @@ static int buffered_stream_write(
struct buffered_stream *buffered_stream = (struct buffered_stream *)s;
GIT_ASSERT_ARG(buffered_stream);
- return git_buf_put(&buffered_stream->input, buffer, len);
+ return git_str_put(&buffered_stream->input, buffer, len);
}
static int buffered_stream_close(git_writestream *s)
{
struct buffered_stream *buffered_stream = (struct buffered_stream *)s;
- git_buf *writebuf;
+ git_str *writebuf;
git_error_state error_state = {0};
int error;
@@ -886,9 +911,6 @@ static int buffered_stream_close(git_writestream *s)
if (error == GIT_PASSTHROUGH) {
writebuf = &buffered_stream->input;
} else if (error == 0) {
- if ((error = git_buf_sanitize(buffered_stream->output)) < 0)
- return error;
-
writebuf = buffered_stream->output;
} else {
/* close stream before erroring out taking care
@@ -911,8 +933,8 @@ static void buffered_stream_free(git_writestream *s)
struct buffered_stream *buffered_stream = (struct buffered_stream *)s;
if (buffered_stream) {
- git_buf_dispose(&buffered_stream->input);
- git_buf_dispose(&buffered_stream->temp_buf);
+ git_str_dispose(&buffered_stream->input);
+ git_str_dispose(&buffered_stream->temp_buf);
git__free(buffered_stream);
}
}
@@ -920,8 +942,8 @@ static void buffered_stream_free(git_writestream *s)
int git_filter_buffered_stream_new(
git_writestream **out,
git_filter *filter,
- int (*write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *),
- git_buf *temp_buf,
+ int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *),
+ git_str *temp_buf,
void **payload,
const git_filter_source *source,
git_writestream *target)
@@ -940,12 +962,43 @@ int git_filter_buffered_stream_new(
buffered_stream->target = target;
if (temp_buf)
- git_buf_clear(temp_buf);
+ git_str_clear(temp_buf);
*out = (git_writestream *)buffered_stream;
return 0;
}
+#ifndef GIT_DEPRECATE_HARD
+static int buffered_legacy_stream_new(
+ git_writestream **out,
+ git_filter *filter,
+ int (*legacy_write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *),
+ git_str *temp_buf,
+ void **payload,
+ const git_filter_source *source,
+ git_writestream *target)
+{
+ struct buffered_stream *buffered_stream = git__calloc(1, sizeof(struct buffered_stream));
+ GIT_ERROR_CHECK_ALLOC(buffered_stream);
+
+ buffered_stream->parent.write = buffered_stream_write;
+ buffered_stream->parent.close = buffered_stream_close;
+ buffered_stream->parent.free = buffered_stream_free;
+ buffered_stream->filter = filter;
+ buffered_stream->legacy_write_fn = legacy_write_fn;
+ buffered_stream->output = temp_buf ? temp_buf : &buffered_stream->temp_buf;
+ buffered_stream->payload = payload;
+ buffered_stream->source = source;
+ buffered_stream->target = target;
+
+ if (temp_buf)
+ git_str_clear(temp_buf);
+
+ *out = (git_writestream *)buffered_stream;
+ return 0;
+}
+#endif
+
static int setup_stream(
git_writestream **out,
git_filter_entry *fe,
@@ -961,7 +1014,7 @@ static int setup_stream(
*/
if (!fe->filter->stream) {
/* Create a stream that proxies the one-shot apply */
- return git_filter_buffered_stream_new(out,
+ return buffered_legacy_stream_new(out,
fe->filter, fe->filter->apply, filters->temp_buf,
&fe->payload, &filters->source, last_stream);
}
@@ -1032,7 +1085,7 @@ int git_filter_list_stream_file(
git_writestream *target)
{
char buf[FILTERIO_BUFSIZE];
- git_buf abspath = GIT_BUF_INIT;
+ git_str abspath = GIT_STR_INIT;
const char *base = repo ? git_repository_workdir(repo) : NULL;
git_vector filter_streams = GIT_VECTOR_INIT;
git_writestream *stream_start;
@@ -1067,7 +1120,7 @@ done:
if (fd >= 0)
p_close(fd);
filter_streams_free(&filter_streams);
- git_buf_dispose(&abspath);
+ git_str_dispose(&abspath);
return error;
}
@@ -1101,7 +1154,7 @@ int git_filter_list_stream_blob(
git_blob *blob,
git_writestream *target)
{
- git_buf in = GIT_BUF_INIT;
+ git_str in = GIT_STR_INIT;
if (buf_from_blob(&in, blob) < 0)
return -1;
@@ -1125,22 +1178,12 @@ int git_filter_list_stream_data(
git_buf *data,
git_writestream *target)
{
- int error;
-
- if ((error = git_buf_sanitize(data)) < 0)
- return error;
-
return git_filter_list_stream_buffer(filters, data->ptr, data->size, target);
}
int git_filter_list_apply_to_data(
git_buf *tgt, git_filter_list *filters, git_buf *src)
{
- int error;
-
- if ((error = git_buf_sanitize(src)) < 0)
- return error;
-
return git_filter_list_apply_to_buffer(tgt, filters, src->ptr, src->size);
}
diff --git a/src/filter.h b/src/filter.h
index 241791276..58cb4b424 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -19,7 +19,7 @@
typedef struct {
git_filter_options options;
git_attr_session *attr_session;
- git_buf *temp_buf;
+ git_str *temp_buf;
} git_filter_session;
#define GIT_FILTER_SESSION_INIT {GIT_FILTER_OPTIONS_INIT, 0}
@@ -36,14 +36,35 @@ extern int git_filter_list__load(
git_filter_mode_t mode,
git_filter_session *filter_session);
+int git_filter_list__apply_to_buffer(
+ git_str *out,
+ git_filter_list *filters,
+ const char *in,
+ size_t in_len);
+int git_filter_list__apply_to_file(
+ git_str *out,
+ git_filter_list *filters,
+ git_repository *repo,
+ const char *path);
+int git_filter_list__apply_to_blob(
+ git_str *out,
+ git_filter_list *filters,
+ git_blob *blob);
+
/*
* The given input buffer will be converted to the given output buffer.
* The input buffer will be freed (_if_ it was allocated).
*/
extern int git_filter_list__convert_buf(
- git_buf *out,
+ git_str *out,
+ git_filter_list *filters,
+ git_str *in);
+
+extern int git_filter_list__apply_to_file(
+ git_str *out,
git_filter_list *filters,
- git_buf *in);
+ git_repository *repo,
+ const char *path);
/*
* Available filters
@@ -55,8 +76,8 @@ extern git_filter *git_ident_filter_new(void);
extern int git_filter_buffered_stream_new(
git_writestream **out,
git_filter *filter,
- int (*write_fn)(git_filter *, void **, git_buf *, const git_buf *, const git_filter_source *),
- git_buf *temp_buf,
+ int (*write_fn)(git_filter *, void **, git_str *, const git_str *, const git_filter_source *),
+ git_str *temp_buf,
void **payload,
const git_filter_source *source,
git_writestream *target);
diff --git a/src/futils.c b/src/futils.c
index d28b231ce..9a15ceeb9 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -22,17 +22,17 @@ int git_futils_mkpath2file(const char *file_path, const mode_t mode)
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
}
-int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
+int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode)
{
int fd;
mode_t mask;
p_umask(mask = p_umask(0));
- git_buf_sets(path_out, filename);
- git_buf_puts(path_out, "_git2_XXXXXX");
+ git_str_sets(path_out, filename);
+ git_str_puts(path_out, "_git2_XXXXXX");
- if (git_buf_oom(path_out))
+ if (git_str_oom(path_out))
return -1;
if ((fd = p_mkstemp(path_out->ptr)) < 0) {
@@ -145,12 +145,12 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
return 0;
}
-int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
+int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len)
{
ssize_t read_size = 0;
size_t alloc_len;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (!git__is_ssizet(len)) {
git_error_set(GIT_ERROR_INVALID, "read too large");
@@ -158,7 +158,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
}
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
- if (git_buf_grow(buf, alloc_len) < 0)
+ if (git_str_grow(buf, alloc_len) < 0)
return -1;
/* p_read loops internally to read len bytes */
@@ -166,7 +166,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
if (read_size != (ssize_t)len) {
git_error_set(GIT_ERROR_OS, "failed to read descriptor");
- git_buf_dispose(buf);
+ git_str_dispose(buf);
return -1;
}
@@ -177,7 +177,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
}
int git_futils_readbuffer_updated(
- git_buf *out,
+ git_str *out,
const char *path,
unsigned char checksum[GIT_HASH_SHA1_SIZE],
int *updated)
@@ -185,7 +185,7 @@ int git_futils_readbuffer_updated(
int error;
git_file fd;
struct stat st;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
unsigned char checksum_new[GIT_HASH_SHA1_SIZE];
GIT_ASSERT_ARG(out);
@@ -220,7 +220,7 @@ int git_futils_readbuffer_updated(
if (checksum) {
if ((error = git_hash_buf(checksum_new, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -228,7 +228,7 @@ int git_futils_readbuffer_updated(
* If we were given a checksum, we only want to use it if it's different
*/
if (!memcmp(checksum, checksum_new, GIT_HASH_SHA1_SIZE)) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (updated)
*updated = 0;
@@ -244,19 +244,19 @@ int git_futils_readbuffer_updated(
if (updated != NULL)
*updated = 1;
- git_buf_swap(out, &buf);
- git_buf_dispose(&buf);
+ git_str_swap(out, &buf);
+ git_str_dispose(&buf);
return 0;
}
-int git_futils_readbuffer(git_buf *buf, const char *path)
+int git_futils_readbuffer(git_str *buf, const char *path)
{
return git_futils_readbuffer_updated(buf, path, NULL, NULL);
}
int git_futils_writebuffer(
- const git_buf *buf, const char *path, int flags, mode_t mode)
+ const git_str *buf, const char *path, int flags, mode_t mode)
{
int fd, do_fsync = 0, error = 0;
@@ -276,7 +276,7 @@ int git_futils_writebuffer(
return fd;
}
- if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
+ if ((error = p_write(fd, git_str_cstr(buf), git_str_len(buf))) < 0) {
git_error_set(GIT_ERROR_OS, "could not write to '%s'", path);
(void)p_close(fd);
return error;
@@ -418,7 +418,7 @@ GIT_INLINE(int) mkdir_validate_mode(
}
GIT_INLINE(int) mkdir_canonicalize(
- git_buf *path,
+ git_str *path,
uint32_t flags)
{
ssize_t root_len;
@@ -450,7 +450,7 @@ GIT_INLINE(int) mkdir_canonicalize(
* the root), we don't have anything to do.
*/
if (path->size <= (size_t)root_len)
- git_buf_clear(path);
+ git_str_clear(path);
return 0;
}
@@ -460,16 +460,16 @@ int git_futils_mkdir(
mode_t mode,
uint32_t flags)
{
- git_buf make_path = GIT_BUF_INIT, parent_path = GIT_BUF_INIT;
+ git_str make_path = GIT_STR_INIT, parent_path = GIT_STR_INIT;
const char *relative;
struct git_futils_mkdir_options opts = { 0 };
struct stat st;
size_t depth = 0;
int len = 0, root_len, error;
- if ((error = git_buf_puts(&make_path, path)) < 0 ||
+ if ((error = git_str_puts(&make_path, path)) < 0 ||
(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
- (error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
+ (error = git_str_puts(&parent_path, make_path.ptr)) < 0 ||
make_path.size == 0)
goto done;
@@ -541,8 +541,8 @@ int git_futils_mkdir(
parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
done:
- git_buf_dispose(&make_path);
- git_buf_dispose(&parent_path);
+ git_str_dispose(&make_path);
+ git_str_dispose(&parent_path);
return error;
}
@@ -558,7 +558,7 @@ int git_futils_mkdir_relative(
uint32_t flags,
struct git_futils_mkdir_options *opts)
{
- git_buf make_path = GIT_BUF_INIT;
+ git_str make_path = GIT_STR_INIT;
ssize_t root = 0, min_root_len;
char lastch = '/', *tail;
struct stat st;
@@ -578,7 +578,7 @@ int git_futils_mkdir_relative(
/* if we are not supposed to make the whole path, reset root */
if ((flags & GIT_MKDIR_PATH) == 0)
- root = git_buf_rfind(&make_path, '/');
+ root = git_str_rfind(&make_path, '/');
/* advance root past drive name or network mount prefix */
min_root_len = git_path_root(make_path.ptr);
@@ -673,7 +673,7 @@ retry_lstat:
}
done:
- git_buf_dispose(&make_path);
+ git_str_dispose(&make_path);
return error;
}
@@ -697,13 +697,13 @@ static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
return -1;
}
-static int futils__rm_first_parent(git_buf *path, const char *ceiling)
+static int futils__rm_first_parent(git_str *path, const char *ceiling)
{
int error = GIT_ENOTFOUND;
struct stat st;
while (error == GIT_ENOTFOUND) {
- git_buf_rtruncate_at_char(path, '/');
+ git_str_rtruncate_at_char(path, '/');
if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
error = 0;
@@ -722,7 +722,7 @@ static int futils__rm_first_parent(git_buf *path, const char *ceiling)
return error;
}
-static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
+static int futils__rmdir_recurs_foreach(void *opaque, git_str *path)
{
int error = 0;
futils__rmdir_data *data = opaque;
@@ -810,7 +810,7 @@ int git_futils_rmdir_r(
const char *path, const char *base, uint32_t flags)
{
int error;
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
futils__rmdir_data data;
/* build path and find "root" where we should start calling mkdir */
@@ -834,7 +834,7 @@ int git_futils_rmdir_r(
error = 0;
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return error;
}
@@ -938,7 +938,7 @@ static int cp_link(const char *from, const char *to, size_t link_size)
typedef struct {
const char *to_root;
- git_buf to;
+ git_str to;
ssize_t from_prefix;
uint32_t flags;
uint32_t mkdir_flags;
@@ -947,7 +947,7 @@ typedef struct {
#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10)
-static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
+static int _cp_r_mkdir(cp_r_info *info, git_str *from)
{
int error = 0;
@@ -969,7 +969,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
return error;
}
-static int _cp_r_callback(void *ref, git_buf *from)
+static int _cp_r_callback(void *ref, git_str *from)
{
int error = 0;
cp_r_info *info = ref;
@@ -980,7 +980,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
from->ptr[git_path_basename_offset(from)] == '.')
return 0;
- if ((error = git_buf_joinpath(
+ if ((error = git_str_joinpath(
&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
return error;
@@ -1064,10 +1064,10 @@ int git_futils_cp_r(
mode_t dirmode)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cp_r_info info;
- if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
+ if (git_str_joinpath(&path, from, "") < 0) /* ensure trailing slash */
return -1;
memset(&info, 0, sizeof(info));
@@ -1075,7 +1075,7 @@ int git_futils_cp_r(
info.flags = flags;
info.dirmode = dirmode;
info.from_prefix = path.size;
- git_buf_init(&info.to, 0);
+ git_str_init(&info.to, 0);
/* precalculate mkdir flags */
if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) {
@@ -1093,8 +1093,8 @@ int git_futils_cp_r(
error = _cp_r_callback(&info, &path);
- git_buf_dispose(&path);
- git_buf_dispose(&info.to);
+ git_str_dispose(&path);
+ git_str_dispose(&info.to);
return error;
}
diff --git a/src/futils.h b/src/futils.h
index 373cc3042..eea69adde 100644
--- a/src/futils.h
+++ b/src/futils.h
@@ -21,13 +21,13 @@
*
* Read whole files into an in-memory buffer for processing
*/
-extern int git_futils_readbuffer(git_buf *obj, const char *path);
+extern int git_futils_readbuffer(git_str *obj, const char *path);
extern int git_futils_readbuffer_updated(
- git_buf *obj,
+ git_str *obj,
const char *path,
unsigned char checksum[GIT_HASH_SHA1_SIZE],
int *updated);
-extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
+extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len);
/* Additional constants for `git_futils_writebuffer`'s `open_flags`. We
* support these internally and they will be removed before the `open` call.
@@ -37,7 +37,7 @@ extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
#endif
extern int git_futils_writebuffer(
- const git_buf *buf, const char *path, int open_flags, mode_t mode);
+ const git_str *buf, const char *path, int open_flags, mode_t mode);
/**
* File utils
@@ -177,7 +177,7 @@ extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags
* Writes the filename into path_out.
* @return On success, an open file descriptor, else an error code < 0.
*/
-extern int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode);
+extern int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode);
/**
* Move a file on the filesystem, create the
diff --git a/src/hash.c b/src/hash.c
index 222eadf40..92e7ff219 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -101,7 +101,7 @@ int git_hash_buf(
int git_hash_vec(
unsigned char *out,
- git_buf_vec *vec,
+ git_str_vec *vec,
size_t n,
git_hash_algorithm_t algorithm)
{
diff --git a/src/hash.h b/src/hash.h
index ec91fa43a..10b14a904 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -16,7 +16,7 @@
typedef struct {
void *data;
size_t len;
-} git_buf_vec;
+} git_str_vec;
typedef enum {
GIT_HASH_ALGORITHM_NONE = 0,
@@ -40,6 +40,6 @@ int git_hash_update(git_hash_ctx *c, const void *data, size_t len);
int git_hash_final(unsigned char *out, git_hash_ctx *c);
int git_hash_buf(unsigned char *out, const void *data, size_t len, git_hash_algorithm_t algorithm);
-int git_hash_vec(unsigned char *out, git_buf_vec *vec, size_t n, git_hash_algorithm_t algorithm);
+int git_hash_vec(unsigned char *out, git_str_vec *vec, size_t n, git_hash_algorithm_t algorithm);
#endif
diff --git a/src/ident.c b/src/ident.c
index e5aab80ed..53095864e 100644
--- a/src/ident.c
+++ b/src/ident.c
@@ -9,7 +9,7 @@
#include "git2/sys/filter.h"
#include "filter.h"
-#include "buffer.h"
+#include "str.h"
static int ident_find_id(
const char **id_start, const char **id_end, const char *start, size_t len)
@@ -40,7 +40,7 @@ static int ident_find_id(
}
static int ident_insert_id(
- git_buf *to, const git_buf *from, const git_filter_source *src)
+ git_str *to, const git_str *from, const git_filter_source *src)
{
char oid[GIT_OID_HEXSZ+1];
const char *id_start, *id_end, *from_end = from->ptr + from->size;
@@ -60,20 +60,20 @@ static int ident_insert_id(
5 /* "$Id: " */ + GIT_OID_HEXSZ + 2 /* " $" */ +
(size_t)(from_end - id_end);
- if (git_buf_grow(to, need_size) < 0)
+ if (git_str_grow(to, need_size) < 0)
return -1;
- git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
- git_buf_put(to, "$Id: ", 5);
- git_buf_put(to, oid, GIT_OID_HEXSZ);
- git_buf_put(to, " $", 2);
- git_buf_put(to, id_end, (size_t)(from_end - id_end));
+ git_str_set(to, from->ptr, (size_t)(id_start - from->ptr));
+ git_str_put(to, "$Id: ", 5);
+ git_str_put(to, oid, GIT_OID_HEXSZ);
+ git_str_put(to, " $", 2);
+ git_str_put(to, id_end, (size_t)(from_end - id_end));
- return git_buf_oom(to) ? -1 : 0;
+ return git_str_oom(to) ? -1 : 0;
}
static int ident_remove_id(
- git_buf *to, const git_buf *from)
+ git_str *to, const git_str *from)
{
const char *id_start, *id_end, *from_end = from->ptr + from->size;
size_t need_size;
@@ -84,27 +84,27 @@ static int ident_remove_id(
need_size = (size_t)(id_start - from->ptr) +
4 /* "$Id$" */ + (size_t)(from_end - id_end);
- if (git_buf_grow(to, need_size) < 0)
+ if (git_str_grow(to, need_size) < 0)
return -1;
- git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
- git_buf_put(to, "$Id$", 4);
- git_buf_put(to, id_end, (size_t)(from_end - id_end));
+ git_str_set(to, from->ptr, (size_t)(id_start - from->ptr));
+ git_str_put(to, "$Id$", 4);
+ git_str_put(to, id_end, (size_t)(from_end - id_end));
- return git_buf_oom(to) ? -1 : 0;
+ return git_str_oom(to) ? -1 : 0;
}
static int ident_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *src)
{
GIT_UNUSED(self); GIT_UNUSED(payload);
/* Don't filter binary files */
- if (git_buf_is_binary(from))
+ if (git_str_is_binary(from))
return GIT_PASSTHROUGH;
if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
diff --git a/src/ignore.c b/src/ignore.c
index 9ead96ba6..eb9fd8a9e 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -105,7 +105,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
size_t i;
git_attr_fnmatch *rule;
char *path;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
*out = 0;
@@ -115,12 +115,12 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
/* path of the file relative to the workdir, so we match the rules in subdirs */
if (match->containing_dir) {
- git_buf_puts(&buf, match->containing_dir);
+ git_str_puts(&buf, match->containing_dir);
}
- if (git_buf_puts(&buf, match->pattern) < 0)
+ if (git_str_puts(&buf, match->pattern) < 0)
return -1;
- path = git_buf_detach(&buf);
+ path = git_str_detach(&buf);
git_vector_foreach(rules, i, rule) {
if (!(rule->flags & GIT_ATTR_FNMATCH_HASWILD)) {
@@ -133,12 +133,12 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
continue;
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
if (rule->containing_dir)
- git_buf_puts(&buf, rule->containing_dir);
- git_buf_puts(&buf, rule->pattern);
+ git_str_puts(&buf, rule->containing_dir);
+ git_str_puts(&buf, rule->pattern);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
goto out;
/*
@@ -151,7 +151,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
effective_flags &= ~WM_PATHNAME;
/* if we found a match, we want to keep this rule */
- if ((wildmatch(git_buf_cstr(&buf), path, effective_flags)) == WM_MATCH) {
+ if ((wildmatch(git_str_cstr(&buf), path, effective_flags)) == WM_MATCH) {
*out = 1;
error = 0;
goto out;
@@ -162,7 +162,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
out:
git__free(path);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -295,7 +295,7 @@ int git_ignore__for_path(
{
int error = 0;
const char *workdir = git_repository_workdir(repo);
- git_buf infopath = GIT_BUF_INIT;
+ git_str infopath = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(ignores);
@@ -314,19 +314,19 @@ int git_ignore__for_path(
/* given a unrooted path in a non-bare repo, resolve it */
if (workdir && git_path_root(path) < 0) {
- git_buf local = GIT_BUF_INIT;
+ git_str local = GIT_STR_INIT;
if ((error = git_path_dirname_r(&local, path)) < 0 ||
(error = git_path_resolve_relative(&local, 0)) < 0 ||
(error = git_path_to_dir(&local)) < 0 ||
- (error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
+ (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
(error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
/* Nothing, we just want to stop on the first error */
}
- git_buf_dispose(&local);
+ git_str_dispose(&local);
} else {
- if (!(error = git_buf_joinpath(&ignores->dir, path, "")))
+ if (!(error = git_str_joinpath(&ignores->dir, path, "")))
error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
}
@@ -349,7 +349,7 @@ int git_ignore__for_path(
}
/* load .git/info/exclude if possible */
- if ((error = git_repository_item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
+ if ((error = git_repository__item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = push_ignore_file(ignores, &ignores->ign_global, infopath.ptr, GIT_IGNORE_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto cleanup;
@@ -363,7 +363,7 @@ int git_ignore__for_path(
git_repository_attr_cache(repo)->cfg_excl_file);
cleanup:
- git_buf_dispose(&infopath);
+ git_str_dispose(&infopath);
if (error < 0)
git_ignore__free(ignores);
@@ -372,7 +372,7 @@ cleanup:
int git_ignore__push_dir(git_ignores *ign, const char *dir)
{
- if (git_buf_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
+ if (git_str_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
return -1;
ign->depth++;
@@ -409,7 +409,7 @@ int git_ignore__pop_dir(git_ignores *ign)
}
if (--ign->depth > 0) {
- git_buf_rtruncate_at_char(&ign->dir, '/');
+ git_str_rtruncate_at_char(&ign->dir, '/');
git_path_to_dir(&ign->dir);
}
@@ -435,7 +435,7 @@ void git_ignore__free(git_ignores *ignores)
}
git_vector_free(&ignores->ign_global);
- git_buf_dispose(&ignores->dir);
+ git_str_dispose(&ignores->dir);
}
static bool ignore_lookup_in_rules(
@@ -604,7 +604,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
size_t i;
git_attr_fnmatch *match;
int ignored;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
const char *filename;
git_index *idx;
@@ -645,7 +645,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
}
git_index_free(idx);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/ignore.h b/src/ignore.h
index 5895d3faa..799195258 100644
--- a/src/ignore.h
+++ b/src/ignore.h
@@ -26,7 +26,7 @@
*/
typedef struct {
git_repository *repo;
- git_buf dir; /* current directory reflected in ign_path */
+ git_str dir; /* current directory reflected in ign_path */
git_attr_file *ign_internal;
git_vector ign_path;
git_vector ign_global;
diff --git a/src/index.c b/src/index.c
index 2e24fff69..b8aa310d3 100644
--- a/src/index.c
+++ b/src/index.c
@@ -641,7 +641,7 @@ static int compare_checksum(git_index *index)
int git_index_read(git_index *index, int force)
{
int error = 0, updated;
- git_buf buffer = GIT_BUF_INIT;
+ git_str buffer = GIT_STR_INIT;
git_futils_filestamp stamp = index->stamp;
if (!index->index_file_path)
@@ -687,7 +687,7 @@ int git_index_read(git_index *index, int force)
index->dirty = 0;
}
- git_buf_dispose(&buffer);
+ git_str_dispose(&buffer);
return error;
}
@@ -969,7 +969,7 @@ static int index_entry_init(
{
int error = 0;
git_index_entry *entry = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
git_oid oid;
git_repository *repo;
@@ -992,7 +992,7 @@ static int index_entry_init(
return -1;
error = git_path_lstat(path.ptr, &st);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error < 0)
return error;
@@ -1525,7 +1525,7 @@ int git_index_add_from_buffer(
static int add_repo_as_submodule(git_index_entry **out, git_index *index, const char *path)
{
git_repository *sub;
- git_buf abspath = GIT_BUF_INIT;
+ git_str abspath = GIT_STR_INIT;
git_repository *repo = INDEX_OWNER(index);
git_reference *head;
git_index_entry *entry;
@@ -1556,7 +1556,7 @@ static int add_repo_as_submodule(git_index_entry **out, git_index *index, const
git_reference_free(head);
git_repository_free(sub);
- git_buf_dispose(&abspath);
+ git_str_dispose(&abspath);
*out = entry;
return 0;
@@ -1722,12 +1722,12 @@ int git_index_remove(git_index *index, const char *path, int stage)
int git_index_remove_directory(git_index *index, const char *dir, int stage)
{
- git_buf pfx = GIT_BUF_INIT;
+ git_str pfx = GIT_STR_INIT;
int error = 0;
size_t pos;
git_index_entry *entry;
- if (!(error = git_buf_sets(&pfx, dir)) &&
+ if (!(error = git_str_sets(&pfx, dir)) &&
!(error = git_path_to_dir(&pfx)))
index_find(&pos, index, pfx.ptr, pfx.size, GIT_INDEX_STAGE_ANY);
@@ -1746,7 +1746,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
/* removed entry at 'pos' so we don't need to increment */
}
- git_buf_dispose(&pfx);
+ git_str_dispose(&pfx);
return error;
}
@@ -2892,7 +2892,7 @@ done:
return error;
}
-static int write_extension(git_filebuf *file, struct index_extension *header, git_buf *data)
+static int write_extension(git_filebuf *file, struct index_extension *header, git_str *data)
{
struct index_extension ondisk;
@@ -2904,30 +2904,30 @@ static int write_extension(git_filebuf *file, struct index_extension *header, gi
return git_filebuf_write(file, data->ptr, data->size);
}
-static int create_name_extension_data(git_buf *name_buf, git_index_name_entry *conflict_name)
+static int create_name_extension_data(git_str *name_buf, git_index_name_entry *conflict_name)
{
int error = 0;
if (conflict_name->ancestor == NULL)
- error = git_buf_put(name_buf, "\0", 1);
+ error = git_str_put(name_buf, "\0", 1);
else
- error = git_buf_put(name_buf, conflict_name->ancestor, strlen(conflict_name->ancestor) + 1);
+ error = git_str_put(name_buf, conflict_name->ancestor, strlen(conflict_name->ancestor) + 1);
if (error != 0)
goto on_error;
if (conflict_name->ours == NULL)
- error = git_buf_put(name_buf, "\0", 1);
+ error = git_str_put(name_buf, "\0", 1);
else
- error = git_buf_put(name_buf, conflict_name->ours, strlen(conflict_name->ours) + 1);
+ error = git_str_put(name_buf, conflict_name->ours, strlen(conflict_name->ours) + 1);
if (error != 0)
goto on_error;
if (conflict_name->theirs == NULL)
- error = git_buf_put(name_buf, "\0", 1);
+ error = git_str_put(name_buf, "\0", 1);
else
- error = git_buf_put(name_buf, conflict_name->theirs, strlen(conflict_name->theirs) + 1);
+ error = git_str_put(name_buf, conflict_name->theirs, strlen(conflict_name->theirs) + 1);
on_error:
return error;
@@ -2935,7 +2935,7 @@ on_error:
static int write_name_extension(git_index *index, git_filebuf *file)
{
- git_buf name_buf = GIT_BUF_INIT;
+ git_str name_buf = GIT_STR_INIT;
git_vector *out = &index->names;
git_index_name_entry *conflict_name;
struct index_extension extension;
@@ -2953,28 +2953,28 @@ static int write_name_extension(git_index *index, git_filebuf *file)
error = write_extension(file, &extension, &name_buf);
- git_buf_dispose(&name_buf);
+ git_str_dispose(&name_buf);
done:
return error;
}
-static int create_reuc_extension_data(git_buf *reuc_buf, git_index_reuc_entry *reuc)
+static int create_reuc_extension_data(git_str *reuc_buf, git_index_reuc_entry *reuc)
{
int i;
int error = 0;
- if ((error = git_buf_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
+ if ((error = git_str_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
return error;
for (i = 0; i < 3; i++) {
- if ((error = git_buf_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
- (error = git_buf_put(reuc_buf, "\0", 1)) < 0)
+ if ((error = git_str_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
+ (error = git_str_put(reuc_buf, "\0", 1)) < 0)
return error;
}
for (i = 0; i < 3; i++) {
- if (reuc->mode[i] && (error = git_buf_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
+ if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
return error;
}
@@ -2983,7 +2983,7 @@ static int create_reuc_extension_data(git_buf *reuc_buf, git_index_reuc_entry *r
static int write_reuc_extension(git_index *index, git_filebuf *file)
{
- git_buf reuc_buf = GIT_BUF_INIT;
+ git_str reuc_buf = GIT_STR_INIT;
git_vector *out = &index->reuc;
git_index_reuc_entry *reuc;
struct index_extension extension;
@@ -3001,7 +3001,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
error = write_extension(file, &extension, &reuc_buf);
- git_buf_dispose(&reuc_buf);
+ git_str_dispose(&reuc_buf);
done:
return error;
@@ -3010,7 +3010,7 @@ done:
static int write_tree_extension(git_index *index, git_filebuf *file)
{
struct index_extension extension;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
if (index->tree == NULL)
@@ -3025,7 +3025,7 @@ static int write_tree_extension(git_index *index, git_filebuf *file)
error = write_extension(file, &extension, &buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -3115,13 +3115,13 @@ static int read_tree_cb(
{
read_tree_data *data = payload;
git_index_entry *entry = NULL, *old_entry;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t pos;
if (git_tree_entry__is_tree(tentry))
return 0;
- if (git_buf_joinpath(&path, root, tentry->filename) < 0)
+ if (git_str_joinpath(&path, root, tentry->filename) < 0)
return -1;
if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, NULL, false) < 0)
@@ -3143,7 +3143,7 @@ static int read_tree_cb(
}
index_entry_adjust_namemask(entry, path.size);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (git_vector_insert(data->new_entries, entry) < 0) {
index_entry_free(entry);
@@ -3540,7 +3540,7 @@ static int index_apply_to_all(
size_t i;
git_pathspec ps;
const char *match;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
GIT_ASSERT_ARG(index);
@@ -3569,7 +3569,7 @@ static int index_apply_to_all(
}
/* index manipulation may alter entry, so don't depend on it */
- if ((error = git_buf_sets(&path, entry->path)) < 0)
+ if ((error = git_str_sets(&path, entry->path)) < 0)
break;
switch (action) {
@@ -3598,7 +3598,7 @@ static int index_apply_to_all(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_pathspec__clear(&ps);
return error;
diff --git a/src/indexer.c b/src/indexer.c
index 16ed7bfae..213ad7581 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -48,7 +48,7 @@ struct git_indexer {
off64_t off;
off64_t entry_start;
git_object_t entry_type;
- git_buf entry_data;
+ git_str entry_data;
git_packfile_stream stream;
size_t nr_objects;
git_vector objects;
@@ -137,7 +137,7 @@ int git_indexer_new(
{
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *idx;
- git_buf path = GIT_BUF_INIT, tmp_path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, tmp_path = GIT_STR_INIT;
static const char suff[] = "/pack";
int error, fd = -1;
@@ -150,7 +150,7 @@ int git_indexer_new(
idx->progress_cb = opts.progress_cb;
idx->progress_payload = opts.progress_cb_payload;
idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
- git_buf_init(&idx->entry_data, 0);
+ git_str_init(&idx->entry_data, 0);
if ((error = git_hash_ctx_init(&idx->hash_ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
(error = git_hash_ctx_init(&idx->trailer, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
@@ -162,17 +162,17 @@ int git_indexer_new(
if (git_repository__fsync_gitdir)
idx->do_fsync = 1;
- error = git_buf_joinpath(&path, prefix, suff);
+ error = git_str_joinpath(&path, prefix, suff);
if (error < 0)
goto cleanup;
- fd = git_futils_mktmp(&tmp_path, git_buf_cstr(&path), idx->mode);
- git_buf_dispose(&path);
+ fd = git_futils_mktmp(&tmp_path, git_str_cstr(&path), idx->mode);
+ git_str_dispose(&path);
if (fd < 0)
goto cleanup;
- error = git_packfile_alloc(&idx->pack, git_buf_cstr(&tmp_path));
- git_buf_dispose(&tmp_path);
+ error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path));
+ git_str_dispose(&tmp_path);
if (error < 0)
goto cleanup;
@@ -188,14 +188,14 @@ cleanup:
if (fd != -1)
p_close(fd);
- if (git_buf_len(&tmp_path) > 0)
- p_unlink(git_buf_cstr(&tmp_path));
+ if (git_str_len(&tmp_path) > 0)
+ p_unlink(git_str_cstr(&tmp_path));
if (idx->pack != NULL)
p_unlink(idx->pack->pack_name);
- git_buf_dispose(&path);
- git_buf_dispose(&tmp_path);
+ git_str_dispose(&path);
+ git_str_dispose(&tmp_path);
git__free(idx);
return -1;
}
@@ -245,7 +245,7 @@ static int hash_object_stream(git_indexer*idx, git_packfile_stream *stream)
break;
if (idx->do_verify)
- git_buf_put(&idx->entry_data, idx->objbuf, read);
+ git_str_put(&idx->entry_data, idx->objbuf, read);
git_hash_update(&idx->hash_ctx, idx->objbuf, read);
} while (read > 0);
@@ -730,7 +730,7 @@ static int read_stream_object(git_indexer *idx, git_indexer_progress *stats)
git_mwindow_close(&w);
idx->entry_start = entry_start;
git_hash_init(&idx->hash_ctx);
- git_buf_clear(&idx->entry_data);
+ git_str_clear(&idx->entry_data);
if (type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA) {
error = advance_delta_offset(idx, type);
@@ -876,7 +876,7 @@ on_error:
return error;
}
-static int index_path(git_buf *path, git_indexer *idx, const char *suffix)
+static int index_path(git_str *path, git_indexer *idx, const char *suffix)
{
const char prefix[] = "pack-";
size_t slash = (size_t)path->size;
@@ -885,17 +885,17 @@ static int index_path(git_buf *path, git_indexer *idx, const char *suffix)
while (slash > 0 && path->ptr[slash - 1] != '/')
slash--;
- if (git_buf_grow(path, slash + 1 + strlen(prefix) +
+ if (git_str_grow(path, slash + 1 + strlen(prefix) +
GIT_OID_HEXSZ + strlen(suffix) + 1) < 0)
return -1;
- git_buf_truncate(path, slash);
- git_buf_puts(path, prefix);
- git_oid_fmt(path->ptr + git_buf_len(path), &idx->hash);
+ git_str_truncate(path, slash);
+ git_str_puts(path, prefix);
+ git_oid_fmt(path->ptr + git_str_len(path), &idx->hash);
path->size += GIT_OID_HEXSZ;
- git_buf_puts(path, suffix);
+ git_str_puts(path, suffix);
- return git_buf_oom(path) ? -1 : 0;
+ return git_str_oom(path) ? -1 : 0;
}
/**
@@ -915,7 +915,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
struct git_pack_entry *pentry = NULL;
git_oid foo = {{0}};
unsigned char hdr[64];
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
off64_t entry_start;
const void *data;
size_t len, hdr_len;
@@ -956,7 +956,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
idx->pack->mwf.size += buf.size;
entry->crc = htonl(crc32(entry->crc, (unsigned char *)buf.ptr, (uInt)buf.size));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Write a fake trailer so the pack functions play ball */
@@ -1152,7 +1152,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
unsigned int i, long_offsets = 0, left;
int error;
struct git_pack_idx_header hdr;
- git_buf filename = GIT_BUF_INIT;
+ git_str filename = GIT_STR_INIT;
struct entry *entry;
git_oid trailer_hash, file_hash;
git_filebuf index_file = {0};
@@ -1226,10 +1226,10 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
* files with different contents have different names */
git_oid_cpy(&idx->hash, &trailer_hash);
- git_buf_sets(&filename, idx->pack->pack_name);
- git_buf_shorten(&filename, strlen("pack"));
- git_buf_puts(&filename, "idx");
- if (git_buf_oom(&filename))
+ git_str_sets(&filename, idx->pack->pack_name);
+ git_str_shorten(&filename, strlen("pack"));
+ git_str_puts(&filename, "idx");
+ if (git_str_oom(&filename))
return -1;
if (git_filebuf_open(&index_file, filename.ptr,
@@ -1336,23 +1336,23 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
goto on_error;
/* And don't forget to rename the packfile to its new place. */
- if (p_rename(idx->pack->pack_name, git_buf_cstr(&filename)) < 0)
+ if (p_rename(idx->pack->pack_name, git_str_cstr(&filename)) < 0)
goto on_error;
/* And fsync the parent directory if we're asked to. */
if (idx->do_fsync &&
- git_futils_fsync_parent(git_buf_cstr(&filename)) < 0)
+ git_futils_fsync_parent(git_str_cstr(&filename)) < 0)
goto on_error;
idx->pack_committed = 1;
- git_buf_dispose(&filename);
+ git_str_dispose(&filename);
return 0;
on_error:
git_mwindow_free_all(&idx->pack->mwf);
git_filebuf_cleanup(&index_file);
- git_buf_dispose(&filename);
+ git_str_dispose(&filename);
return -1;
}
@@ -1389,7 +1389,7 @@ void git_indexer_free(git_indexer *idx)
git_hash_ctx_cleanup(&idx->trailer);
git_hash_ctx_cleanup(&idx->hash_ctx);
- git_buf_dispose(&idx->entry_data);
+ git_str_dispose(&idx->entry_data);
git_oidmap_free(idx->expected_oids);
git__free(idx);
}
diff --git a/src/iterator.c b/src/iterator.c
index ce9f305ef..5549c636a 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -424,7 +424,7 @@ typedef struct {
git_tree *tree;
/* path to this particular frame (folder) */
- git_buf path;
+ git_str path;
/* a sorted list of the entries for this frame (folder), these are
* actually pointers to the iterator's entry pool.
@@ -441,7 +441,7 @@ typedef struct {
* parent path.
*/
git_vector similar_trees;
- git_array_t(git_buf) similar_paths;
+ git_array_t(git_str) similar_paths;
} tree_iterator_frame;
typedef struct {
@@ -450,7 +450,7 @@ typedef struct {
git_array_t(tree_iterator_frame) frames;
git_index_entry entry;
- git_buf entry_path;
+ git_str entry_path;
/* a pool of entries to reduce the number of allocations */
git_pool entry_pool;
@@ -508,20 +508,20 @@ static int tree_iterator_entry_sort_icase(const void *ptr_a, const void *ptr_b)
}
static int tree_iterator_compute_path(
- git_buf *out,
+ git_str *out,
tree_iterator_entry *entry)
{
- git_buf_clear(out);
+ git_str_clear(out);
if (entry->parent_path)
- git_buf_joinpath(out, entry->parent_path, entry->tree_entry->filename);
+ git_str_joinpath(out, entry->parent_path, entry->tree_entry->filename);
else
- git_buf_puts(out, entry->tree_entry->filename);
+ git_str_puts(out, entry->tree_entry->filename);
if (git_tree_entry__is_tree(entry->tree_entry))
- git_buf_putc(out, '/');
+ git_str_putc(out, '/');
- if (git_buf_oom(out))
+ if (git_str_oom(out))
return -1;
return 0;
@@ -601,7 +601,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
tree_iterator_entry *entry, *new_entry;
git_tree *tree = NULL;
git_tree_entry *tree_entry;
- git_buf *path;
+ git_str *path;
size_t new_size, i;
int error = 0;
@@ -621,7 +621,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
path = git_array_alloc(parent_frame->similar_paths);
GIT_ERROR_CHECK_ALLOC(path);
- memset(path, 0, sizeof(git_buf));
+ memset(path, 0, sizeof(git_str));
if ((error = tree_iterator_compute_path(path, entry)) < 0)
break;
@@ -681,7 +681,7 @@ done:
static int tree_iterator_frame_pop(tree_iterator *iter)
{
tree_iterator_frame *frame;
- git_buf *buf = NULL;
+ git_str *buf = NULL;
git_tree *tree;
size_t i;
@@ -694,7 +694,7 @@ static int tree_iterator_frame_pop(tree_iterator *iter)
do {
buf = git_array_pop(frame->similar_paths);
- git_buf_dispose(buf);
+ git_str_dispose(buf);
} while (buf != NULL);
git_array_clear(frame->similar_paths);
@@ -704,7 +704,7 @@ static int tree_iterator_frame_pop(tree_iterator *iter)
git_vector_free(&frame->similar_trees);
- git_buf_dispose(&frame->path);
+ git_str_dispose(&frame->path);
return 0;
}
@@ -892,7 +892,7 @@ static void tree_iterator_clear(tree_iterator *iter)
git_array_clear(iter->frames);
git_pool_clear(&iter->entry_pool);
- git_buf_clear(&iter->entry_path);
+ git_str_clear(&iter->entry_path);
iterator_clear(&iter->base);
}
@@ -925,7 +925,7 @@ static void tree_iterator_free(git_iterator *i)
tree_iterator_clear(iter);
git_tree_free(iter->root);
- git_buf_dispose(&iter->entry_path);
+ git_str_dispose(&iter->entry_path);
}
int git_iterator_for_tree(
@@ -1040,11 +1040,11 @@ typedef struct {
/* info about the current entry */
git_index_entry entry;
- git_buf current_path;
+ git_str current_path;
int current_is_ignored;
/* temporary buffer for advance_over */
- git_buf tmp_buf;
+ git_str tmp_buf;
} filesystem_iterator;
@@ -1266,7 +1266,7 @@ static int filesystem_iterator_entry_hash(
filesystem_iterator *iter,
filesystem_iterator_entry *entry)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
int error;
if (S_ISDIR(entry->st.st_mode)) {
@@ -1278,11 +1278,11 @@ static int filesystem_iterator_entry_hash(
return git_repository_hashfile(&entry->id,
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
- if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)) &&
+ if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
!(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return error;
}
@@ -1337,7 +1337,7 @@ static int filesystem_iterator_frame_push(
{
filesystem_iterator_frame *new_frame = NULL;
git_path_diriter diriter = GIT_PATH_DIRITER_INIT;
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
const char *path;
filesystem_iterator_entry *entry;
struct stat statbuf;
@@ -1356,11 +1356,11 @@ static int filesystem_iterator_frame_push(
memset(new_frame, 0, sizeof(filesystem_iterator_frame));
if (frame_entry)
- git_buf_joinpath(&root, iter->root, frame_entry->path);
+ git_str_joinpath(&root, iter->root, frame_entry->path);
else
- git_buf_puts(&root, iter->root);
+ git_str_puts(&root, iter->root);
- if (git_buf_oom(&root) ||
+ if (git_str_oom(&root) ||
git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
error = -1;
goto done;
@@ -1471,7 +1471,7 @@ done:
if (error < 0)
git_array_pop(iter->frames);
- git_buf_dispose(&root);
+ git_str_dispose(&root);
git_path_diriter_free(&diriter);
return error;
}
@@ -1551,7 +1551,7 @@ static int filesystem_iterator_is_dir(
const filesystem_iterator_entry *entry)
{
struct stat st;
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
int error = 0;
if (S_ISDIR(entry->st.st_mode)) {
@@ -1564,7 +1564,7 @@ static int filesystem_iterator_is_dir(
goto done;
}
- if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
+ if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
(error = p_stat(fullpath.ptr, &st)) < 0)
goto done;
@@ -1572,7 +1572,7 @@ static int filesystem_iterator_is_dir(
*is_dir = S_ISDIR(st.st_mode);
done:
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return error;
}
@@ -1673,7 +1673,7 @@ static int filesystem_iterator_advance_into(
return filesystem_iterator_advance(out, i);
}
-int git_iterator_current_workdir_path(git_buf **out, git_iterator *i)
+int git_iterator_current_workdir_path(git_str **out, git_iterator *i)
{
filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
const git_index_entry *entry;
@@ -1684,10 +1684,10 @@ int git_iterator_current_workdir_path(git_buf **out, git_iterator *i)
return 0;
}
- git_buf_truncate(&iter->current_path, iter->root_len);
+ git_str_truncate(&iter->current_path, iter->root_len);
if (git_iterator_current(&entry, i) < 0 ||
- git_buf_puts(&iter->current_path, entry->path) < 0)
+ git_str_puts(&iter->current_path, entry->path) < 0)
return -1;
*out = &iter->current_path;
@@ -1790,8 +1790,8 @@ static int filesystem_iterator_advance_over(
return filesystem_iterator_advance(out, i);
}
- git_buf_clear(&iter->tmp_buf);
- if ((error = git_buf_puts(&iter->tmp_buf, entry->path)) < 0)
+ git_str_clear(&iter->tmp_buf);
+ if ((error = git_str_puts(&iter->tmp_buf, entry->path)) < 0)
return error;
base = iter->tmp_buf.ptr;
@@ -1858,7 +1858,7 @@ static void filesystem_iterator_clear(filesystem_iterator *iter)
git_array_clear(iter->frames);
git_ignore__free(&iter->ignores);
- git_buf_dispose(&iter->tmp_buf);
+ git_str_dispose(&iter->tmp_buf);
iterator_clear(&iter->base);
}
@@ -1892,7 +1892,7 @@ static void filesystem_iterator_free(git_iterator *i)
{
filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
git__free(iter->root);
- git_buf_dispose(&iter->current_path);
+ git_str_dispose(&iter->current_path);
git_tree_free(iter->tree);
if (iter->index)
git_index_snapshot_release(&iter->index_snapshot, iter->index);
@@ -1946,7 +1946,7 @@ static int iterator_for_filesystem(
iter->root[root_len] = '\0';
iter->root_len = root_len;
- if ((error = git_buf_puts(&iter->current_path, iter->root)) < 0)
+ if ((error = git_str_puts(&iter->current_path, iter->root)) < 0)
goto on_error;
if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0)
@@ -2024,7 +2024,7 @@ typedef struct {
/* the pseudotree entry */
git_index_entry tree_entry;
- git_buf tree_buf;
+ git_str tree_buf;
bool skip_tree;
const git_index_entry *entry;
@@ -2064,8 +2064,8 @@ static bool index_iterator_create_pseudotree(
if ((dirsep = strchr(relative_path, '/')) == NULL)
return false;
- git_buf_clear(&iter->tree_buf);
- git_buf_put(&iter->tree_buf, path, (dirsep - path) + 1);
+ git_str_clear(&iter->tree_buf);
+ git_str_put(&iter->tree_buf, path, (dirsep - path) + 1);
iter->tree_entry.mode = GIT_FILEMODE_TREE;
iter->tree_entry.path = iter->tree_buf.ptr;
@@ -2230,7 +2230,7 @@ static void index_iterator_free(git_iterator *i)
index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
git_index_snapshot_release(&iter->entries, iter->base.index);
- git_buf_dispose(&iter->tree_buf);
+ git_str_dispose(&iter->tree_buf);
}
int git_iterator_for_index(
diff --git a/src/iterator.h b/src/iterator.h
index 30465df2f..e55c1047a 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -11,7 +11,7 @@
#include "git2/index.h"
#include "vector.h"
-#include "buffer.h"
+#include "str.h"
#include "ignore.h"
typedef struct git_iterator git_iterator;
@@ -278,11 +278,11 @@ extern bool git_iterator_current_tree_is_ignored(git_iterator *iter);
/**
* Get full path of the current item from a workdir iterator. This will
- * return NULL for a non-workdir iterator. The git_buf is still owned by
+ * return NULL for a non-workdir iterator. The git_str is still owned by
* the iterator; this is exposed just for efficiency.
*/
extern int git_iterator_current_workdir_path(
- git_buf **path, git_iterator *iter);
+ git_str **path, git_iterator *iter);
/**
* Retrieve the index stored in the iterator.
diff --git a/src/libgit2.c b/src/libgit2.c
index cc793b458..b3a72de18 100644
--- a/src/libgit2.c
+++ b/src/libgit2.c
@@ -9,6 +9,7 @@
#include <git2.h>
#include "alloc.h"
+#include "buf.h"
#include "cache.h"
#include "common.h"
#include "filter.h"
@@ -192,15 +193,17 @@ int git_libgit2_opts(int key, ...)
{
int sysdir = va_arg(ap, int);
git_buf *out = va_arg(ap, git_buf *);
- const git_buf *tmp;
+ git_str str = GIT_STR_INIT;
+ const git_str *tmp;
int level;
- if ((error = config_level_to_sysdir(&level, sysdir)) < 0 ||
- (error = git_buf_sanitize(out)) < 0 ||
- (error = git_sysdir_get(&tmp, level)) < 0)
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = config_level_to_sysdir(&level, sysdir)) < 0 ||
+ (error = git_sysdir_get(&tmp, level)) < 0 ||
+ (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
break;
- error = git_buf_sets(out, tmp->ptr);
+ error = git_buf_fromstr(out, &str);
}
break;
@@ -237,13 +240,15 @@ int git_libgit2_opts(int key, ...)
case GIT_OPT_GET_TEMPLATE_PATH:
{
git_buf *out = va_arg(ap, git_buf *);
- const git_buf *tmp;
+ git_str str = GIT_STR_INIT;
+ const git_str *tmp;
- if ((error = git_buf_sanitize(out)) < 0 ||
- (error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0)
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0 ||
+ (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
break;
- error = git_buf_sets(out, tmp->ptr);
+ error = git_buf_fromstr(out, &str);
}
break;
@@ -306,9 +311,13 @@ int git_libgit2_opts(int key, ...)
case GIT_OPT_GET_USER_AGENT:
{
git_buf *out = va_arg(ap, git_buf *);
- if ((error = git_buf_sanitize(out)) < 0)
+ git_str str = GIT_STR_INIT;
+
+ if ((error = git_buf_tostr(&str, out)) < 0 ||
+ (error = git_str_puts(&str, git__user_agent)) < 0)
break;
- error = git_buf_sets(out, git__user_agent);
+
+ error = git_buf_fromstr(out, &str);
}
break;
diff --git a/src/mailmap.c b/src/mailmap.c
index b69d55e2e..38ae01645 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -8,6 +8,7 @@
#include "mailmap.h"
#include "common.h"
+#include "config.h"
#include "path.h"
#include "repository.h"
#include "signature.h"
@@ -90,21 +91,21 @@ static int advance_until(
/*
* Parse a single entry from a mailmap file.
*
- * The output git_bufs will be non-owning, and should be copied before being
+ * The output git_strs will be non-owning, and should be copied before being
* persisted.
*/
static int parse_mailmap_entry(
- git_buf *real_name, git_buf *real_email,
- git_buf *replace_name, git_buf *replace_email,
+ git_str *real_name, git_str *real_email,
+ git_str *replace_name, git_str *replace_email,
git_parse_ctx *ctx)
{
const char *start;
size_t len;
- git_buf_clear(real_name);
- git_buf_clear(real_email);
- git_buf_clear(replace_name);
- git_buf_clear(replace_email);
+ git_str_clear(real_name);
+ git_str_clear(real_email);
+ git_str_clear(replace_name);
+ git_str_clear(replace_email);
git_parse_advance_ws(ctx);
if (is_eol(ctx))
@@ -114,8 +115,8 @@ static int parse_mailmap_entry(
if (advance_until(&start, &len, ctx, '<') < 0)
return -1;
- git_buf_attach_notowned(real_name, start, len);
- git_buf_rtrim(real_name);
+ git_str_attach_notowned(real_name, start, len);
+ git_str_rtrim(real_name);
/*
* If this is the last email in the line, this is the email to replace,
@@ -126,19 +127,19 @@ static int parse_mailmap_entry(
/* If we aren't at the end of the line, parse a second name and email */
if (!is_eol(ctx)) {
- git_buf_attach_notowned(real_email, start, len);
+ git_str_attach_notowned(real_email, start, len);
git_parse_advance_ws(ctx);
if (advance_until(&start, &len, ctx, '<') < 0)
return -1;
- git_buf_attach_notowned(replace_name, start, len);
- git_buf_rtrim(replace_name);
+ git_str_attach_notowned(replace_name, start, len);
+ git_str_rtrim(replace_name);
if (advance_until(&start, &len, ctx, '>') < 0)
return -1;
}
- git_buf_attach_notowned(replace_email, start, len);
+ git_str_attach_notowned(replace_email, start, len);
if (!is_eol(ctx))
return -1;
@@ -231,10 +232,10 @@ static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
git_parse_ctx ctx;
/* Scratch buffers containing the real parsed names & emails */
- git_buf real_name = GIT_BUF_INIT;
- git_buf real_email = GIT_BUF_INIT;
- git_buf replace_name = GIT_BUF_INIT;
- git_buf replace_email = GIT_BUF_INIT;
+ git_str real_name = GIT_STR_INIT;
+ git_str real_email = GIT_STR_INIT;
+ git_str replace_name = GIT_STR_INIT;
+ git_str replace_email = GIT_STR_INIT;
/* Buffers may not contain '\0's. */
if (memchr(buf, '\0', len) != NULL)
@@ -263,10 +264,10 @@ static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
}
cleanup:
- git_buf_dispose(&real_name);
- git_buf_dispose(&real_email);
- git_buf_dispose(&replace_name);
- git_buf_dispose(&replace_email);
+ git_str_dispose(&real_name);
+ git_str_dispose(&real_email);
+ git_str_dispose(&replace_name);
+ git_str_dispose(&replace_email);
return error;
}
@@ -289,7 +290,7 @@ static int mailmap_add_blob(
{
git_object *object = NULL;
git_blob *blob = NULL;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(mm);
@@ -312,7 +313,7 @@ static int mailmap_add_blob(
goto cleanup;
cleanup:
- git_buf_dispose(&content);
+ git_str_dispose(&content);
git_blob_free(blob);
git_object_free(object);
return error;
@@ -322,8 +323,8 @@ static int mailmap_add_file_ondisk(
git_mailmap *mm, const char *path, git_repository *repo)
{
const char *base = repo ? git_repository_workdir(repo) : NULL;
- git_buf fullpath = GIT_BUF_INIT;
- git_buf content = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
+ git_str content = GIT_STR_INIT;
int error;
error = git_path_join_unrooted(&fullpath, path, base, NULL);
@@ -343,8 +344,8 @@ static int mailmap_add_file_ondisk(
goto cleanup;
cleanup:
- git_buf_dispose(&fullpath);
- git_buf_dispose(&content);
+ git_str_dispose(&fullpath);
+ git_str_dispose(&content);
return error;
}
@@ -352,8 +353,8 @@ cleanup:
static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
{
git_config *config = NULL;
- git_buf rev_buf = GIT_BUF_INIT;
- git_buf path_buf = GIT_BUF_INIT;
+ git_str rev_buf = GIT_STR_INIT;
+ git_str path_buf = GIT_STR_INIT;
const char *rev = NULL;
const char *path = NULL;
@@ -363,9 +364,9 @@ static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
/* Try to load 'mailmap.file' and 'mailmap.blob' cfgs from the repo */
if (git_repository_config(&config, repo) == 0) {
- if (git_config_get_string_buf(&rev_buf, config, MM_BLOB_CONFIG) == 0)
+ if (git_config__get_string_buf(&rev_buf, config, MM_BLOB_CONFIG) == 0)
rev = rev_buf.ptr;
- if (git_config_get_path(&path_buf, config, MM_FILE_CONFIG) == 0)
+ if (git_config__get_path(&path_buf, config, MM_FILE_CONFIG) == 0)
path = path_buf.ptr;
}
@@ -387,8 +388,8 @@ static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
if (path != NULL)
mailmap_add_file_ondisk(mm, path, repo);
- git_buf_dispose(&rev_buf);
- git_buf_dispose(&path_buf);
+ git_str_dispose(&rev_buf);
+ git_str_dispose(&path_buf);
git_config_free(config);
}
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;
}
diff --git a/src/merge_driver.c b/src/merge_driver.c
index 17c386a14..be4d3bf8a 100644
--- a/src/merge_driver.c
+++ b/src/merge_driver.c
@@ -110,7 +110,7 @@ int git_merge_driver__builtin_apply(
merged_out->ptr = (char *)result.ptr;
merged_out->size = result.len;
- merged_out->asize = result.len;
+ merged_out->reserved = 0;
result.ptr = NULL;
done:
diff --git a/src/message.c b/src/message.c
index 327b984fc..ec0103a33 100644
--- a/src/message.c
+++ b/src/message.c
@@ -5,7 +5,9 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "message.h"
+#include "buf.h"
+
+#include "git2/message.h"
static size_t line_length_without_trailing_spaces(const char *line, size_t len)
{
@@ -21,17 +23,17 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len)
/* Greatly inspired from git.git "stripspace" */
/* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */
-int git_message_prettify(git_buf *message_out, const char *message, int strip_comments, char comment_char)
+static int git_message__prettify(
+ git_str *message_out,
+ const char *message,
+ int strip_comments,
+ char comment_char)
{
const size_t message_len = strlen(message);
int consecutive_empty_lines = 0;
size_t i, line_length, rtrimmed_line_length;
char *next_newline;
- int error;
-
- if ((error = git_buf_sanitize(message_out)) < 0)
- return error;
for (i = 0; i < strlen(message); i += line_length) {
next_newline = memchr(message + i, '\n', message_len - i);
@@ -53,12 +55,21 @@ int git_message_prettify(git_buf *message_out, const char *message, int strip_co
}
if (consecutive_empty_lines > 0 && message_out->size > 0)
- git_buf_putc(message_out, '\n');
+ git_str_putc(message_out, '\n');
consecutive_empty_lines = 0;
- git_buf_put(message_out, message + i, rtrimmed_line_length);
- git_buf_putc(message_out, '\n');
+ git_str_put(message_out, message + i, rtrimmed_line_length);
+ git_str_putc(message_out, '\n');
}
- return git_buf_oom(message_out) ? -1 : 0;
+ return git_str_oom(message_out) ? -1 : 0;
+}
+
+int git_message_prettify(
+ git_buf *message_out,
+ const char *message,
+ int strip_comments,
+ char comment_char)
+{
+ GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char);
}
diff --git a/src/midx.c b/src/midx.c
index cd3c98cef..b8da98986 100644
--- a/src/midx.c
+++ b/src/midx.c
@@ -8,7 +8,7 @@
#include "midx.h"
#include "array.h"
-#include "buffer.h"
+#include "buf.h"
#include "filebuf.h"
#include "futils.h"
#include "hash.h"
@@ -16,6 +16,7 @@
#include "pack.h"
#include "path.h"
#include "repository.h"
+#include "str.h"
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
#define MIDX_VERSION 1
@@ -313,7 +314,7 @@ int git_midx_open(
idx = git__calloc(1, sizeof(git_midx_file));
GIT_ERROR_CHECK_ALLOC(idx);
- error = git_buf_sets(&idx->filename, path);
+ error = git_str_sets(&idx->filename, path);
if (error < 0)
return error;
@@ -477,7 +478,7 @@ void git_midx_free(git_midx_file *idx)
if (!idx)
return;
- git_buf_dispose(&idx->filename);
+ git_str_dispose(&idx->filename);
git_midx_close(idx);
git__free(idx);
}
@@ -497,14 +498,14 @@ int git_midx_writer_new(
git_midx_writer *w = git__calloc(1, sizeof(git_midx_writer));
GIT_ERROR_CHECK_ALLOC(w);
- if (git_buf_sets(&w->pack_dir, pack_dir) < 0) {
+ if (git_str_sets(&w->pack_dir, pack_dir) < 0) {
git__free(w);
return -1;
}
git_path_squash_slashes(&w->pack_dir);
if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) {
- git_buf_dispose(&w->pack_dir);
+ git_str_dispose(&w->pack_dir);
git__free(w);
return -1;
}
@@ -524,7 +525,7 @@ void git_midx_writer_free(git_midx_writer *w)
git_vector_foreach (&w->packs, i, p)
git_mwindow_put_pack(p);
git_vector_free(&w->packs);
- git_buf_dispose(&w->pack_dir);
+ git_str_dispose(&w->pack_dir);
git__free(w);
}
@@ -532,16 +533,16 @@ int git_midx_writer_add(
git_midx_writer *w,
const char *idx_path)
{
- git_buf idx_path_buf = GIT_BUF_INIT;
+ git_str idx_path_buf = GIT_STR_INIT;
int error;
struct git_pack_file *p;
- error = git_path_prettify(&idx_path_buf, idx_path, git_buf_cstr(&w->pack_dir));
+ error = git_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir));
if (error < 0)
return error;
- error = git_mwindow_get_pack(&p, git_buf_cstr(&idx_path_buf));
- git_buf_dispose(&idx_path_buf);
+ error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf));
+ git_str_dispose(&idx_path_buf);
if (error < 0)
return error;
@@ -613,8 +614,8 @@ static int write_chunk_header(int chunk_id, off64_t offset, midx_write_cb write_
static int midx_write_buf(const char *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
struct midx_write_hash_context {
@@ -648,10 +649,10 @@ static int midx_write(
uint32_t object_large_offsets_count;
uint32_t oid_fanout[256];
off64_t offset;
- git_buf packfile_names = GIT_BUF_INIT,
- oid_lookup = GIT_BUF_INIT,
- object_offsets = GIT_BUF_INIT,
- object_large_offsets = GIT_BUF_INIT;
+ git_str packfile_names = GIT_STR_INIT,
+ oid_lookup = GIT_STR_INIT,
+ object_offsets = GIT_STR_INIT,
+ object_large_offsets = GIT_STR_INIT;
git_oid idx_checksum = {{0}};
git_midx_entry *entry;
object_entry_array_t object_entries_array = GIT_ARRAY_INIT;
@@ -676,34 +677,34 @@ static int midx_write(
git_vector_sort(&w->packs);
git_vector_foreach (&w->packs, i, p) {
- git_buf relative_index = GIT_BUF_INIT;
+ git_str relative_index = GIT_STR_INIT;
struct object_entry_cb_state state = {0};
size_t path_len;
state.pack_index = (uint32_t)i;
state.object_entries_array = &object_entries_array;
- error = git_buf_sets(&relative_index, p->pack_name);
+ error = git_str_sets(&relative_index, p->pack_name);
if (error < 0)
goto cleanup;
- error = git_path_make_relative(&relative_index, git_buf_cstr(&w->pack_dir));
+ error = git_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir));
if (error < 0) {
- git_buf_dispose(&relative_index);
+ git_str_dispose(&relative_index);
goto cleanup;
}
- path_len = git_buf_len(&relative_index);
- if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(&relative_index), ".pack") != 0) {
- git_buf_dispose(&relative_index);
+ path_len = git_str_len(&relative_index);
+ if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(&relative_index), ".pack") != 0) {
+ git_str_dispose(&relative_index);
git_error_set(GIT_ERROR_INVALID, "invalid packfile name: '%s'", p->pack_name);
error = -1;
goto cleanup;
}
path_len -= strlen(".pack");
- git_buf_put(&packfile_names, git_buf_cstr(&relative_index), path_len);
- git_buf_puts(&packfile_names, ".idx");
- git_buf_putc(&packfile_names, '\0');
- git_buf_dispose(&relative_index);
+ git_str_put(&packfile_names, git_str_cstr(&relative_index), path_len);
+ git_str_puts(&packfile_names, ".idx");
+ git_str_putc(&packfile_names, '\0');
+ git_str_dispose(&relative_index);
error = git_pack_foreach_entry_offset(p, object_entry__cb, &state);
if (error < 0)
@@ -723,8 +724,8 @@ static int midx_write(
git_vector_uniq(&object_entries, NULL);
/* Pad the packfile names so it is a multiple of four. */
- while (git_buf_len(&packfile_names) & 3)
- git_buf_putc(&packfile_names, '\0');
+ while (git_str_len(&packfile_names) & 3)
+ git_str_putc(&packfile_names, '\0');
/* Fill the OID Fanout table. */
oid_fanout_count = 0;
@@ -737,7 +738,7 @@ static int midx_write(
/* Fill the OID Lookup table. */
git_vector_foreach (&object_entries, i, entry) {
- error = git_buf_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
+ error = git_str_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
if (error < 0)
goto cleanup;
}
@@ -748,7 +749,7 @@ static int midx_write(
uint32_t word;
word = htonl((uint32_t)entry->pack_index);
- error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
+ error = git_str_put(&object_offsets, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
if (entry->offset >= 0x80000000l) {
@@ -759,7 +760,7 @@ static int midx_write(
word = htonl((uint32_t)entry->offset & 0x7fffffffu);
}
- error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
+ error = git_str_put(&object_offsets, (const char *)&word, sizeof(word));
if (error < 0)
goto cleanup;
}
@@ -767,7 +768,7 @@ static int midx_write(
/* Write the header. */
hdr.packfiles = htonl((uint32_t)git_vector_length(&w->packs));
hdr.chunks = 4;
- if (git_buf_len(&object_large_offsets) > 0)
+ if (git_str_len(&object_large_offsets) > 0)
hdr.chunks++;
error = write_cb((const char *)&hdr, sizeof(hdr), cb_data);
if (error < 0)
@@ -778,7 +779,7 @@ static int midx_write(
error = write_chunk_header(MIDX_PACKFILE_NAMES_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&packfile_names);
+ offset += git_str_len(&packfile_names);
error = write_chunk_header(MIDX_OID_FANOUT_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
@@ -786,35 +787,35 @@ static int midx_write(
error = write_chunk_header(MIDX_OID_LOOKUP_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&oid_lookup);
+ offset += git_str_len(&oid_lookup);
error = write_chunk_header(MIDX_OBJECT_OFFSETS_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&object_offsets);
- if (git_buf_len(&object_large_offsets) > 0) {
+ offset += git_str_len(&object_offsets);
+ if (git_str_len(&object_large_offsets) > 0) {
error = write_chunk_header(MIDX_OBJECT_LARGE_OFFSETS_ID, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
- offset += git_buf_len(&object_large_offsets);
+ offset += git_str_len(&object_large_offsets);
}
error = write_chunk_header(0, offset, write_cb, cb_data);
if (error < 0)
goto cleanup;
/* Write all the chunks. */
- error = write_cb(git_buf_cstr(&packfile_names), git_buf_len(&packfile_names), cb_data);
+ error = write_cb(git_str_cstr(&packfile_names), git_str_len(&packfile_names), cb_data);
if (error < 0)
goto cleanup;
error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&oid_lookup), git_buf_len(&oid_lookup), cb_data);
+ error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&object_offsets), git_buf_len(&object_offsets), cb_data);
+ error = write_cb(git_str_cstr(&object_offsets), git_str_len(&object_offsets), cb_data);
if (error < 0)
goto cleanup;
- error = write_cb(git_buf_cstr(&object_large_offsets), git_buf_len(&object_large_offsets), cb_data);
+ error = write_cb(git_str_cstr(&object_large_offsets), git_str_len(&object_large_offsets), cb_data);
if (error < 0)
goto cleanup;
@@ -829,10 +830,10 @@ static int midx_write(
cleanup:
git_array_clear(object_entries_array);
git_vector_free(&object_entries);
- git_buf_dispose(&packfile_names);
- git_buf_dispose(&oid_lookup);
- git_buf_dispose(&object_offsets);
- git_buf_dispose(&object_large_offsets);
+ git_str_dispose(&packfile_names);
+ git_str_dispose(&oid_lookup);
+ git_str_dispose(&object_offsets);
+ git_str_dispose(&object_large_offsets);
git_hash_ctx_cleanup(&ctx);
return error;
}
@@ -848,17 +849,17 @@ int git_midx_writer_commit(
{
int error;
int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER;
- git_buf midx_path = GIT_BUF_INIT;
+ git_str midx_path = GIT_STR_INIT;
git_filebuf output = GIT_FILEBUF_INIT;
- error = git_buf_joinpath(&midx_path, git_buf_cstr(&w->pack_dir), "multi-pack-index");
+ error = git_str_joinpath(&midx_path, git_str_cstr(&w->pack_dir), "multi-pack-index");
if (error < 0)
return error;
if (git_repository__fsync_gitdir)
filebuf_flags |= GIT_FILEBUF_FSYNC;
- error = git_filebuf_open(&output, git_buf_cstr(&midx_path), filebuf_flags, 0644);
- git_buf_dispose(&midx_path);
+ error = git_filebuf_open(&output, git_str_cstr(&midx_path), filebuf_flags, 0644);
+ git_str_dispose(&midx_path);
if (error < 0)
return error;
@@ -875,5 +876,13 @@ int git_midx_writer_dump(
git_buf *midx,
git_midx_writer *w)
{
- return midx_write(w, midx_write_buf, midx);
+ git_str str = GIT_STR_INIT;
+ int error;
+
+ if ((error = git_buf_tostr(&str, midx)) < 0 ||
+ (error = midx_write(w, midx_write_buf, &str)) == 0)
+ error = git_buf_fromstr(midx, &str);
+
+ git_str_dispose(&str);
+ return error;
}
diff --git a/src/midx.h b/src/midx.h
index 4ce17ce73..ef3d534bc 100644
--- a/src/midx.h
+++ b/src/midx.h
@@ -54,7 +54,7 @@ typedef struct git_midx_file {
git_oid checksum;
/* something like ".git/objects/pack/multi-pack-index". */
- git_buf filename;
+ git_str filename;
} git_midx_file;
/*
@@ -77,7 +77,7 @@ struct git_midx_writer {
* The path of the directory where the .pack/.idx files are stored. The
* `multi-pack-index` file will be written to the same directory.
*/
- git_buf pack_dir;
+ git_str pack_dir;
/* The list of `git_pack_file`s. */
git_vector packs;
diff --git a/src/net.c b/src/net.c
index 361e40e7b..58792ee7d 100644
--- a/src/net.c
+++ b/src/net.c
@@ -12,7 +12,7 @@
#include "git2/errors.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "http_parser.h"
#include "runtime.h"
@@ -79,13 +79,13 @@ int git_net_url_parse(git_net_url *url, const char *given)
{
struct http_parser_url u = {0};
bool has_scheme, has_host, has_port, has_path, has_query, has_userinfo;
- git_buf scheme = GIT_BUF_INIT,
- host = GIT_BUF_INIT,
- port = GIT_BUF_INIT,
- path = GIT_BUF_INIT,
- username = GIT_BUF_INIT,
- password = GIT_BUF_INIT,
- query = GIT_BUF_INIT;
+ git_str scheme = GIT_STR_INIT,
+ host = GIT_STR_INIT,
+ port = GIT_STR_INIT,
+ path = GIT_STR_INIT,
+ username = GIT_STR_INIT,
+ password = GIT_STR_INIT,
+ query = GIT_STR_INIT;
int error = GIT_EINVALIDSPEC;
if (http_parser_parse_url(given, strlen(given), false, &u)) {
@@ -103,7 +103,7 @@ int git_net_url_parse(git_net_url *url, const char *given)
if (has_scheme) {
const char *url_scheme = given + u.field_data[UF_SCHEMA].off;
size_t url_scheme_len = u.field_data[UF_SCHEMA].len;
- git_buf_put(&scheme, url_scheme, url_scheme_len);
+ git_str_put(&scheme, url_scheme, url_scheme_len);
git__strntolower(scheme.ptr, scheme.size);
} else {
git_error_set(GIT_ERROR_NET, "malformed URL '%s'", given);
@@ -113,13 +113,13 @@ int git_net_url_parse(git_net_url *url, const char *given)
if (has_host) {
const char *url_host = given + u.field_data[UF_HOST].off;
size_t url_host_len = u.field_data[UF_HOST].len;
- git_buf_decode_percent(&host, url_host, url_host_len);
+ git_str_decode_percent(&host, url_host, url_host_len);
}
if (has_port) {
const char *url_port = given + u.field_data[UF_PORT].off;
size_t url_port_len = u.field_data[UF_PORT].len;
- git_buf_put(&port, url_port, url_port_len);
+ git_str_put(&port, url_port, url_port_len);
} else {
const char *default_port = default_port_for_scheme(scheme.ptr);
@@ -128,21 +128,21 @@ int git_net_url_parse(git_net_url *url, const char *given)
goto done;
}
- git_buf_puts(&port, default_port);
+ git_str_puts(&port, default_port);
}
if (has_path) {
const char *url_path = given + u.field_data[UF_PATH].off;
size_t url_path_len = u.field_data[UF_PATH].len;
- git_buf_put(&path, url_path, url_path_len);
+ git_str_put(&path, url_path, url_path_len);
} else {
- git_buf_puts(&path, "/");
+ git_str_puts(&path, "/");
}
if (has_query) {
const char *url_query = given + u.field_data[UF_QUERY].off;
size_t url_query_len = u.field_data[UF_QUERY].len;
- git_buf_decode_percent(&query, url_query, url_query_len);
+ git_str_decode_percent(&query, url_query, url_query_len);
}
if (has_userinfo) {
@@ -156,40 +156,40 @@ int git_net_url_parse(git_net_url *url, const char *given)
const char *url_password = colon + 1;
size_t url_password_len = url_userinfo_len - (url_username_len + 1);
- git_buf_decode_percent(&username, url_username, url_username_len);
- git_buf_decode_percent(&password, url_password, url_password_len);
+ git_str_decode_percent(&username, url_username, url_username_len);
+ git_str_decode_percent(&password, url_password, url_password_len);
} else {
- git_buf_decode_percent(&username, url_userinfo, url_userinfo_len);
+ git_str_decode_percent(&username, url_userinfo, url_userinfo_len);
}
}
- if (git_buf_oom(&scheme) ||
- git_buf_oom(&host) ||
- git_buf_oom(&port) ||
- git_buf_oom(&path) ||
- git_buf_oom(&query) ||
- git_buf_oom(&username) ||
- git_buf_oom(&password))
+ if (git_str_oom(&scheme) ||
+ git_str_oom(&host) ||
+ git_str_oom(&port) ||
+ git_str_oom(&path) ||
+ git_str_oom(&query) ||
+ git_str_oom(&username) ||
+ git_str_oom(&password))
return -1;
- url->scheme = git_buf_detach(&scheme);
- url->host = git_buf_detach(&host);
- url->port = git_buf_detach(&port);
- url->path = git_buf_detach(&path);
- url->query = git_buf_detach(&query);
- url->username = git_buf_detach(&username);
- url->password = git_buf_detach(&password);
+ url->scheme = git_str_detach(&scheme);
+ url->host = git_str_detach(&host);
+ url->port = git_str_detach(&port);
+ url->path = git_str_detach(&path);
+ url->query = git_str_detach(&query);
+ url->username = git_str_detach(&username);
+ url->password = git_str_detach(&password);
error = 0;
done:
- git_buf_dispose(&scheme);
- git_buf_dispose(&host);
- git_buf_dispose(&port);
- git_buf_dispose(&path);
- git_buf_dispose(&query);
- git_buf_dispose(&username);
- git_buf_dispose(&password);
+ git_str_dispose(&scheme);
+ git_str_dispose(&host);
+ git_str_dispose(&port);
+ git_str_dispose(&path);
+ git_str_dispose(&query);
+ git_str_dispose(&username);
+ git_str_dispose(&password);
return error;
}
@@ -198,7 +198,7 @@ int git_net_url_joinpath(
git_net_url *one,
const char *two)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
const char *query;
size_t one_len, two_len;
@@ -226,14 +226,14 @@ int git_net_url_joinpath(
two_len--;
}
- git_buf_put(&path, one->path, one_len);
- git_buf_putc(&path, '/');
- git_buf_put(&path, two, two_len);
+ git_str_put(&path, one->path, one_len);
+ git_str_putc(&path, '/');
+ git_str_put(&path, two, two_len);
- if (git_buf_oom(&path))
+ if (git_str_oom(&path))
return -1;
- out->path = git_buf_detach(&path);
+ out->path = git_str_detach(&path);
if (one->scheme) {
out->scheme = git__strdup(one->scheme);
@@ -399,53 +399,53 @@ void git_net_url_swap(git_net_url *a, git_net_url *b)
memcpy(b, &tmp, sizeof(git_net_url));
}
-int git_net_url_fmt(git_buf *buf, git_net_url *url)
+int git_net_url_fmt(git_str *buf, git_net_url *url)
{
GIT_ASSERT_ARG(url);
GIT_ASSERT_ARG(url->scheme);
GIT_ASSERT_ARG(url->host);
- git_buf_puts(buf, url->scheme);
- git_buf_puts(buf, "://");
+ git_str_puts(buf, url->scheme);
+ git_str_puts(buf, "://");
if (url->username) {
- git_buf_puts(buf, url->username);
+ git_str_puts(buf, url->username);
if (url->password) {
- git_buf_puts(buf, ":");
- git_buf_puts(buf, url->password);
+ git_str_puts(buf, ":");
+ git_str_puts(buf, url->password);
}
- git_buf_putc(buf, '@');
+ git_str_putc(buf, '@');
}
- git_buf_puts(buf, url->host);
+ git_str_puts(buf, url->host);
if (url->port && !git_net_url_is_default_port(url)) {
- git_buf_putc(buf, ':');
- git_buf_puts(buf, url->port);
+ git_str_putc(buf, ':');
+ git_str_puts(buf, url->port);
}
- git_buf_puts(buf, url->path ? url->path : "/");
+ git_str_puts(buf, url->path ? url->path : "/");
if (url->query) {
- git_buf_putc(buf, '?');
- git_buf_puts(buf, url->query);
+ git_str_putc(buf, '?');
+ git_str_puts(buf, url->query);
}
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
-int git_net_url_fmt_path(git_buf *buf, git_net_url *url)
+int git_net_url_fmt_path(git_str *buf, git_net_url *url)
{
- git_buf_puts(buf, url->path ? url->path : "/");
+ git_str_puts(buf, url->path ? url->path : "/");
if (url->query) {
- git_buf_putc(buf, '?');
- git_buf_puts(buf, url->query);
+ git_str_putc(buf, '?');
+ git_str_puts(buf, url->query);
}
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
static bool matches_pattern(
diff --git a/src/net.h b/src/net.h
index 322d0bda9..728add3d0 100644
--- a/src/net.h
+++ b/src/net.h
@@ -52,10 +52,10 @@ extern int git_net_url_apply_redirect(
extern void git_net_url_swap(git_net_url *a, git_net_url *b);
/** Places the URL into the given buffer. */
-extern int git_net_url_fmt(git_buf *out, git_net_url *url);
+extern int git_net_url_fmt(git_str *out, git_net_url *url);
/** Place the path and query string into the given buffer. */
-extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url);
+extern int git_net_url_fmt_path(git_str *buf, git_net_url *url);
/** Determines if the url matches given pattern or pattern list */
extern bool git_net_url_matches_pattern(
diff --git a/src/netops.c b/src/netops.c
index a1ee2927c..0a27365b8 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -11,7 +11,7 @@
#include "git2/errors.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "http_parser.h"
#include "runtime.h"
diff --git a/src/notes.c b/src/notes.c
index 95db334fb..d1a2b0f64 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -7,7 +7,7 @@
#include "notes.h"
-#include "git2.h"
+#include "buf.h"
#include "refs.h"
#include "config.h"
#include "iterator.h"
@@ -407,7 +407,7 @@ cleanup:
return error;
}
-static int note_get_default_ref(git_buf *out, git_repository *repo)
+static int note_get_default_ref(git_str *out, git_repository *repo)
{
git_config *cfg;
int error;
@@ -415,25 +415,25 @@ static int note_get_default_ref(git_buf *out, git_repository *repo)
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
- error = git_config_get_string_buf(out, cfg, "core.notesref");
+ error = git_config__get_string_buf(out, cfg, "core.notesref");
if (error == GIT_ENOTFOUND)
- error = git_buf_puts(out, GIT_NOTES_DEFAULT_REF);
+ error = git_str_puts(out, GIT_NOTES_DEFAULT_REF);
return error;
}
-static int normalize_namespace(git_buf *out, git_repository *repo, const char *notes_ref)
+static int normalize_namespace(git_str *out, git_repository *repo, const char *notes_ref)
{
if (notes_ref)
- return git_buf_puts(out, notes_ref);
+ return git_str_puts(out, notes_ref);
return note_get_default_ref(out, repo);
}
static int retrieve_note_commit(
git_commit **commit_out,
- git_buf *notes_ref_out,
+ git_str *notes_ref_out,
git_repository *repo,
const char *notes_ref)
{
@@ -478,7 +478,7 @@ int git_note_read(git_note **out, git_repository *repo,
const char *notes_ref_in, const git_oid *oid)
{
int error;
- git_buf notes_ref = GIT_BUF_INIT;
+ git_str notes_ref = GIT_STR_INIT;
git_commit *commit = NULL;
error = retrieve_note_commit(&commit, &notes_ref, repo, notes_ref_in);
@@ -489,7 +489,7 @@ int git_note_read(git_note **out, git_repository *repo,
error = git_note_commit_read(out, repo, commit, oid);
cleanup:
- git_buf_dispose(&notes_ref);
+ git_str_dispose(&notes_ref);
git_commit_free(commit);
return error;
}
@@ -536,7 +536,7 @@ int git_note_create(
int allow_note_overwrite)
{
int error;
- git_buf notes_ref = GIT_BUF_INIT;
+ git_str notes_ref = GIT_STR_INIT;
git_commit *existing_notes_commit = NULL;
git_reference *ref = NULL;
git_oid notes_blob_oid, notes_commit_oid;
@@ -562,7 +562,7 @@ int git_note_create(
git_oid_cpy(out, &notes_blob_oid);
cleanup:
- git_buf_dispose(&notes_ref);
+ git_str_dispose(&notes_ref);
git_commit_free(existing_notes_commit);
git_reference_free(ref);
return error;
@@ -598,7 +598,7 @@ int git_note_remove(git_repository *repo, const char *notes_ref_in,
const git_oid *oid)
{
int error;
- git_buf notes_ref_target = GIT_BUF_INIT;
+ git_str notes_ref_target = GIT_STR_INIT;
git_commit *existing_notes_commit = NULL;
git_oid new_notes_commit;
git_reference *notes_ref = NULL;
@@ -618,7 +618,7 @@ int git_note_remove(git_repository *repo, const char *notes_ref_in,
&new_notes_commit, 1, NULL);
cleanup:
- git_buf_dispose(&notes_ref_target);
+ git_str_dispose(&notes_ref_target);
git_reference_free(notes_ref);
git_commit_free(existing_notes_commit);
return error;
@@ -626,16 +626,7 @@ cleanup:
int git_note_default_ref(git_buf *out, git_repository *repo)
{
- int error;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(repo);
-
- if ((error = git_buf_sanitize(out)) < 0 ||
- (error = note_get_default_ref(out, repo)) < 0)
- git_buf_dispose(out);
-
- return error;
+ GIT_BUF_WRAP_PRIVATE(out, note_get_default_ref, repo);
}
const git_signature *git_note_committer(const git_note *note)
@@ -679,12 +670,12 @@ static int process_entry_path(
{
int error = 0;
size_t i = 0, j = 0, len;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- if ((error = git_buf_puts(&buf, entry_path)) < 0)
+ if ((error = git_str_puts(&buf, entry_path)) < 0)
goto cleanup;
- len = git_buf_len(&buf);
+ len = git_str_len(&buf);
while (i < len) {
if (buf.ptr[i] == '/') {
@@ -715,7 +706,7 @@ static int process_entry_path(
error = git_oid_fromstr(annotated_object_id, buf.ptr);
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -780,7 +771,7 @@ int git_note_iterator_new(
{
int error;
git_commit *commit = NULL;
- git_buf notes_ref = GIT_BUF_INIT;
+ git_str notes_ref = GIT_STR_INIT;
error = retrieve_note_commit(&commit, &notes_ref, repo, notes_ref_in);
if (error < 0)
@@ -789,7 +780,7 @@ int git_note_iterator_new(
error = git_note_commit_iterator_new(it, commit);
cleanup:
- git_buf_dispose(&notes_ref);
+ git_str_dispose(&notes_ref);
git_commit_free(commit);
return error;
diff --git a/src/object.c b/src/object.c
index 42e1e46bc..fb861e9e1 100644
--- a/src/object.c
+++ b/src/object.c
@@ -11,6 +11,7 @@
#include "repository.h"
+#include "buf.h"
#include "commit.h"
#include "hash.h"
#include "tree.h"
@@ -491,7 +492,7 @@ cleanup:
return error;
}
-int git_object_short_id(git_buf *out, const git_object *obj)
+static int git_object__short_id(git_str *out, const git_object *obj)
{
git_repository *repo;
int len = GIT_ABBREV_DEFAULT, error;
@@ -501,9 +502,6 @@ int git_object_short_id(git_buf *out, const git_object *obj)
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(obj);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
repo = git_object_owner(obj);
if ((error = git_repository__configmap_lookup(&len, repo, GIT_CONFIGMAP_ABBREV)) < 0)
@@ -526,7 +524,7 @@ int git_object_short_id(git_buf *out, const git_object *obj)
len++;
}
- if (!error && !(error = git_buf_grow(out, len + 1))) {
+ if (!error && !(error = git_str_grow(out, len + 1))) {
git_oid_tostr(out->ptr, len + 1, &id);
out->size = len;
}
@@ -536,6 +534,11 @@ int git_object_short_id(git_buf *out, const git_object *obj)
return error;
}
+int git_object_short_id(git_buf *out, const git_object *obj)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_object__short_id, obj);
+}
+
bool git_object__is_valid(
git_repository *repo, const git_oid *id, git_object_t expected_type)
{
diff --git a/src/object.h b/src/object.h
index 4b6793612..66be57557 100644
--- a/src/object.h
+++ b/src/object.h
@@ -47,7 +47,7 @@ git_object_t git_object_stringn2type(const char *str, size_t len);
int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
-void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
+void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid);
bool git_object__is_valid(
git_repository *repo, const git_oid *id, git_object_t expected_type);
diff --git a/src/odb.c b/src/odb.c
index baa287348..7bf575474 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -109,7 +109,7 @@ int git_odb__format_object_header(
int git_odb__hashobj(git_oid *id, git_rawobj *obj)
{
- git_buf_vec vec[2];
+ git_str_vec vec[2];
char header[64];
size_t hdrlen;
int error;
@@ -248,7 +248,7 @@ int git_odb__hashfd_filtered(
git_oid *out, git_file fd, size_t size, git_object_t type, git_filter_list *fl)
{
int error;
- git_buf raw = GIT_BUF_INIT;
+ git_str raw = GIT_STR_INIT;
if (!fl)
return git_odb__hashfd(out, fd, size, type);
@@ -258,14 +258,14 @@ int git_odb__hashfd_filtered(
*/
if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) {
- git_buf post = GIT_BUF_INIT;
+ git_str post = GIT_STR_INIT;
error = git_filter_list__convert_buf(&post, fl, &raw);
if (!error)
error = git_odb_hash(out, post.ptr, post.size, type);
- git_buf_dispose(&post);
+ git_str_dispose(&post);
}
return error;
@@ -636,8 +636,8 @@ int git_odb__add_default_backends(
static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_depth)
{
- git_buf alternates_path = GIT_BUF_INIT;
- git_buf alternates_buf = GIT_BUF_INIT;
+ git_str alternates_path = GIT_STR_INIT;
+ git_str alternates_buf = GIT_STR_INIT;
char *buffer;
const char *alternate;
int result = 0;
@@ -646,16 +646,16 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
if (alternate_depth > GIT_ALTERNATES_MAX_DEPTH)
return 0;
- if (git_buf_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
+ if (git_str_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
return -1;
if (git_path_exists(alternates_path.ptr) == false) {
- git_buf_dispose(&alternates_path);
+ git_str_dispose(&alternates_path);
return 0;
}
if (git_futils_readbuffer(&alternates_buf, alternates_path.ptr) < 0) {
- git_buf_dispose(&alternates_path);
+ git_str_dispose(&alternates_path);
return -1;
}
@@ -672,17 +672,17 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
* the current repository.
*/
if (*alternate == '.' && !alternate_depth) {
- if ((result = git_buf_joinpath(&alternates_path, objects_dir, alternate)) < 0)
+ if ((result = git_str_joinpath(&alternates_path, objects_dir, alternate)) < 0)
break;
- alternate = git_buf_cstr(&alternates_path);
+ alternate = git_str_cstr(&alternates_path);
}
if ((result = git_odb__add_default_backends(odb, alternate, true, alternate_depth + 1)) < 0)
break;
}
- git_buf_dispose(&alternates_path);
- git_buf_dispose(&alternates_buf);
+ git_str_dispose(&alternates_path);
+ git_str_dispose(&alternates_buf);
return result;
}
@@ -1337,15 +1337,15 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
data = raw.data;
if (found && git_oid__cmp(&full_oid, &found_full_oid)) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_printf(&buf, "multiple matches for prefix: %s",
+ git_str_printf(&buf, "multiple matches for prefix: %s",
git_oid_tostr_s(&full_oid));
- git_buf_printf(&buf, " %s",
+ git_str_printf(&buf, " %s",
git_oid_tostr_s(&found_full_oid));
error = git_odb__error_ambiguous(buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_mutex_unlock(&db->lock);
goto out;
}
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 1f8a0bb21..f0c3ac2c8 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -76,17 +76,17 @@ typedef struct {
***********************************************************/
static int object_file_name(
- git_buf *name, const loose_backend *be, const git_oid *id)
+ git_str *name, const loose_backend *be, const git_oid *id)
{
size_t alloclen;
/* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_HEXSZ);
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3);
- if (git_buf_grow(name, alloclen) < 0)
+ if (git_str_grow(name, alloclen) < 0)
return -1;
- git_buf_set(name, be->objects_dir, be->objects_dirlen);
+ git_str_set(name, be->objects_dir, be->objects_dirlen);
git_path_to_dir(name);
/* loose object filename: aa/aaa... (41 bytes) */
@@ -97,7 +97,7 @@ static int object_file_name(
return 0;
}
-static int object_mkdir(const git_buf *name, const loose_backend *be)
+static int object_mkdir(const git_str *name, const loose_backend *be)
{
return git_futils_mkdir_relative(
name->ptr + be->objects_dirlen, be->objects_dir, be->object_dir_mode,
@@ -222,9 +222,9 @@ static int is_zlib_compressed_data(unsigned char *data, size_t data_len)
* of loose object data into packs. This format is no longer used, but
* we must still read it.
*/
-static int read_loose_packlike(git_rawobj *out, git_buf *obj)
+static int read_loose_packlike(git_rawobj *out, git_str *obj)
{
- git_buf body = GIT_BUF_INIT;
+ git_str body = GIT_STR_INIT;
const unsigned char *obj_data;
obj_hdr hdr;
size_t obj_len, head_len, alloc_size;
@@ -253,7 +253,7 @@ static int read_loose_packlike(git_rawobj *out, git_buf *obj)
* allocate a buffer and inflate the data into it
*/
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) ||
- git_buf_init(&body, alloc_size) < 0) {
+ git_str_init(&body, alloc_size) < 0) {
error = -1;
goto done;
}
@@ -263,14 +263,14 @@ static int read_loose_packlike(git_rawobj *out, git_buf *obj)
out->len = hdr.size;
out->type = hdr.type;
- out->data = git_buf_detach(&body);
+ out->data = git_str_detach(&body);
done:
- git_buf_dispose(&body);
+ git_str_dispose(&body);
return error;
}
-static int read_loose_standard(git_rawobj *out, git_buf *obj)
+static int read_loose_standard(git_rawobj *out, git_str *obj)
{
git_zstream zstream = GIT_ZSTREAM_INIT;
unsigned char head[MAX_HEADER_LEN], *body = NULL;
@@ -279,7 +279,7 @@ static int read_loose_standard(git_rawobj *out, git_buf *obj)
int error;
if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0 ||
- (error = git_zstream_set_input(&zstream, git_buf_cstr(obj), git_buf_len(obj))) < 0)
+ (error = git_zstream_set_input(&zstream, git_str_cstr(obj), git_str_len(obj))) < 0)
goto done;
decompressed = sizeof(head);
@@ -339,15 +339,15 @@ done:
return error;
}
-static int read_loose(git_rawobj *out, git_buf *loc)
+static int read_loose(git_rawobj *out, git_str *loc)
{
int error;
- git_buf obj = GIT_BUF_INIT;
+ git_str obj = GIT_STR_INIT;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(loc);
- if (git_buf_oom(loc))
+ if (git_str_oom(loc))
return -1;
out->data = NULL;
@@ -363,7 +363,7 @@ static int read_loose(git_rawobj *out, git_buf *loc)
error = read_loose_standard(out, &obj);
done:
- git_buf_dispose(&obj);
+ git_str_dispose(&obj);
return error;
}
@@ -406,7 +406,7 @@ done:
return error;
}
-static int read_header_loose(git_rawobj *out, git_buf *loc)
+static int read_header_loose(git_rawobj *out, git_str *loc)
{
unsigned char obj[1024];
ssize_t obj_len;
@@ -415,7 +415,7 @@ static int read_header_loose(git_rawobj *out, git_buf *loc)
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(loc);
- if (git_buf_oom(loc))
+ if (git_str_oom(loc))
return -1;
out->data = NULL;
@@ -446,7 +446,7 @@ done:
}
static int locate_object(
- git_buf *object_location,
+ git_str *object_location,
loose_backend *backend,
const git_oid *oid)
{
@@ -459,10 +459,10 @@ static int locate_object(
}
/* Explore an entry of a directory and see if it matches a short oid */
-static int fn_locate_object_short_oid(void *state, git_buf *pathbuf) {
+static int fn_locate_object_short_oid(void *state, git_str *pathbuf) {
loose_locate_object_state *sstate = (loose_locate_object_state *)state;
- if (git_buf_len(pathbuf) - sstate->dir_len != GIT_OID_HEXSZ - 2) {
+ if (git_str_len(pathbuf) - sstate->dir_len != GIT_OID_HEXSZ - 2) {
/* Entry cannot be an object. Continue to next entry */
return 0;
}
@@ -491,7 +491,7 @@ static int fn_locate_object_short_oid(void *state, git_buf *pathbuf) {
/* Locate an object matching a given short oid */
static int locate_object_short_oid(
- git_buf *object_location,
+ git_str *object_location,
git_oid *res_oid,
loose_backend *backend,
const git_oid *short_oid,
@@ -505,20 +505,20 @@ static int locate_object_short_oid(
/* prealloc memory for OBJ_DIR/xx/xx..38x..xx */
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3);
- if (git_buf_grow(object_location, alloc_len) < 0)
+ if (git_str_grow(object_location, alloc_len) < 0)
return -1;
- git_buf_set(object_location, objects_dir, dir_len);
+ git_str_set(object_location, objects_dir, dir_len);
git_path_to_dir(object_location);
/* save adjusted position at end of dir so it can be restored later */
- dir_len = git_buf_len(object_location);
+ dir_len = git_str_len(object_location);
/* Convert raw oid to hex formatted oid */
git_oid_fmt((char *)state.short_oid, short_oid);
/* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */
- if (git_buf_put(object_location, (char *)state.short_oid, 3) < 0)
+ if (git_str_put(object_location, (char *)state.short_oid, 3) < 0)
return -1;
object_location->ptr[object_location->size - 1] = '/';
@@ -527,7 +527,7 @@ static int locate_object_short_oid(
return git_odb__error_notfound("no matching loose object for prefix",
short_oid, len);
- state.dir_len = git_buf_len(object_location);
+ state.dir_len = git_str_len(object_location);
state.short_oid_len = len;
state.found = 0;
@@ -553,8 +553,8 @@ static int locate_object_short_oid(
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ);
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
- git_buf_truncate(object_location, dir_len);
- if (git_buf_grow(object_location, alloc_len) < 0)
+ git_str_truncate(object_location, dir_len);
+ if (git_str_grow(object_location, alloc_len) < 0)
return -1;
git_oid_pathfmt(object_location->ptr + dir_len, res_oid);
@@ -583,7 +583,7 @@ static int locate_object_short_oid(
static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_rawobj raw;
int error;
@@ -601,14 +601,14 @@ static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_o
*type_p = raw.type;
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_rawobj raw;
int error = 0;
@@ -624,7 +624,7 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *typ
*type_p = raw.type;
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
@@ -648,7 +648,7 @@ static int loose_backend__read_prefix(
if (!error)
git_oid_cpy(out_oid, short_oid);
} else {
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_rawobj raw;
GIT_ASSERT_ARG(backend && short_oid);
@@ -662,7 +662,7 @@ static int loose_backend__read_prefix(
*type_p = raw.type;
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
}
return error;
@@ -670,7 +670,7 @@ static int loose_backend__read_prefix(
static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(backend);
@@ -678,7 +678,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
error = locate_object(&object_path, (loose_backend *)backend, oid);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return !error;
}
@@ -686,7 +686,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
static int loose_backend__exists_prefix(
git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len)
{
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(backend);
@@ -697,7 +697,7 @@ static int loose_backend__exists_prefix(
error = locate_object_short_oid(
&object_path, out, (loose_backend *)backend, short_id, len);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
@@ -736,7 +736,7 @@ GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
return 0;
}
-static int foreach_object_dir_cb(void *_state, git_buf *path)
+static int foreach_object_dir_cb(void *_state, git_str *path)
{
git_oid oid;
struct foreach_state *state = (struct foreach_state *) _state;
@@ -748,12 +748,12 @@ static int foreach_object_dir_cb(void *_state, git_buf *path)
state->cb(&oid, state->data), "git_odb_foreach");
}
-static int foreach_cb(void *_state, git_buf *path)
+static int foreach_cb(void *_state, git_str *path)
{
struct foreach_state *state = (struct foreach_state *) _state;
/* non-dir is some stray file, ignore it */
- if (!git_path_isdir(git_buf_cstr(path)))
+ if (!git_path_isdir(git_str_cstr(path)))
return 0;
return git_path_direach(path, 0, foreach_object_dir_cb, state);
@@ -763,7 +763,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
{
char *objects_dir;
int error;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
struct foreach_state state;
loose_backend *backend = (loose_backend *) _backend;
@@ -772,19 +772,19 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
objects_dir = backend->objects_dir;
- git_buf_sets(&buf, objects_dir);
+ git_str_sets(&buf, objects_dir);
git_path_to_dir(&buf);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
memset(&state, 0, sizeof(state));
state.cb = cb;
state.data = data;
- state.dir_len = git_buf_len(&buf);
+ state.dir_len = git_str_len(&buf);
error = git_path_direach(&buf, 0, foreach_cb, &state);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -793,7 +793,7 @@ static int loose_backend__writestream_finalize(git_odb_stream *_stream, const gi
{
loose_writestream *stream = (loose_writestream *)_stream;
loose_backend *backend = (loose_backend *)_stream->backend;
- git_buf final_path = GIT_BUF_INIT;
+ git_str final_path = GIT_STR_INIT;
int error = 0;
if (object_file_name(&final_path, backend, oid) < 0 ||
@@ -803,7 +803,7 @@ static int loose_backend__writestream_finalize(git_odb_stream *_stream, const gi
error = git_filebuf_commit_at(
&stream->fbuf, final_path.ptr);
- git_buf_dispose(&final_path);
+ git_str_dispose(&final_path);
return error;
}
@@ -838,7 +838,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
loose_backend *backend;
loose_writestream *stream = NULL;
char hdr[MAX_HEADER_LEN];
- git_buf tmp_path = GIT_BUF_INIT;
+ git_str tmp_path = GIT_STR_INIT;
size_t hdrlen;
int error;
@@ -861,7 +861,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
stream->stream.free = &loose_backend__writestream_free;
stream->stream.mode = GIT_STREAM_WRONLY;
- if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
+ if (git_str_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend),
backend->object_file_mode) < 0 ||
stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0)
@@ -870,7 +870,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe
git__free(stream);
stream = NULL;
}
- git_buf_dispose(&tmp_path);
+ git_str_dispose(&tmp_path);
*stream_out = (git_odb_stream *)stream;
return !stream ? -1 : 0;
@@ -996,7 +996,7 @@ static int loose_backend__readstream(
loose_backend *backend;
loose_readstream *stream = NULL;
git_hash_ctx *hash_ctx = NULL;
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
obj_hdr hdr;
int error = 0;
@@ -1059,14 +1059,14 @@ done:
}
}
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, const void *data, size_t len, git_object_t type)
{
int error = 0;
- git_buf final_path = GIT_BUF_INIT;
+ git_str final_path = GIT_STR_INIT;
char header[MAX_HEADER_LEN];
size_t header_len;
git_filebuf fbuf = GIT_FILEBUF_INIT;
@@ -1079,7 +1079,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
header, sizeof(header), len, type)) < 0)
goto cleanup;
- if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
+ if (git_str_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend),
backend->object_file_mode) < 0)
{
@@ -1098,7 +1098,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
cleanup:
if (error < 0)
git_filebuf_cleanup(&fbuf);
- git_buf_dispose(&final_path);
+ git_str_dispose(&final_path);
return error;
}
@@ -1107,14 +1107,14 @@ static int loose_backend__freshen(
const git_oid *oid)
{
loose_backend *backend = (loose_backend *)_backend;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if (object_file_name(&path, backend, oid) < 0)
return -1;
error = git_futils_touch(path.ptr, NULL);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index d08356a8d..6f27f45f8 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -7,18 +7,20 @@
#include "common.h"
-#include "git2/object.h"
-#include "git2/sys/odb_backend.h"
-#include "git2/sys/mempack.h"
+#include "buf.h"
#include "futils.h"
#include "hash.h"
#include "odb.h"
#include "array.h"
#include "oidmap.h"
+#include "pack-objects.h"
#include "git2/odb_backend.h"
+#include "git2/object.h"
#include "git2/types.h"
#include "git2/pack.h"
+#include "git2/sys/odb_backend.h"
+#include "git2/sys/mempack.h"
struct memobject {
git_oid oid;
@@ -100,7 +102,10 @@ static int impl__read_header(size_t *len_p, git_object_t *type_p, git_odb_backen
return 0;
}
-int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *_backend)
+static int git_mempack__dump(
+ git_str *pack,
+ git_repository *repo,
+ git_odb_backend *_backend)
{
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
git_packbuilder *packbuilder;
@@ -120,13 +125,21 @@ int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *_back
goto cleanup;
}
- err = git_packbuilder_write_buf(pack, packbuilder);
+ err = git_packbuilder__write_buf(pack, packbuilder);
cleanup:
git_packbuilder_free(packbuilder);
return err;
}
+int git_mempack_dump(
+ git_buf *pack,
+ git_repository *repo,
+ git_odb_backend *_backend)
+{
+ GIT_BUF_WRAP_PRIVATE(pack, git_mempack__dump, repo, _backend);
+}
+
int git_mempack_reset(git_odb_backend *_backend)
{
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index f4cb9a558..f2c47adbe 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -166,7 +166,7 @@ struct pack_writepack {
static int packfile_sort__cb(const void *a_, const void *b_);
-static int packfile_load__cb(void *_data, git_buf *path);
+static int packfile_load__cb(void *_data, git_str *path);
static int packfile_byname_search_cmp(const void *path, const void *pack_entry);
@@ -195,10 +195,10 @@ static int pack_entry_find_prefix(
static int packfile_byname_search_cmp(const void *path_, const void *p_)
{
- const git_buf *path = (const git_buf *)path_;
+ const git_str *path = (const git_str *)path_;
const struct git_pack_file *p = (const struct git_pack_file *)p_;
- return strncmp(p->pack_name, git_buf_cstr(path), git_buf_len(path));
+ return strncmp(p->pack_name, git_str_cstr(path), git_str_len(path));
}
static int packfile_sort__cb(const void *a_, const void *b_)
@@ -231,20 +231,20 @@ static int packfile_sort__cb(const void *a_, const void *b_)
}
-static int packfile_load__cb(void *data, git_buf *path)
+static int packfile_load__cb(void *data, git_str *path)
{
struct pack_backend *backend = data;
struct git_pack_file *pack;
- const char *path_str = git_buf_cstr(path);
- git_buf index_prefix = GIT_BUF_INIT;
- size_t cmp_len = git_buf_len(path);
+ const char *path_str = git_str_cstr(path);
+ git_str index_prefix = GIT_STR_INIT;
+ size_t cmp_len = git_str_len(path);
int error;
if (cmp_len <= strlen(".idx") || git__suffixcmp(path_str, ".idx") != 0)
return 0; /* not an index */
cmp_len -= strlen(".idx");
- git_buf_attach_notowned(&index_prefix, path_str, cmp_len);
+ git_str_attach_notowned(&index_prefix, path_str, cmp_len);
if (git_vector_search2(NULL, &backend->midx_packs, packfile_byname_search_cmp, &index_prefix) == 0)
return 0;
@@ -404,29 +404,29 @@ static int process_multi_pack_index_pack(
int error;
struct git_pack_file *pack;
size_t found_position;
- git_buf pack_path = GIT_BUF_INIT, index_prefix = GIT_BUF_INIT;
+ git_str pack_path = GIT_STR_INIT, index_prefix = GIT_STR_INIT;
- error = git_buf_joinpath(&pack_path, backend->pack_folder, packfile_name);
+ error = git_str_joinpath(&pack_path, backend->pack_folder, packfile_name);
if (error < 0)
return error;
/* This is ensured by midx_parse_packfile_name() */
- if (git_buf_len(&pack_path) <= strlen(".idx") || git__suffixcmp(git_buf_cstr(&pack_path), ".idx") != 0)
+ if (git_str_len(&pack_path) <= strlen(".idx") || git__suffixcmp(git_str_cstr(&pack_path), ".idx") != 0)
return git_odb__error_notfound("midx file contained a non-index", NULL, 0);
- git_buf_attach_notowned(&index_prefix, git_buf_cstr(&pack_path), git_buf_len(&pack_path) - strlen(".idx"));
+ git_str_attach_notowned(&index_prefix, git_str_cstr(&pack_path), git_str_len(&pack_path) - strlen(".idx"));
if (git_vector_search2(&found_position, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0) {
/* Pack was found in the packs list. Moving it to the midx_packs list. */
- git_buf_dispose(&pack_path);
+ git_str_dispose(&pack_path);
git_vector_set(NULL, &backend->midx_packs, i, git_vector_get(&backend->packs, found_position));
git_vector_remove(&backend->packs, found_position);
return 0;
}
/* Pack was not found. Allocate a new one. */
- error = git_mwindow_get_pack(&pack, git_buf_cstr(&pack_path));
- git_buf_dispose(&pack_path);
+ error = git_mwindow_get_pack(&pack, git_str_cstr(&pack_path));
+ git_str_dispose(&pack_path);
if (error < 0)
return error;
@@ -442,11 +442,11 @@ static int process_multi_pack_index_pack(
static int refresh_multi_pack_index(struct pack_backend *backend)
{
int error;
- git_buf midx_path = GIT_BUF_INIT;
+ git_str midx_path = GIT_STR_INIT;
const char *packfile_name;
size_t i;
- error = git_buf_joinpath(&midx_path, backend->pack_folder, "multi-pack-index");
+ error = git_str_joinpath(&midx_path, backend->pack_folder, "multi-pack-index");
if (error < 0)
return error;
@@ -457,19 +457,19 @@ static int refresh_multi_pack_index(struct pack_backend *backend)
* refreshing the new multi-pack-index fails, or the file is deleted.
*/
if (backend->midx) {
- if (!git_midx_needs_refresh(backend->midx, git_buf_cstr(&midx_path))) {
- git_buf_dispose(&midx_path);
+ if (!git_midx_needs_refresh(backend->midx, git_str_cstr(&midx_path))) {
+ git_str_dispose(&midx_path);
return 0;
}
error = remove_multi_pack_index(backend);
if (error < 0) {
- git_buf_dispose(&midx_path);
+ git_str_dispose(&midx_path);
return error;
}
}
- error = git_midx_open(&backend->midx, git_buf_cstr(&midx_path));
- git_buf_dispose(&midx_path);
+ error = git_midx_open(&backend->midx, git_str_cstr(&midx_path));
+ git_str_dispose(&midx_path);
if (error < 0)
return error;
@@ -505,7 +505,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
{
int error;
struct stat st;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct pack_backend *backend = (struct pack_backend *)backend_;
if (backend->pack_folder == NULL)
@@ -523,10 +523,10 @@ static int pack_backend__refresh(git_odb_backend *backend_)
}
/* reload all packs */
- git_buf_sets(&path, backend->pack_folder);
+ git_str_sets(&path, backend->pack_folder);
error = git_path_direach(&path, 0, packfile_load__cb, backend);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_vector_sort(&backend->packs);
return error;
@@ -743,7 +743,7 @@ static int pack_backend__writepack(struct git_odb_writepack **out,
}
static int get_idx_path(
- git_buf *idx_path,
+ git_str *idx_path,
struct pack_backend *backend,
struct git_pack_file *p)
{
@@ -753,11 +753,11 @@ static int get_idx_path(
error = git_path_prettify(idx_path, p->pack_name, backend->pack_folder);
if (error < 0)
return error;
- path_len = git_buf_len(idx_path);
- if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(idx_path), ".pack") != 0)
+ path_len = git_str_len(idx_path);
+ if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(idx_path), ".pack") != 0)
return git_odb__error_notfound("packfile does not end in .pack", NULL, 0);
path_len -= strlen(".pack");
- error = git_buf_splice(idx_path, path_len, strlen(".pack"), ".idx", strlen(".idx"));
+ error = git_str_splice(idx_path, path_len, strlen(".pack"), ".idx", strlen(".idx"));
if (error < 0)
return error;
@@ -781,22 +781,22 @@ static int pack_backend__writemidx(git_odb_backend *_backend)
return error;
git_vector_foreach(&backend->midx_packs, i, p) {
- git_buf idx_path = GIT_BUF_INIT;
+ git_str idx_path = GIT_STR_INIT;
error = get_idx_path(&idx_path, backend, p);
if (error < 0)
goto cleanup;
- error = git_midx_writer_add(w, git_buf_cstr(&idx_path));
- git_buf_dispose(&idx_path);
+ error = git_midx_writer_add(w, git_str_cstr(&idx_path));
+ git_str_dispose(&idx_path);
if (error < 0)
goto cleanup;
}
git_vector_foreach(&backend->packs, i, p) {
- git_buf idx_path = GIT_BUF_INIT;
+ git_str idx_path = GIT_STR_INIT;
error = get_idx_path(&idx_path, backend, p);
if (error < 0)
goto cleanup;
- error = git_midx_writer_add(w, git_buf_cstr(&idx_path));
- git_buf_dispose(&idx_path);
+ error = git_midx_writer_add(w, git_str_cstr(&idx_path));
+ git_str_dispose(&idx_path);
if (error < 0)
goto cleanup;
}
@@ -896,15 +896,15 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
{
int error = 0;
struct pack_backend *backend = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (pack_backend__alloc(&backend, 8) < 0)
return -1;
- if (!(error = git_buf_joinpath(&path, objects_dir, "pack")) &&
- git_path_isdir(git_buf_cstr(&path)))
+ if (!(error = git_str_joinpath(&path, objects_dir, "pack")) &&
+ git_path_isdir(git_str_cstr(&path)))
{
- backend->pack_folder = git_buf_detach(&path);
+ backend->pack_folder = git_str_detach(&path);
error = pack_backend__refresh((git_odb_backend *)backend);
}
@@ -915,7 +915,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
*backend_out = (git_odb_backend *)backend;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
diff --git a/src/oid.c b/src/oid.c
index 893e2fc0f..dbc5a5a90 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -162,14 +162,14 @@ int git_oid__parse(
return 0;
}
-void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid)
+void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid)
{
char hex_oid[GIT_OID_HEXSZ];
git_oid_fmt(hex_oid, oid);
- git_buf_puts(buf, header);
- git_buf_put(buf, hex_oid, GIT_OID_HEXSZ);
- git_buf_putc(buf, '\n');
+ git_str_puts(buf, header);
+ git_str_put(buf, hex_oid, GIT_OID_HEXSZ);
+ git_str_putc(buf, '\n');
}
int git_oid_fromraw(git_oid *out, const unsigned char *raw)
diff --git a/src/pack-objects.c b/src/pack-objects.c
index d89a4e780..e5fc625a4 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -7,6 +7,7 @@
#include "pack-objects.h"
+#include "buf.h"
#include "zstream.h"
#include "delta.h"
#include "iterator.h"
@@ -33,7 +34,7 @@ struct unpacked {
struct tree_walk_context {
git_packbuilder *pb;
- git_buf buf;
+ git_str buf;
};
struct pack_write_context {
@@ -685,8 +686,8 @@ done:
static int write_pack_buf(void *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
static int type_size_sort(const void *_a, const void *_b)
@@ -947,7 +948,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
size_t *list_size, size_t window, size_t depth)
{
git_pobject *po;
- git_buf zbuf = GIT_BUF_INIT;
+ git_str zbuf = GIT_STR_INIT;
struct unpacked *array;
size_t idx = 0, count = 0;
size_t mem_usage = 0;
@@ -1045,7 +1046,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
memcpy(po->delta_data, zbuf.ptr, zbuf.size);
po->z_delta_size = zbuf.size;
- git_buf_clear(&zbuf);
+ git_str_clear(&zbuf);
GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
pb->delta_cache_size -= po->delta_size;
@@ -1093,7 +1094,7 @@ on_error:
git__free(array[i].data);
}
git__free(array);
- git_buf_dispose(&zbuf);
+ git_str_dispose(&zbuf);
return error;
}
@@ -1360,18 +1361,18 @@ int git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t siz
return write_pack(pb, cb, payload);
}
-int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
+int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb)
{
- int error;
-
- if ((error = git_buf_sanitize(buf)) < 0)
- return error;
-
PREPARE_PACK;
return write_pack(pb, &write_pack_buf, buf);
}
+int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
+{
+ GIT_BUF_WRAP_PRIVATE(buf, git_packbuilder__write_buf, pb);
+}
+
static int write_cb(void *buf, size_t len, void *payload)
{
struct pack_write_context *ctx = payload;
@@ -1386,7 +1387,7 @@ int git_packbuilder_write(
void *progress_cb_payload)
{
int error = -1;
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *indexer = NULL;
git_indexer_progress stats;
@@ -1396,11 +1397,11 @@ int git_packbuilder_write(
PREPARE_PACK;
if (path == NULL) {
- if ((error = git_repository_item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
+ if ((error = git_repository__item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
goto cleanup;
- if ((error = git_buf_joinpath(&object_path, git_buf_cstr(&object_path), "pack")) < 0)
+ if ((error = git_str_joinpath(&object_path, git_str_cstr(&object_path), "pack")) < 0)
goto cleanup;
- path = git_buf_cstr(&object_path);
+ path = git_str_cstr(&object_path);
}
opts.progress_cb = progress_cb;
@@ -1425,7 +1426,7 @@ int git_packbuilder_write(
cleanup:
git_indexer_free(indexer);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
@@ -1447,10 +1448,10 @@ static int cb_tree_walk(
if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT)
return 0;
- if (!(error = git_buf_sets(&ctx->buf, root)) &&
- !(error = git_buf_puts(&ctx->buf, git_tree_entry_name(entry))))
+ if (!(error = git_str_sets(&ctx->buf, root)) &&
+ !(error = git_str_puts(&ctx->buf, git_tree_entry_name(entry))))
error = git_packbuilder_insert(
- ctx->pb, git_tree_entry_id(entry), git_buf_cstr(&ctx->buf));
+ ctx->pb, git_tree_entry_id(entry), git_str_cstr(&ctx->buf));
return error;
}
@@ -1474,14 +1475,14 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
{
int error;
git_tree *tree = NULL;
- struct tree_walk_context context = { pb, GIT_BUF_INIT };
+ struct tree_walk_context context = { pb, GIT_STR_INIT };
if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
!(error = git_packbuilder_insert(pb, oid, NULL)))
error = git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, &context);
git_tree_free(tree);
- git_buf_dispose(&context.buf);
+ git_str_dispose(&context.buf);
return error;
}
diff --git a/src/pack-objects.h b/src/pack-objects.h
index 04514daa6..db2038b0a 100644
--- a/src/pack-objects.h
+++ b/src/pack-objects.h
@@ -10,7 +10,7 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "hash.h"
#include "oidmap.h"
#include "netops.h"
@@ -96,6 +96,6 @@ struct git_packbuilder {
bool done;
};
-int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb);
+int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb);
#endif
diff --git a/src/pack.c b/src/pack.c
index aadf3f2be..e17d20f8c 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -308,7 +308,7 @@ static int pack_index_open_locked(struct git_pack_file *p)
{
int error = 0;
size_t name_len;
- git_buf idx_name = GIT_BUF_INIT;
+ git_str idx_name = GIT_STR_INIT;
if (p->index_version > -1)
goto cleanup;
@@ -317,12 +317,12 @@ static int pack_index_open_locked(struct git_pack_file *p)
name_len = strlen(p->pack_name);
GIT_ASSERT(name_len > strlen(".pack"));
- if ((error = git_buf_init(&idx_name, name_len)) < 0)
+ if ((error = git_str_init(&idx_name, name_len)) < 0)
goto cleanup;
- git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
- git_buf_puts(&idx_name, ".idx");
- if (git_buf_oom(&idx_name)) {
+ git_str_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
+ git_str_puts(&idx_name, ".idx");
+ if (git_str_oom(&idx_name)) {
error = -1;
goto cleanup;
}
@@ -331,7 +331,7 @@ static int pack_index_open_locked(struct git_pack_file *p)
error = pack_index_check_locked(idx_name.ptr, p);
cleanup:
- git_buf_dispose(&idx_name);
+ git_str_dispose(&idx_name);
return error;
}
@@ -1156,17 +1156,17 @@ cleanup:
int git_packfile__name(char **out, const char *path)
{
size_t path_len;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
path_len = strlen(path);
if (path_len < strlen(".idx"))
return git_odb__error_notfound("invalid packfile path", NULL, 0);
- if (git_buf_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
+ if (git_str_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
return -1;
- *out = git_buf_detach(&buf);
+ *out = git_str_detach(&buf);
return 0;
}
diff --git a/src/patch.c b/src/patch.c
index f02c928de..a30546f3c 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -76,15 +76,15 @@ size_t git_patch_size(
out += patch->header_size;
if (include_file_headers) {
- git_buf file_header = GIT_BUF_INIT;
+ git_str file_header = GIT_STR_INIT;
if (git_diff_delta__format_file_header(
&file_header, patch->delta, NULL, NULL, 0, true) < 0)
git_error_clear();
else
- out += git_buf_len(&file_header);
+ out += git_str_len(&file_header);
- git_buf_dispose(&file_header);
+ git_str_dispose(&file_header);
}
return out;
diff --git a/src/patch.h b/src/patch.h
index 156d1310e..1e1471ed6 100644
--- a/src/patch.h
+++ b/src/patch.h
@@ -63,6 +63,7 @@ typedef struct {
#define GIT_PATCH_OPTIONS_INIT { 1 }
+extern int git_patch__to_buf(git_str *out, git_patch *patch);
extern void git_patch_free(git_patch *patch);
#endif
diff --git a/src/patch_generate.c b/src/patch_generate.c
index 38cd714a9..6d115affe 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -261,7 +261,7 @@ static int create_binary(
const char *b_data,
size_t b_datalen)
{
- git_buf deflate = GIT_BUF_INIT, delta = GIT_BUF_INIT;
+ git_str deflate = GIT_STR_INIT, delta = GIT_STR_INIT;
size_t delta_data_len = 0;
int error;
@@ -302,18 +302,18 @@ static int create_binary(
if (delta.size && delta.size < deflate.size) {
*out_type = GIT_DIFF_BINARY_DELTA;
*out_datalen = delta.size;
- *out_data = git_buf_detach(&delta);
+ *out_data = git_str_detach(&delta);
*out_inflatedlen = delta_data_len;
} else {
*out_type = GIT_DIFF_BINARY_LITERAL;
*out_datalen = deflate.size;
- *out_data = git_buf_detach(&deflate);
+ *out_data = git_str_detach(&deflate);
*out_inflatedlen = b_datalen;
}
done:
- git_buf_dispose(&deflate);
- git_buf_dispose(&delta);
+ git_str_dispose(&deflate);
+ git_str_dispose(&delta);
return error;
}
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 2cc5c5995..fce4bc9e4 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -65,19 +65,19 @@ static size_t header_path_len(git_patch_parse_ctx *ctx)
return len;
}
-static int parse_header_path_buf(git_buf *path, git_patch_parse_ctx *ctx, size_t path_len)
+static int parse_header_path_buf(git_str *path, git_patch_parse_ctx *ctx, size_t path_len)
{
int error;
- if ((error = git_buf_put(path, ctx->parse_ctx.line, path_len)) < 0)
+ if ((error = git_str_put(path, ctx->parse_ctx.line, path_len)) < 0)
return error;
git_parse_advance_chars(&ctx->parse_ctx, path_len);
- git_buf_rtrim(path);
+ git_str_rtrim(path);
if (path->size > 0 && path->ptr[0] == '"' &&
- (error = git_buf_unquote(path)) < 0)
+ (error = git_str_unquote(path)) < 0)
return error;
git_path_squash_slashes(path);
@@ -91,22 +91,22 @@ static int parse_header_path_buf(git_buf *path, git_patch_parse_ctx *ctx, size_t
static int parse_header_path(char **out, git_patch_parse_ctx *ctx)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if ((error = parse_header_path_buf(&path, ctx, header_path_len(ctx))) < 0)
goto out;
- *out = git_buf_detach(&path);
+ *out = git_str_detach(&path);
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
static int parse_header_git_oldpath(
git_patch_parsed *patch, git_patch_parse_ctx *ctx)
{
- git_buf old_path = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT;
int error;
if (patch->old_path) {
@@ -118,17 +118,17 @@ static int parse_header_git_oldpath(
if ((error = parse_header_path_buf(&old_path, ctx, ctx->parse_ctx.line_len - 1)) < 0)
goto out;
- patch->old_path = git_buf_detach(&old_path);
+ patch->old_path = git_str_detach(&old_path);
out:
- git_buf_dispose(&old_path);
+ git_str_dispose(&old_path);
return error;
}
static int parse_header_git_newpath(
git_patch_parsed *patch, git_patch_parse_ctx *ctx)
{
- git_buf new_path = GIT_BUF_INIT;
+ git_str new_path = GIT_STR_INIT;
int error;
if (patch->new_path) {
@@ -139,10 +139,10 @@ static int parse_header_git_newpath(
if ((error = parse_header_path_buf(&new_path, ctx, ctx->parse_ctx.line_len - 1)) < 0)
goto out;
- patch->new_path = git_buf_detach(&new_path);
+ patch->new_path = git_str_detach(&new_path);
out:
- git_buf_dispose(&new_path);
+ git_str_dispose(&new_path);
return error;
}
@@ -257,7 +257,7 @@ static int parse_header_rename(
char **out,
git_patch_parse_ctx *ctx)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (parse_header_path_buf(&path, ctx, header_path_len(ctx)) < 0)
return -1;
@@ -265,7 +265,7 @@ static int parse_header_rename(
/* Note: the `rename from` and `rename to` lines include the literal
* filename. They do *not* include the prefix. (Who needs consistency?)
*/
- *out = git_buf_detach(&path);
+ *out = git_str_detach(&path);
return 0;
}
@@ -766,7 +766,7 @@ static int parse_patch_binary_side(
git_patch_parse_ctx *ctx)
{
git_diff_binary_t type = GIT_DIFF_BINARY_NONE;
- git_buf base85 = GIT_BUF_INIT, decoded = GIT_BUF_INIT;
+ git_str base85 = GIT_STR_INIT, decoded = GIT_STR_INIT;
int64_t len;
int error = 0;
@@ -815,7 +815,7 @@ static int parse_patch_binary_side(
goto done;
}
- if ((error = git_buf_decode_base85(
+ if ((error = git_str_decode_base85(
&decoded, ctx->parse_ctx.line, encoded_len, decoded_len)) < 0)
goto done;
@@ -835,11 +835,11 @@ static int parse_patch_binary_side(
binary->type = type;
binary->inflatedlen = (size_t)len;
binary->datalen = decoded.size;
- binary->data = git_buf_detach(&decoded);
+ binary->data = git_str_detach(&decoded);
done:
- git_buf_dispose(&base85);
- git_buf_dispose(&decoded);
+ git_str_dispose(&base85);
+ git_str_dispose(&decoded);
return error;
}
diff --git a/src/path.c b/src/path.c
index c444b31a7..d8d33a141 100644
--- a/src/path.c
+++ b/src/path.c
@@ -93,7 +93,7 @@ static bool looks_like_network_computer_name(const char *path, int pos)
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-int git_path_basename_r(git_buf *buffer, const char *path)
+int git_path_basename_r(git_str *buffer, const char *path)
{
const char *endp, *startp;
int len, result;
@@ -128,7 +128,7 @@ int git_path_basename_r(git_buf *buffer, const char *path)
Exit:
result = len;
- if (buffer != NULL && git_buf_set(buffer, startp, len) < 0)
+ if (buffer != NULL && git_str_set(buffer, startp, len) < 0)
return -1;
return result;
@@ -166,7 +166,7 @@ static int win32_prefix_length(const char *path, int len)
* Based on the Android implementation, BSD licensed.
* Check http://android.git.kernel.org/
*/
-int git_path_dirname_r(git_buf *buffer, const char *path)
+int git_path_dirname_r(git_str *buffer, const char *path)
{
const char *endp;
int is_prefix = 0, len;
@@ -225,9 +225,9 @@ int git_path_dirname_r(git_buf *buffer, const char *path)
Exit:
if (buffer) {
- if (git_buf_set(buffer, path, len) < 0)
+ if (git_str_set(buffer, path, len) < 0)
return -1;
- if (is_prefix && git_buf_putc(buffer, '/') < 0)
+ if (is_prefix && git_str_putc(buffer, '/') < 0)
return -1;
}
@@ -237,36 +237,36 @@ Exit:
char *git_path_dirname(const char *path)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *dirname;
git_path_dirname_r(&buf, path);
- dirname = git_buf_detach(&buf);
- git_buf_dispose(&buf); /* avoid memleak if error occurs */
+ dirname = git_str_detach(&buf);
+ git_str_dispose(&buf); /* avoid memleak if error occurs */
return dirname;
}
char *git_path_basename(const char *path)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *basename;
git_path_basename_r(&buf, path);
- basename = git_buf_detach(&buf);
- git_buf_dispose(&buf); /* avoid memleak if error occurs */
+ basename = git_str_detach(&buf);
+ git_str_dispose(&buf); /* avoid memleak if error occurs */
return basename;
}
-size_t git_path_basename_offset(git_buf *buffer)
+size_t git_path_basename_offset(git_str *buffer)
{
ssize_t slash;
if (!buffer || buffer->size <= 0)
return 0;
- slash = git_buf_rfind_next(buffer, '/');
+ slash = git_str_rfind_next(buffer, '/');
if (slash >= 0 && buffer->ptr[slash] == '/')
return (size_t)(slash + 1);
@@ -304,7 +304,7 @@ int git_path_root(const char *path)
return -1; /* Not a real error - signals that path is not rooted */
}
-static void path_trim_slashes(git_buf *path)
+static void path_trim_slashes(git_str *path)
{
int ceiling = git_path_root(path->ptr) + 1;
@@ -321,7 +321,7 @@ static void path_trim_slashes(git_buf *path)
}
int git_path_join_unrooted(
- git_buf *path_out, const char *path, const char *base, ssize_t *root_at)
+ git_str *path_out, const char *path, const char *base, ssize_t *root_at)
{
ssize_t root;
@@ -331,12 +331,12 @@ int git_path_join_unrooted(
root = (ssize_t)git_path_root(path);
if (base != NULL && root < 0) {
- if (git_buf_joinpath(path_out, base, path) < 0)
+ if (git_str_joinpath(path_out, base, path) < 0)
return -1;
root = (ssize_t)strlen(base);
} else {
- if (git_buf_sets(path_out, path) < 0)
+ if (git_str_sets(path_out, path) < 0)
return -1;
if (root < 0)
@@ -351,7 +351,7 @@ int git_path_join_unrooted(
return 0;
}
-void git_path_squash_slashes(git_buf *path)
+void git_path_squash_slashes(git_str *path)
{
char *p, *q;
@@ -370,7 +370,7 @@ void git_path_squash_slashes(git_buf *path)
*p = '\0';
}
-int git_path_prettify(git_buf *path_out, const char *path, const char *base)
+int git_path_prettify(git_str *path_out, const char *path, const char *base)
{
char buf[GIT_PATH_MAX];
@@ -379,7 +379,7 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
/* construct path if needed */
if (base != NULL && git_path_root(path) < 0) {
- if (git_buf_joinpath(path_out, base, path) < 0)
+ if (git_str_joinpath(path_out, base, path) < 0)
return -1;
path = path_out->ptr;
}
@@ -389,28 +389,28 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path);
- git_buf_clear(path_out);
+ git_str_clear(path_out);
return error;
}
- return git_buf_sets(path_out, buf);
+ return git_str_sets(path_out, buf);
}
-int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base)
+int git_path_prettify_dir(git_str *path_out, const char *path, const char *base)
{
int error = git_path_prettify(path_out, path, base);
return (error < 0) ? error : git_path_to_dir(path_out);
}
-int git_path_to_dir(git_buf *path)
+int git_path_to_dir(git_str *path)
{
if (path->asize > 0 &&
- git_buf_len(path) > 0 &&
- path->ptr[git_buf_len(path) - 1] != '/')
- git_buf_putc(path, '/');
+ git_str_len(path) > 0 &&
+ path->ptr[git_str_len(path) - 1] != '/')
+ git_str_putc(path, '/');
- return git_buf_oom(path) ? -1 : 0;
+ return git_str_oom(path) ? -1 : 0;
}
void git_path_string_to_dir(char *path, size_t size)
@@ -423,7 +423,7 @@ void git_path_string_to_dir(char *path, size_t size)
}
}
-int git__percent_decode(git_buf *decoded_out, const char *input)
+int git__percent_decode(git_str *decoded_out, const char *input)
{
int len, hi, lo, i;
@@ -431,7 +431,7 @@ int git__percent_decode(git_buf *decoded_out, const char *input)
GIT_ASSERT_ARG(input);
len = (int)strlen(input);
- git_buf_clear(decoded_out);
+ git_str_clear(decoded_out);
for(i = 0; i < len; i++)
{
@@ -453,7 +453,7 @@ int git__percent_decode(git_buf *decoded_out, const char *input)
i += 2;
append:
- if (git_buf_putc(decoded_out, c) < 0)
+ if (git_str_putc(decoded_out, c) < 0)
return -1;
}
@@ -485,7 +485,7 @@ bool git_path_is_local_file_url(const char *file_url)
return (local_file_url_prefixlen(file_url) > 0);
}
-int git_path_fromurl(git_buf *local_path_out, const char *file_url)
+int git_path_fromurl(git_str *local_path_out, const char *file_url)
{
int offset;
@@ -500,18 +500,18 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url)
offset--; /* A *nix absolute path starts with a forward slash */
#endif
- git_buf_clear(local_path_out);
+ git_str_clear(local_path_out);
return git__percent_decode(local_path_out, file_url + offset);
}
int git_path_walk_up(
- git_buf *path,
+ git_str *path,
const char *ceiling,
int (*cb)(void *data, const char *),
void *data)
{
int error = 0;
- git_buf iter;
+ git_str iter;
ssize_t stop = 0, scan;
char oldc = '\0';
@@ -522,9 +522,9 @@ int git_path_walk_up(
if (git__prefixcmp(path->ptr, ceiling) == 0)
stop = (ssize_t)strlen(ceiling);
else
- stop = git_buf_len(path);
+ stop = git_str_len(path);
}
- scan = git_buf_len(path);
+ scan = git_str_len(path);
/* empty path: yield only once */
if (!scan) {
@@ -535,7 +535,7 @@ int git_path_walk_up(
}
iter.ptr = path->ptr;
- iter.size = git_buf_len(path);
+ iter.size = git_str_len(path);
iter.asize = path->asize;
while (scan >= stop) {
@@ -547,7 +547,7 @@ int git_path_walk_up(
break;
}
- scan = git_buf_rfind_next(&iter, '/');
+ scan = git_str_rfind_next(&iter, '/');
if (scan >= 0) {
scan++;
oldc = iter.ptr[scan];
@@ -651,7 +651,7 @@ bool git_path_is_empty_dir(const char *path)
#else
-static int path_found_entry(void *payload, git_buf *path)
+static int path_found_entry(void *payload, git_str *path)
{
GIT_UNUSED(payload);
return !git_path_is_dot_or_dotdot(path->ptr);
@@ -660,17 +660,17 @@ static int path_found_entry(void *payload, git_buf *path)
bool git_path_is_empty_dir(const char *path)
{
int error;
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
if (!git_path_isdir(path))
return false;
- if ((error = git_buf_sets(&dir, path)) != 0)
+ if ((error = git_str_sets(&dir, path)) != 0)
git_error_clear();
else
error = git_path_direach(&dir, 0, path_found_entry, NULL);
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
return !error;
}
@@ -713,54 +713,54 @@ int git_path_lstat(const char *path, struct stat *st)
}
static bool _check_dir_contents(
- git_buf *dir,
+ git_str *dir,
const char *sub,
bool (*predicate)(const char *))
{
bool result;
- size_t dir_size = git_buf_len(dir);
+ size_t dir_size = git_str_len(dir);
size_t sub_size = strlen(sub);
size_t alloc_size;
/* leave base valid even if we could not make space for subdir */
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) ||
- git_buf_try_grow(dir, alloc_size, false) < 0)
+ git_str_try_grow(dir, alloc_size, false) < 0)
return false;
/* save excursion */
- if (git_buf_joinpath(dir, dir->ptr, sub) < 0)
+ if (git_str_joinpath(dir, dir->ptr, sub) < 0)
return false;
result = predicate(dir->ptr);
/* restore path */
- git_buf_truncate(dir, dir_size);
+ git_str_truncate(dir, dir_size);
return result;
}
-bool git_path_contains(git_buf *dir, const char *item)
+bool git_path_contains(git_str *dir, const char *item)
{
return _check_dir_contents(dir, item, &git_path_exists);
}
-bool git_path_contains_dir(git_buf *base, const char *subdir)
+bool git_path_contains_dir(git_str *base, const char *subdir)
{
return _check_dir_contents(base, subdir, &git_path_isdir);
}
-bool git_path_contains_file(git_buf *base, const char *file)
+bool git_path_contains_file(git_str *base, const char *file)
{
return _check_dir_contents(base, file, &git_path_isfile);
}
-int git_path_find_dir(git_buf *dir)
+int git_path_find_dir(git_str *dir)
{
int error = 0;
char buf[GIT_PATH_MAX];
if (p_realpath(dir->ptr, buf) != NULL)
- error = git_buf_sets(dir, buf);
+ error = git_str_sets(dir, buf);
/* call dirname if this is not a directory */
if (!error) /* && git_path_isdir(dir->ptr) == false) */
@@ -772,12 +772,12 @@ int git_path_find_dir(git_buf *dir)
return error;
}
-int git_path_resolve_relative(git_buf *path, size_t ceiling)
+int git_path_resolve_relative(git_str *path, size_t ceiling)
{
char *base, *to, *from, *next;
size_t len;
- GIT_ERROR_CHECK_ALLOC_BUF(path);
+ GIT_ERROR_CHECK_ALLOC_STR(path);
if (ceiling > path->size)
ceiling = path->size;
@@ -851,9 +851,9 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
return 0;
}
-int git_path_apply_relative(git_buf *target, const char *relpath)
+int git_path_apply_relative(git_str *target, const char *relpath)
{
- return git_buf_joinpath(target, git_buf_cstr(target), relpath) ||
+ return git_str_joinpath(target, git_str_cstr(target), relpath) ||
git_path_resolve_relative(target, 0);
}
@@ -896,7 +896,7 @@ size_t git_path_common_dirlen(const char *one, const char *two)
return dirsep ? (dirsep - one) + 1 : 0;
}
-int git_path_make_relative(git_buf *path, const char *parent)
+int git_path_make_relative(git_str *path, const char *parent)
{
const char *p, *q, *p_dirsep, *q_dirsep;
size_t plen = path->size, newlen, alloclen, depth = 1, i, offset;
@@ -923,7 +923,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
else if (!*p && *q == '/')
q++;
else if (!*p && !*q)
- return git_buf_clear(path), 0;
+ return git_str_clear(path), 0;
else {
p = p_dirsep + 1;
q = q_dirsep + 1;
@@ -932,7 +932,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
plen -= (p - path->ptr);
if (!*q)
- return git_buf_set(path, p, plen);
+ return git_str_set(path, p, plen);
for (; (q = strchr(q, '/')) && *(q + 1); q++)
depth++;
@@ -944,7 +944,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
/* save the offset as we might realllocate the pointer */
offset = p - path->ptr;
- if (git_buf_try_grow(path, alloclen, 1) < 0)
+ if (git_str_try_grow(path, alloclen, 1) < 0)
return -1;
p = path->ptr + offset;
@@ -972,7 +972,7 @@ bool git_path_has_non_ascii(const char *path, size_t pathlen)
int git_path_iconv_init_precompose(git_path_iconv_t *ic)
{
- git_buf_init(&ic->buf, 0);
+ git_str_init(&ic->buf, 0);
ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING);
return 0;
}
@@ -982,7 +982,7 @@ void git_path_iconv_clear(git_path_iconv_t *ic)
if (ic) {
if (ic->map != (iconv_t)-1)
iconv_close(ic->map);
- git_buf_dispose(&ic->buf);
+ git_str_dispose(&ic->buf);
}
}
@@ -996,11 +996,11 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen)
!git_path_has_non_ascii(*in, *inlen))
return 0;
- git_buf_clear(&ic->buf);
+ git_str_clear(&ic->buf);
while (1) {
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1);
- if (git_buf_grow(&ic->buf, alloclen) < 0)
+ if (git_str_grow(&ic->buf, alloclen) < 0)
return -1;
nfc = ic->buf.ptr + ic->buf.size;
@@ -1054,7 +1054,7 @@ static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX";
*/
bool git_path_does_fs_decompose_unicode(const char *root)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fd;
bool found_decomposed = false;
char tmp[6];
@@ -1063,7 +1063,7 @@ bool git_path_does_fs_decompose_unicode(const char *root)
* using the decomposed name. If the lookup fails, then we will mark
* that we should precompose unicode for this repository.
*/
- if (git_buf_joinpath(&path, root, nfc_file) < 0 ||
+ if (git_str_joinpath(&path, root, nfc_file) < 0 ||
(fd = p_mkstemp(path.ptr)) < 0)
goto done;
p_close(fd);
@@ -1072,21 +1072,21 @@ bool git_path_does_fs_decompose_unicode(const char *root)
memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp));
/* try to look up as NFD path */
- if (git_buf_joinpath(&path, root, nfd_file) < 0)
+ if (git_str_joinpath(&path, root, nfd_file) < 0)
goto done;
memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
found_decomposed = git_path_exists(path.ptr);
/* remove temporary file (using original precomposed path) */
- if (git_buf_joinpath(&path, root, nfc_file) < 0)
+ if (git_str_joinpath(&path, root, nfc_file) < 0)
goto done;
memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp));
(void)p_unlink(path.ptr);
done:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return found_decomposed;
}
@@ -1107,9 +1107,9 @@ typedef struct dirent path_dirent_data;
#endif
int git_path_direach(
- git_buf *path,
+ git_str *path,
uint32_t flags,
- int (*fn)(void *, git_buf *),
+ int (*fn)(void *, git_str *),
void *arg)
{
int error = 0;
@@ -1126,7 +1126,7 @@ int git_path_direach(
if (git_path_to_dir(path) < 0)
return -1;
- wd_len = git_buf_len(path);
+ wd_len = git_str_len(path);
if ((dir = opendir(path->ptr)) == NULL) {
git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr);
@@ -1153,13 +1153,13 @@ int git_path_direach(
break;
#endif
- if ((error = git_buf_put(path, de_path, de_len)) < 0)
+ if ((error = git_str_put(path, de_path, de_len)) < 0)
break;
git_error_clear();
error = fn(arg, path);
- git_buf_truncate(path, wd_len); /* restore path */
+ git_str_truncate(path, wd_len); /* restore path */
/* Only set our own error if the callback did not set one already */
if (error != 0) {
@@ -1205,7 +1205,7 @@ int git_path_diriter_init(
memset(diriter, 0, sizeof(git_path_diriter));
diriter->handle = INVALID_HANDLE_VALUE;
- if (git_buf_puts(&diriter->path_utf8, path) < 0)
+ if (git_str_puts(&diriter->path_utf8, path) < 0)
return -1;
path_trim_slashes(&diriter->path_utf8);
@@ -1261,15 +1261,15 @@ static int diriter_update_paths(git_path_diriter *diriter)
diriter->current.cFileName, filename_len * sizeof(wchar_t));
diriter->path[path_len-1] = L'\0';
- git_buf_truncate(&diriter->path_utf8, diriter->parent_utf8_len);
+ git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len);
if (diriter->parent_utf8_len > 0 &&
diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/')
- git_buf_putc(&diriter->path_utf8, '/');
+ git_str_putc(&diriter->path_utf8, '/');
- git_buf_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len);
+ git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len);
- if (git_buf_oom(&diriter->path_utf8))
+ if (git_str_oom(&diriter->path_utf8))
return -1;
return 0;
@@ -1339,7 +1339,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
if (diriter == NULL)
return;
- git_buf_dispose(&diriter->path_utf8);
+ git_str_dispose(&diriter->path_utf8);
if (diriter->handle != INVALID_HANDLE_VALUE) {
FindClose(diriter->handle);
@@ -1359,7 +1359,7 @@ int git_path_diriter_init(
memset(diriter, 0, sizeof(git_path_diriter));
- if (git_buf_puts(&diriter->path, path) < 0)
+ if (git_str_puts(&diriter->path, path) < 0)
return -1;
path_trim_slashes(&diriter->path);
@@ -1370,7 +1370,7 @@ int git_path_diriter_init(
}
if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
- git_buf_dispose(&diriter->path);
+ git_str_dispose(&diriter->path);
git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path);
return -1;
@@ -1419,15 +1419,15 @@ int git_path_diriter_next(git_path_diriter *diriter)
return error;
#endif
- git_buf_truncate(&diriter->path, diriter->parent_len);
+ git_str_truncate(&diriter->path, diriter->parent_len);
if (diriter->parent_len > 0 &&
diriter->path.ptr[diriter->parent_len-1] != '/')
- git_buf_putc(&diriter->path, '/');
+ git_str_putc(&diriter->path, '/');
- git_buf_put(&diriter->path, filename, filename_len);
+ git_str_put(&diriter->path, filename, filename_len);
- if (git_buf_oom(&diriter->path))
+ if (git_str_oom(&diriter->path))
return -1;
return error;
@@ -1484,7 +1484,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
git_path_iconv_clear(&diriter->ic);
#endif
- git_buf_dispose(&diriter->path);
+ git_str_dispose(&diriter->path);
}
#endif
@@ -1527,12 +1527,12 @@ int git_path_dirload(
return error;
}
-int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path)
+int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path)
{
if (git_path_is_local_file_url(url_or_path))
return git_path_fromurl(local_path_out, url_or_path);
else
- return git_buf_sets(local_path_out, url_or_path);
+ return git_str_sets(local_path_out, url_or_path);
}
/* Reject paths like AUX or COM1, or those versions that end in a dot or
@@ -1625,7 +1625,7 @@ static bool verify_dotgit_hfs(const char *path, size_t len)
GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size_t len)
{
- git_buf *reserved = git_repository__reserved_names_win32;
+ git_str *reserved = git_repository__reserved_names_win32;
size_t reserved_len = git_repository__reserved_names_win32_len;
size_t start = 0, i;
@@ -1633,7 +1633,7 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
git_repository__reserved_names(&reserved, &reserved_len, repo, true);
for (i = 0; i < reserved_len; i++) {
- git_buf *r = &reserved[i];
+ git_str *r = &reserved[i];
if (len >= r->size &&
strncasecmp(path, r->ptr, r->size) == 0) {
@@ -1943,17 +1943,17 @@ int git_path_validate_workdir_with_len(
return 0;
}
-int git_path_validate_workdir_buf(git_repository *repo, git_buf *path)
+int git_path_validate_workdir_buf(git_repository *repo, git_str *path)
{
return git_path_validate_workdir_with_len(repo, path->ptr, path->size);
}
-int git_path_normalize_slashes(git_buf *out, const char *path)
+int git_path_normalize_slashes(git_str *out, const char *path)
{
int error;
char *p;
- if ((error = git_buf_puts(out, path)) < 0)
+ if ((error = git_str_puts(out, path)) < 0)
return error;
for (p = out->ptr; *p; p++) {
@@ -2004,7 +2004,7 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil
bool git_path_supports_symlinks(const char *dir)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
bool supported = false;
struct stat st;
int fd;
@@ -2020,7 +2020,7 @@ bool git_path_supports_symlinks(const char *dir)
done:
if (path.size)
(void)p_unlink(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return supported;
}
diff --git a/src/path.h b/src/path.h
index de6ec8ff2..4074c3425 100644
--- a/src/path.h
+++ b/src/path.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
#include "vector.h"
#include "git2/sys/path.h"
@@ -35,13 +35,13 @@
* The `git_path_dirname` implementation is thread safe. The returned
* string must be manually free'd.
*
- * The `git_path_dirname_r` implementation writes the dirname to a `git_buf`
+ * The `git_path_dirname_r` implementation writes the dirname to a `git_str`
* if the buffer pointer is not NULL.
* It returns an error code < 0 if there is an allocation error, otherwise
* the length of the dirname (which will be > 0).
*/
extern char *git_path_dirname(const char *path);
-extern int git_path_dirname_r(git_buf *buffer, const char *path);
+extern int git_path_dirname_r(git_str *buffer, const char *path);
/*
* This function returns the basename of the file, which is the last
@@ -55,17 +55,17 @@ extern int git_path_dirname_r(git_buf *buffer, const char *path);
* The `git_path_basename` implementation is thread safe. The returned
* string must be manually free'd.
*
- * The `git_path_basename_r` implementation writes the basename to a `git_buf`.
+ * The `git_path_basename_r` implementation writes the basename to a `git_str`.
* It returns an error code < 0 if there is an allocation error, otherwise
* the length of the basename (which will be >= 0).
*/
extern char *git_path_basename(const char *path);
-extern int git_path_basename_r(git_buf *buffer, const char *path);
+extern int git_path_basename_r(git_str *buffer, const char *path);
/* Return the offset of the start of the basename. Unlike the other
* basename functions, this returns 0 if the path is empty.
*/
-extern size_t git_path_basename_offset(git_buf *buffer);
+extern size_t git_path_basename_offset(git_str *buffer);
/**
* Find offset to root of path if path has one.
@@ -80,7 +80,7 @@ extern int git_path_root(const char *path);
/**
* Ensure path has a trailing '/'.
*/
-extern int git_path_to_dir(git_buf *path);
+extern int git_path_to_dir(git_str *path);
/**
* Ensure string has a trailing '/' if there is space for it.
@@ -150,12 +150,12 @@ GIT_INLINE(int) git_path_at_end_of_segment(const char *p)
return !*p || *p == '/';
}
-extern int git__percent_decode(git_buf *decoded_out, const char *input);
+extern int git__percent_decode(git_str *decoded_out, const char *input);
/**
* Extract path from file:// URL.
*/
-extern int git_path_fromurl(git_buf *local_path_out, const char *file_url);
+extern int git_path_fromurl(git_str *local_path_out, const char *file_url);
/**
@@ -205,7 +205,7 @@ extern int git_path_lstat(const char *path, struct stat *st);
* @param item Item that might be in the directory.
* @return 0 if item exists in directory, <0 otherwise.
*/
-extern bool git_path_contains(git_buf *dir, const char *item);
+extern bool git_path_contains(git_str *dir, const char *item);
/**
* Check if the given path contains the given subdirectory.
@@ -214,7 +214,7 @@ extern bool git_path_contains(git_buf *dir, const char *item);
* @param subdir Subdirectory name to look for in parent
* @return true if subdirectory exists, false otherwise.
*/
-extern bool git_path_contains_dir(git_buf *parent, const char *subdir);
+extern bool git_path_contains_dir(git_str *parent, const char *subdir);
/**
* Determine the common directory length between two paths, including
@@ -237,7 +237,7 @@ extern size_t git_path_common_dirlen(const char *one, const char *two);
* if there was not common root between the paths,
* or <0.
*/
-extern int git_path_make_relative(git_buf *path, const char *parent);
+extern int git_path_make_relative(git_str *path, const char *parent);
/**
* Check if the given path contains the given file.
@@ -246,7 +246,7 @@ extern int git_path_make_relative(git_buf *path, const char *parent);
* @param file File name to look for in parent
* @return true if file exists, false otherwise.
*/
-extern bool git_path_contains_file(git_buf *dir, const char *file);
+extern bool git_path_contains_file(git_str *dir, const char *file);
/**
* Prepend base to unrooted path or just copy path over.
@@ -255,24 +255,24 @@ extern bool git_path_contains_file(git_buf *dir, const char *file);
* is, either the end of the base directory prefix or the path root.
*/
extern int git_path_join_unrooted(
- git_buf *path_out, const char *path, const char *base, ssize_t *root_at);
+ git_str *path_out, const char *path, const char *base, ssize_t *root_at);
/**
* Removes multiple occurrences of '/' in a row, squashing them into a
* single '/'.
*/
-extern void git_path_squash_slashes(git_buf *path);
+extern void git_path_squash_slashes(git_str *path);
/**
* Clean up path, prepending base if it is not already rooted.
*/
-extern int git_path_prettify(git_buf *path_out, const char *path, const char *base);
+extern int git_path_prettify(git_str *path_out, const char *path, const char *base);
/**
* Clean up path, prepending base if it is not already rooted and
* appending a slash.
*/
-extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base);
+extern int git_path_prettify_dir(git_str *path_out, const char *path, const char *base);
/**
* Get a directory from a path.
@@ -283,7 +283,7 @@ extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char
* appends the trailing '/'. If the path does not exist, it is
* treated like a regular filename.
*/
-extern int git_path_find_dir(git_buf *dir);
+extern int git_path_find_dir(git_str *dir);
/**
* Resolve relative references within a path.
@@ -295,7 +295,7 @@ extern int git_path_find_dir(git_buf *dir);
* Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
* prefix and not touch that part of the path.
*/
-extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
+extern int git_path_resolve_relative(git_str *path, size_t ceiling);
/**
* Apply a relative path to base path.
@@ -306,7 +306,7 @@ extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
* slash, "." will be eaten with no change, and ".." will remove a
* segment from the base path.
*/
-extern int git_path_apply_relative(git_buf *target, const char *relpath);
+extern int git_path_apply_relative(git_str *target, const char *relpath);
enum {
GIT_PATH_DIR_IGNORE_CASE = (1u << 0),
@@ -328,9 +328,9 @@ enum {
* @return 0 on success or error code from OS error or from callback
*/
extern int git_path_direach(
- git_buf *pathbuf,
+ git_str *pathbuf,
uint32_t flags,
- int (*callback)(void *payload, git_buf *path),
+ int (*callback)(void *payload, git_str *path),
void *payload);
/**
@@ -360,7 +360,7 @@ extern int git_path_cmp(
* @param payload Passed to fn as the first ath.
*/
extern int git_path_walk_up(
- git_buf *pathbuf,
+ git_str *pathbuf,
const char *ceiling,
int (*callback)(void *payload, const char *path),
void *payload);
@@ -429,10 +429,10 @@ extern bool git_path_has_non_ascii(const char *path, size_t pathlen);
typedef struct {
iconv_t map;
- git_buf buf;
+ git_str buf;
} git_path_iconv_t;
-#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_BUF_INIT }
+#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT }
/* Init iconv data for converting decomposed UTF-8 to precomposed */
extern int git_path_iconv_init_precompose(git_path_iconv_t *ic);
@@ -461,7 +461,7 @@ struct git_path_diriter
git_win32_path path;
size_t parent_len;
- git_buf path_utf8;
+ git_str path_utf8;
size_t parent_utf8_len;
HANDLE handle;
@@ -472,13 +472,13 @@ struct git_path_diriter
unsigned int needs_next;
};
-#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_BUF_INIT, 0, INVALID_HANDLE_VALUE }
+#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE }
#else
struct git_path_diriter
{
- git_buf path;
+ git_str path;
size_t parent_len;
unsigned int flags;
@@ -490,7 +490,7 @@ struct git_path_diriter
#endif
};
-#define GIT_PATH_DIRITER_INIT { GIT_BUF_INIT }
+#define GIT_PATH_DIRITER_INIT { GIT_STR_INIT }
#endif
@@ -584,7 +584,7 @@ extern int git_path_dirload(
/* Used for paths to repositories on the filesystem */
extern bool git_path_is_local_file_url(const char *file_url);
-extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path);
+extern int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path);
/* Flags to determine path validity in `git_path_isvalid` */
#define GIT_PATH_REJECT_TRAVERSAL (1 << 0)
@@ -713,12 +713,12 @@ extern int git_path_validate_workdir_with_len(
size_t path_len);
extern int git_path_validate_workdir_buf(
git_repository *repo,
- git_buf *buf);
+ git_str *buf);
/**
* Convert any backslashes into slashes
*/
-int git_path_normalize_slashes(git_buf *out, const char *path);
+int git_path_normalize_slashes(git_str *out, const char *path);
bool git_path_supports_symlinks(const char *dir);
diff --git a/src/pathspec.c b/src/pathspec.c
index c6ad16571..3e44643c6 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -20,11 +20,11 @@
/* what is the common non-wildcard prefix for all items in the pathspec */
char *git_pathspec_prefix(const git_strarray *pathspec)
{
- git_buf prefix = GIT_BUF_INIT;
+ git_str prefix = GIT_STR_INIT;
const char *scan;
if (!pathspec || !pathspec->count ||
- git_buf_common_prefix(&prefix, pathspec->strings, pathspec->count) < 0)
+ git_str_common_prefix(&prefix, pathspec->strings, pathspec->count) < 0)
return NULL;
/* diff prefix will only be leading non-wildcards */
@@ -33,16 +33,16 @@ char *git_pathspec_prefix(const git_strarray *pathspec)
(scan == prefix.ptr || (*(scan - 1) != '\\')))
break;
}
- git_buf_truncate(&prefix, scan - prefix.ptr);
+ git_str_truncate(&prefix, scan - prefix.ptr);
if (prefix.size <= 0) {
- git_buf_dispose(&prefix);
+ git_str_dispose(&prefix);
return NULL;
}
- git_buf_unescape(&prefix);
+ git_str_unescape(&prefix);
- return git_buf_detach(&prefix);
+ return git_str_detach(&prefix);
}
/* is there anything in the spec that needs to be filtered on */
diff --git a/src/pathspec.h b/src/pathspec.h
index c4d1a83d3..bfdcd48a7 100644
--- a/src/pathspec.h
+++ b/src/pathspec.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "git2/pathspec.h"
-#include "buffer.h"
+#include "str.h"
#include "vector.h"
#include "pool.h"
#include "array.h"
diff --git a/src/push.c b/src/push.c
index b724188f9..3bf7ba5d9 100644
--- a/src/push.c
+++ b/src/push.c
@@ -159,7 +159,7 @@ int git_push_add_refspec(git_push *push, const char *refspec)
int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
{
- git_buf remote_ref_name = GIT_BUF_INIT;
+ git_str remote_ref_name = GIT_STR_INIT;
size_t i, j;
git_refspec *fetch_spec;
push_spec *push_spec = NULL;
@@ -180,9 +180,9 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
continue;
/* Clear the buffer which can be dirty from previous iteration */
- git_buf_clear(&remote_ref_name);
+ git_str_clear(&remote_ref_name);
- if ((error = git_refspec_transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
+ if ((error = git_refspec__transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
goto on_error;
/* Find matching push ref spec */
@@ -197,7 +197,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
/* Update the remote ref */
if (git_oid_is_zero(&push_spec->loid)) {
- error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
+ error = git_reference_lookup(&remote_ref, push->remote->repo, git_str_cstr(&remote_ref_name));
if (error >= 0) {
error = git_reference_delete(remote_ref);
@@ -205,7 +205,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
}
} else {
error = git_reference_create(NULL, push->remote->repo,
- git_buf_cstr(&remote_ref_name), &push_spec->loid, 1,
+ git_str_cstr(&remote_ref_name), &push_spec->loid, 1,
"update by push");
}
@@ -218,7 +218,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
}
if (fire_callback && callbacks && callbacks->update_tips) {
- error = callbacks->update_tips(git_buf_cstr(&remote_ref_name),
+ error = callbacks->update_tips(git_str_cstr(&remote_ref_name),
&push_spec->roid, &push_spec->loid, callbacks->payload);
if (error < 0)
@@ -229,7 +229,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
error = 0;
on_error:
- git_buf_dispose(&remote_ref_name);
+ git_str_dispose(&remote_ref_name);
return error;
}
diff --git a/src/reader.c b/src/reader.c
index 48928940d..ba9775240 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -23,7 +23,7 @@ typedef struct {
} tree_reader;
static int tree_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *_reader,
@@ -42,7 +42,7 @@ static int tree_reader_read(
blobsize = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(blobsize);
- if ((error = git_buf_set(out, git_blob_rawcontent(blob), (size_t)blobsize)) < 0)
+ if ((error = git_str_set(out, git_blob_rawcontent(blob), (size_t)blobsize)) < 0)
goto done;
if (out_id)
@@ -83,14 +83,14 @@ typedef struct {
} workdir_reader;
static int workdir_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *_reader,
const char *filename)
{
workdir_reader *reader = (workdir_reader *)_reader;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
git_filemode_t filemode;
git_filter_list *filters = NULL;
@@ -120,7 +120,7 @@ static int workdir_reader_read(
GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT)) < 0)
goto done;
- if ((error = git_filter_list_apply_to_file(out,
+ if ((error = git_filter_list__apply_to_file(out,
filters, reader->repo, path.ptr)) < 0)
goto done;
@@ -146,7 +146,7 @@ static int workdir_reader_read(
done:
git_filter_list_free(filters);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -186,7 +186,7 @@ typedef struct {
} index_reader;
static int index_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *_reader,
@@ -247,7 +247,7 @@ int git_reader_for_index(
/* generic */
int git_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *reader,
diff --git a/src/reader.h b/src/reader.h
index 18a6a1103..b58dc93f6 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -25,7 +25,7 @@ typedef struct git_reader git_reader;
* reader after disposing the underlying object that it reads.
*/
struct git_reader {
- int (*read)(git_buf *out, git_oid *out_oid, git_filemode_t *mode, git_reader *reader, const char *filename);
+ int (*read)(git_str *out, git_oid *out_oid, git_filemode_t *mode, git_reader *reader, const char *filename);
};
/**
@@ -91,7 +91,7 @@ extern int git_reader_for_workdir(
* @param filename The filename to read from the reader
*/
extern int git_reader_read(
- git_buf *out,
+ git_str *out,
git_oid *out_id,
git_filemode_t *out_filemode,
git_reader *reader,
diff --git a/src/rebase.c b/src/rebase.c
index 4f10c296b..302fc81fc 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -7,10 +7,11 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "repository.h"
#include "posix.h"
#include "filebuf.h"
+#include "commit.h"
#include "merge.h"
#include "array.h"
#include "config.h"
@@ -90,22 +91,22 @@ static int rebase_state_type(
char **path_out,
git_repository *repo)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_rebase_t type = GIT_REBASE_NONE;
- if (git_buf_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
+ if (git_str_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
return -1;
- if (git_path_isdir(git_buf_cstr(&path))) {
+ if (git_path_isdir(git_str_cstr(&path))) {
type = GIT_REBASE_APPLY;
goto done;
}
- git_buf_clear(&path);
- if (git_buf_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
+ git_str_clear(&path);
+ if (git_str_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
return -1;
- if (git_path_isdir(git_buf_cstr(&path))) {
+ if (git_path_isdir(git_str_cstr(&path))) {
type = GIT_REBASE_MERGE;
goto done;
}
@@ -114,36 +115,36 @@ done:
*type_out = type;
if (type != GIT_REBASE_NONE && path_out)
- *path_out = git_buf_detach(&path);
+ *path_out = git_str_detach(&path);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
GIT_INLINE(int) rebase_readfile(
- git_buf *out,
- git_buf *state_path,
+ git_str *out,
+ git_str *state_path,
const char *filename)
{
size_t state_path_len = state_path->size;
int error;
- git_buf_clear(out);
+ git_str_clear(out);
- if ((error = git_buf_joinpath(state_path, state_path->ptr, filename)) < 0 ||
+ if ((error = git_str_joinpath(state_path, state_path->ptr, filename)) < 0 ||
(error = git_futils_readbuffer(out, state_path->ptr)) < 0)
goto done;
- git_buf_rtrim(out);
+ git_str_rtrim(out);
done:
- git_buf_truncate(state_path, state_path_len);
+ git_str_truncate(state_path, state_path_len);
return error;
}
GIT_INLINE(int) rebase_readint(
- size_t *out, git_buf *asc_out, git_buf *state_path, const char *filename)
+ size_t *out, git_str *asc_out, git_str *state_path, const char *filename)
{
int32_t num;
const char *eol;
@@ -163,7 +164,7 @@ GIT_INLINE(int) rebase_readint(
}
GIT_INLINE(int) rebase_readoid(
- git_oid *out, git_buf *str_out, git_buf *state_path, const char *filename)
+ git_oid *out, git_str *str_out, git_str *state_path, const char *filename)
{
int error;
@@ -201,13 +202,13 @@ static git_rebase_operation *rebase_operation_alloc(
static int rebase_open_merge(git_rebase *rebase)
{
- git_buf state_path = GIT_BUF_INIT, buf = GIT_BUF_INIT, cmt = GIT_BUF_INIT;
+ git_str state_path = GIT_STR_INIT, buf = GIT_STR_INIT, cmt = GIT_STR_INIT;
git_oid id;
git_rebase_operation *operation;
size_t i, msgnum = 0, end;
int error;
- if ((error = git_buf_puts(&state_path, rebase->state_path)) < 0)
+ if ((error = git_str_puts(&state_path, rebase->state_path)) < 0)
goto done;
/* Read 'msgnum' if it exists (otherwise, let msgnum = 0) */
@@ -234,9 +235,9 @@ static int rebase_open_merge(git_rebase *rebase)
GIT_ERROR_CHECK_ARRAY(rebase->operations);
for (i = 0; i < end; i++) {
- git_buf_clear(&cmt);
+ git_str_clear(&cmt);
- if ((error = git_buf_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
+ if ((error = git_str_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
(error = rebase_readoid(&id, &buf, &state_path, cmt.ptr)) < 0)
goto done;
@@ -248,12 +249,12 @@ static int rebase_open_merge(git_rebase *rebase)
if ((error = rebase_readfile(&buf, &state_path, ONTO_NAME_FILE)) < 0)
goto done;
- rebase->onto_name = git_buf_detach(&buf);
+ rebase->onto_name = git_str_detach(&buf);
done:
- git_buf_dispose(&cmt);
- git_buf_dispose(&state_path);
- git_buf_dispose(&buf);
+ git_str_dispose(&cmt);
+ git_str_dispose(&state_path);
+ git_str_dispose(&buf);
return error;
}
@@ -296,8 +297,8 @@ int git_rebase_open(
const git_rebase_options *given_opts)
{
git_rebase *rebase;
- git_buf path = GIT_BUF_INIT, orig_head_name = GIT_BUF_INIT,
- orig_head_id = GIT_BUF_INIT, onto_id = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, orig_head_name = GIT_STR_INIT,
+ orig_head_id = GIT_STR_INIT, onto_id = GIT_STR_INIT;
size_t state_path_len;
int error;
@@ -320,54 +321,54 @@ int git_rebase_open(
goto done;
}
- if ((error = git_buf_puts(&path, rebase->state_path)) < 0)
+ if ((error = git_str_puts(&path, rebase->state_path)) < 0)
goto done;
- state_path_len = git_buf_len(&path);
+ state_path_len = git_str_len(&path);
- if ((error = git_buf_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
(error = git_futils_readbuffer(&orig_head_name, path.ptr)) < 0)
goto done;
- git_buf_rtrim(&orig_head_name);
+ git_str_rtrim(&orig_head_name);
if (strcmp(ORIG_DETACHED_HEAD, orig_head_name.ptr) == 0)
rebase->head_detached = 1;
- git_buf_truncate(&path, state_path_len);
+ git_str_truncate(&path, state_path_len);
- if ((error = git_buf_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
goto done;
if (!git_path_isfile(path.ptr)) {
/* Previous versions of git.git used 'head' here; support that. */
- git_buf_truncate(&path, state_path_len);
+ git_str_truncate(&path, state_path_len);
- if ((error = git_buf_joinpath(&path, path.ptr, HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&path, path.ptr, HEAD_FILE)) < 0)
goto done;
}
if ((error = git_futils_readbuffer(&orig_head_id, path.ptr)) < 0)
goto done;
- git_buf_rtrim(&orig_head_id);
+ git_str_rtrim(&orig_head_id);
if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0)
goto done;
- git_buf_truncate(&path, state_path_len);
+ git_str_truncate(&path, state_path_len);
- if ((error = git_buf_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
(error = git_futils_readbuffer(&onto_id, path.ptr)) < 0)
goto done;
- git_buf_rtrim(&onto_id);
+ git_str_rtrim(&onto_id);
if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0)
goto done;
if (!rebase->head_detached)
- rebase->orig_head_name = git_buf_detach(&orig_head_name);
+ rebase->orig_head_name = git_str_detach(&orig_head_name);
switch (rebase->type) {
case GIT_REBASE_INTERACTIVE:
@@ -391,10 +392,10 @@ done:
else
git_rebase_free(rebase);
- git_buf_dispose(&path);
- git_buf_dispose(&orig_head_name);
- git_buf_dispose(&orig_head_id);
- git_buf_dispose(&onto_id);
+ git_str_dispose(&path);
+ git_str_dispose(&orig_head_name);
+ git_str_dispose(&orig_head_id);
+ git_str_dispose(&onto_id);
return error;
}
@@ -410,20 +411,20 @@ static int rebase_cleanup(git_rebase *rebase)
static int rebase_setupfile(git_rebase *rebase, const char *filename, int flags, const char *fmt, ...)
{
- git_buf path = GIT_BUF_INIT,
- contents = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT,
+ contents = GIT_STR_INIT;
va_list ap;
int error;
va_start(ap, fmt);
- git_buf_vprintf(&contents, fmt, ap);
+ git_str_vprintf(&contents, fmt, ap);
va_end(ap);
- if ((error = git_buf_joinpath(&path, rebase->state_path, filename)) == 0)
+ if ((error = git_str_joinpath(&path, rebase->state_path, filename)) == 0)
error = git_futils_writebuffer(&contents, path.ptr, flags, REBASE_FILE_MODE);
- git_buf_dispose(&path);
- git_buf_dispose(&contents);
+ git_str_dispose(&path);
+ git_str_dispose(&contents);
return error;
}
@@ -440,7 +441,7 @@ static const char *rebase_onto_name(const git_annotated_commit *onto)
static int rebase_setupfiles_merge(git_rebase *rebase)
{
- git_buf commit_filename = GIT_BUF_INIT;
+ git_str commit_filename = GIT_STR_INIT;
char id_str[GIT_OID_HEXSZ];
git_rebase_operation *operation;
size_t i;
@@ -453,8 +454,8 @@ static int rebase_setupfiles_merge(git_rebase *rebase)
for (i = 0; i < git_array_size(rebase->operations); i++) {
operation = git_array_get(rebase->operations, i);
- git_buf_clear(&commit_filename);
- git_buf_printf(&commit_filename, CMT_FILE_FMT, i+1);
+ git_str_clear(&commit_filename);
+ git_str_printf(&commit_filename, CMT_FILE_FMT, i+1);
git_oid_fmt(id_str, &operation->id);
@@ -464,7 +465,7 @@ static int rebase_setupfiles_merge(git_rebase *rebase)
}
done:
- git_buf_dispose(&commit_filename);
+ git_str_dispose(&commit_filename);
return error;
}
@@ -626,16 +627,16 @@ static int rebase_init_merge(
{
git_reference *head_ref = NULL;
git_commit *onto_commit = NULL;
- git_buf reflog = GIT_BUF_INIT;
- git_buf state_path = GIT_BUF_INIT;
+ git_str reflog = GIT_STR_INIT;
+ git_str state_path = GIT_STR_INIT;
int error;
GIT_UNUSED(upstream);
- if ((error = git_buf_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
+ if ((error = git_str_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
goto done;
- rebase->state_path = git_buf_detach(&state_path);
+ rebase->state_path = git_str_detach(&state_path);
GIT_ERROR_CHECK_ALLOC(rebase->state_path);
if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
@@ -654,7 +655,7 @@ static int rebase_init_merge(
git_oid_cpy(&rebase->onto_id, git_annotated_commit_id(onto));
if ((error = rebase_setupfiles(rebase)) < 0 ||
- (error = git_buf_printf(&reflog,
+ (error = git_str_printf(&reflog,
"rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
(error = git_commit_lookup(
&onto_commit, repo, git_annotated_commit_id(onto))) < 0 ||
@@ -667,8 +668,8 @@ static int rebase_init_merge(
done:
git_reference_free(head_ref);
git_commit_free(onto_commit);
- git_buf_dispose(&reflog);
- git_buf_dispose(&state_path);
+ git_str_dispose(&reflog);
+ git_str_dispose(&state_path);
return error;
}
@@ -795,7 +796,7 @@ static int rebase_next_merge(
git_rebase_operation **out,
git_rebase *rebase)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_commit *current_commit = NULL, *parent_commit = NULL;
git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL;
git_index *index = NULL;
@@ -848,7 +849,7 @@ done:
git_tree_free(parent_tree);
git_commit_free(parent_commit);
git_commit_free(current_commit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -955,14 +956,14 @@ static int create_signed(
size_t parent_count,
const git_commit **parents)
{
- git_buf commit_content = GIT_BUF_INIT,
- commit_signature = GIT_BUF_INIT,
- signature_field = GIT_BUF_INIT;
+ git_str commit_content = GIT_STR_INIT;
+ git_buf commit_signature = { NULL, 0, 0 },
+ signature_field = { NULL, 0, 0 };
int error;
git_error_clear();
- if ((error = git_commit_create_buffer(&commit_content,
+ if ((error = git_commit__create_buffer(&commit_content,
rebase->repo, author, committer, message_encoding,
message, tree, parent_count, parents)) < 0)
goto done;
@@ -986,7 +987,7 @@ static int create_signed(
done:
git_buf_dispose(&commit_signature);
git_buf_dispose(&signature_field);
- git_buf_dispose(&commit_content);
+ git_str_dispose(&commit_content);
return error;
}
#endif
@@ -1216,13 +1217,13 @@ done:
return error;
}
-static int notes_ref_lookup(git_buf *out, git_rebase *rebase)
+static int notes_ref_lookup(git_str *out, git_rebase *rebase)
{
git_config *config = NULL;
int do_rewrite, error;
if (rebase->options.rewrite_notes_ref) {
- git_buf_attach_notowned(out,
+ git_str_attach_notowned(out,
rebase->options.rewrite_notes_ref,
strlen(rebase->options.rewrite_notes_ref));
return 0;
@@ -1239,7 +1240,7 @@ static int notes_ref_lookup(git_buf *out, git_rebase *rebase)
}
error = do_rewrite ?
- git_config_get_string_buf(out, config, "notes.rewriteref") :
+ git_config__get_string_buf(out, config, "notes.rewriteref") :
GIT_ENOTFOUND;
done:
@@ -1294,7 +1295,7 @@ static int rebase_copy_notes(
git_rebase *rebase,
const git_signature *committer)
{
- git_buf path = GIT_BUF_INIT, rewritten = GIT_BUF_INIT, notes_ref = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, rewritten = GIT_STR_INIT, notes_ref = GIT_STR_INIT;
char *pair_list, *fromstr, *tostr, *end;
git_oid from, to;
unsigned int linenum = 1;
@@ -1309,7 +1310,7 @@ static int rebase_copy_notes(
goto done;
}
- if ((error = git_buf_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
+ if ((error = git_str_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
(error = git_futils_readbuffer(&rewritten, path.ptr)) < 0)
goto done;
@@ -1349,9 +1350,9 @@ on_error:
error = -1;
done:
- git_buf_dispose(&rewritten);
- git_buf_dispose(&path);
- git_buf_dispose(&notes_ref);
+ git_str_dispose(&rewritten);
+ git_str_dispose(&path);
+ git_str_dispose(&notes_ref);
return error;
}
@@ -1360,16 +1361,16 @@ static int return_to_orig_head(git_rebase *rebase)
{
git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL;
git_commit *terminal_commit = NULL;
- git_buf branch_msg = GIT_BUF_INIT, head_msg = GIT_BUF_INIT;
+ git_str branch_msg = GIT_STR_INIT, head_msg = GIT_STR_INIT;
char onto[GIT_OID_HEXSZ];
int error = 0;
git_oid_fmt(onto, &rebase->onto_id);
- if ((error = git_buf_printf(&branch_msg,
+ if ((error = git_str_printf(&branch_msg,
"rebase finished: %s onto %.*s",
rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
- (error = git_buf_printf(&head_msg,
+ (error = git_str_printf(&head_msg,
"rebase finished: returning to %s",
rebase->orig_head_name)) == 0 &&
(error = git_repository_head(&terminal_ref, rebase->repo)) == 0 &&
@@ -1383,8 +1384,8 @@ static int return_to_orig_head(git_rebase *rebase)
rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
head_msg.ptr);
- git_buf_dispose(&head_msg);
- git_buf_dispose(&branch_msg);
+ git_str_dispose(&head_msg);
+ git_str_dispose(&branch_msg);
git_commit_free(terminal_commit);
git_reference_free(head_ref);
git_reference_free(branch_ref);
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 24cb22fb0..37eb85ecc 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -69,11 +69,11 @@ typedef struct refdb_fs_backend {
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
GIT_INLINE(int) loose_path(
- git_buf *out,
+ git_str *out,
const char *base,
const char *refname)
{
- if (git_buf_joinpath(out, base, refname) < 0)
+ if (git_str_joinpath(out, base, refname) < 0)
return -1;
return git_path_validate_filesystem_with_suffix(out->ptr, out->size,
@@ -81,7 +81,7 @@ GIT_INLINE(int) loose_path(
}
GIT_INLINE(int) reflog_path(
- git_buf *out,
+ git_str *out,
git_repository *repo,
const char *refname)
{
@@ -91,7 +91,7 @@ GIT_INLINE(int) reflog_path(
base = (strcmp(refname, GIT_HEAD_FILE) == 0) ? repo->gitdir :
repo->commondir;
- if ((error = git_buf_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
+ if ((error = git_str_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
return error;
return loose_path(out, out->ptr, refname);
@@ -106,7 +106,7 @@ static int packref_cmp(const void *a_, const void *b_)
static int packed_reload(refdb_fs_backend *backend)
{
int error;
- git_buf packedrefs = GIT_BUF_INIT;
+ git_str packedrefs = GIT_STR_INIT;
char *scan, *eof, *eol;
if (!backend->gitpath)
@@ -212,7 +212,7 @@ static int packed_reload(refdb_fs_backend *backend)
}
git_sortedcache_wunlock(backend->refcache);
- git_buf_dispose(&packedrefs);
+ git_str_dispose(&packedrefs);
return 0;
@@ -221,17 +221,17 @@ parse_failed:
GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
git_sortedcache_wunlock(backend->refcache);
- git_buf_dispose(&packedrefs);
+ git_str_dispose(&packedrefs);
return -1;
}
static int loose_parse_oid(
- git_oid *oid, const char *filename, git_buf *file_content)
+ git_oid *oid, const char *filename, git_str *file_content)
{
- const char *str = git_buf_cstr(file_content);
+ const char *str = git_str_cstr(file_content);
- if (git_buf_len(file_content) < GIT_OID_HEXSZ)
+ if (git_str_len(file_content) < GIT_OID_HEXSZ)
goto corrupted;
/* we need to get 40 OID characters from the file */
@@ -248,13 +248,13 @@ corrupted:
return -1;
}
-static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
+static int loose_readbuffer(git_str *buf, const char *base, const char *path)
{
int error;
if ((error = loose_path(buf, base, path)) < 0 ||
(error = git_futils_readbuffer(buf, buf->ptr)) < 0)
- git_buf_dispose(buf);
+ git_str_dispose(buf);
return error;
}
@@ -262,7 +262,7 @@ static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
{
int error = 0;
- git_buf ref_file = GIT_BUF_INIT;
+ git_str ref_file = GIT_STR_INIT;
struct packref *ref = NULL;
git_oid oid;
@@ -275,7 +275,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
}
/* skip symbolic refs */
- if (!git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF))
+ if (!git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF))
goto done;
/* parse OID from file */
@@ -295,11 +295,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
git_sortedcache_wunlock(backend->refcache);
done:
- git_buf_dispose(&ref_file);
+ git_str_dispose(&ref_file);
return error;
}
-static int _dirent_loose_load(void *payload, git_buf *full_path)
+static int _dirent_loose_load(void *payload, git_str *full_path)
{
refdb_fs_backend *backend = payload;
const char *file_path;
@@ -333,9 +333,9 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
static int packed_loadloose(refdb_fs_backend *backend)
{
int error;
- git_buf refs_path = GIT_BUF_INIT;
+ git_str refs_path = GIT_STR_INIT;
- if (git_buf_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
+ if (git_str_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
return -1;
/*
@@ -346,7 +346,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
error = git_path_direach(
&refs_path, backend->direach_flags, _dirent_loose_load, backend);
- git_buf_dispose(&refs_path);
+ git_str_dispose(&refs_path);
return error;
}
@@ -357,7 +357,7 @@ static int refdb_fs_backend__exists(
const char *ref_name)
{
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(backend);
@@ -381,18 +381,18 @@ static int refdb_fs_backend__exists(
}
out:
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
return error;
}
-static const char *loose_parse_symbolic(git_buf *file_content)
+static const char *loose_parse_symbolic(git_str *file_content)
{
const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
const char *refname_start;
refname_start = (const char *)file_content->ptr;
- if (git_buf_len(file_content) < header_len + 1) {
+ if (git_str_len(file_content) < header_len + 1) {
git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file");
return NULL;
}
@@ -424,7 +424,7 @@ static int loose_lookup(
refdb_fs_backend *backend,
const char *ref_name)
{
- git_buf ref_file = GIT_BUF_INIT;
+ git_str ref_file = GIT_STR_INIT;
int error = 0;
const char *ref_dir;
@@ -438,10 +438,10 @@ static int loose_lookup(
if ((error = loose_readbuffer(&ref_file, ref_dir, ref_name)) < 0)
/* cannot read loose ref file - gah */;
- else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
+ else if (git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF) == 0) {
const char *target;
- git_buf_rtrim(&ref_file);
+ git_str_rtrim(&ref_file);
if (!(target = loose_parse_symbolic(&ref_file)))
error = -1;
@@ -455,7 +455,7 @@ static int loose_lookup(
*out = git_reference__alloc(ref_name, &oid, NULL);
}
- git_buf_dispose(&ref_file);
+ git_str_dispose(&ref_file);
return error;
}
@@ -542,7 +542,7 @@ static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
{
int error = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_iterator *fsit = NULL;
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL;
@@ -578,26 +578,26 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
}
}
- if ((error = git_buf_puts(&path, backend->commonpath)) < 0 ||
- (error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) {
- git_buf_dispose(&path);
+ if ((error = git_str_puts(&path, backend->commonpath)) < 0 ||
+ (error = git_str_put(&path, ref_prefix, ref_prefix_len)) < 0) {
+ git_str_dispose(&path);
return error;
}
if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
}
- error = git_buf_sets(&path, ref_prefix);
+ error = git_str_sets(&path, ref_prefix);
while (!error && !git_iterator_advance(&entry, fsit)) {
const char *ref_name;
char *ref_dup;
- git_buf_truncate(&path, ref_prefix_len);
- git_buf_puts(&path, entry->path);
- ref_name = git_buf_cstr(&path);
+ git_str_truncate(&path, ref_prefix_len);
+ git_str_puts(&path, entry->path);
+ ref_name = git_str_cstr(&path);
if (git__suffixcmp(ref_name, ".lock") == 0 ||
(iter->glob && wildmatch(iter->glob, ref_name, 0) != 0))
@@ -611,7 +611,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
}
git_iterator_free(fsit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -810,7 +810,7 @@ static int reference_path_available(
static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
{
int error, filebuf_flags;
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
const char *basedir;
GIT_ASSERT_ARG(file);
@@ -845,7 +845,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
if (error == GIT_EDIRECTORY)
git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
return error;
}
@@ -1013,7 +1013,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
{
size_t i;
git_filebuf lock = GIT_FILEBUF_INIT;
- git_buf ref_content = GIT_BUF_INIT;
+ git_str ref_content = GIT_STR_INIT;
int error = 0;
/* backend->refcache is already locked when this is called */
@@ -1034,7 +1034,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
continue;
if (error < 0) {
- git_buf_dispose(&ref_content);
+ git_str_dispose(&ref_content);
git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
return error;
}
@@ -1065,7 +1065,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
p_unlink(lock.path_original);
}
- git_buf_dispose(&ref_content);
+ git_str_dispose(&ref_content);
git_filebuf_cleanup(&lock);
return 0;
}
@@ -1333,32 +1333,32 @@ static int refdb_fs_backend__prune_refs(
const char *ref_name,
const char *prefix)
{
- git_buf relative_path = GIT_BUF_INIT;
- git_buf base_path = GIT_BUF_INIT;
+ git_str relative_path = GIT_STR_INIT;
+ git_str base_path = GIT_STR_INIT;
size_t commonlen;
int error;
GIT_ASSERT_ARG(backend);
GIT_ASSERT_ARG(ref_name);
- if ((error = git_buf_sets(&relative_path, ref_name)) < 0)
+ if ((error = git_str_sets(&relative_path, ref_name)) < 0)
goto cleanup;
git_path_squash_slashes(&relative_path);
- if ((commonlen = git_path_common_dirlen("refs/heads/", git_buf_cstr(&relative_path))) == strlen("refs/heads/") ||
- (commonlen = git_path_common_dirlen("refs/tags/", git_buf_cstr(&relative_path))) == strlen("refs/tags/") ||
- (commonlen = git_path_common_dirlen("refs/remotes/", git_buf_cstr(&relative_path))) == strlen("refs/remotes/")) {
+ if ((commonlen = git_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
+ (commonlen = git_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
+ (commonlen = git_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
- git_buf_truncate(&relative_path, commonlen);
+ git_str_truncate(&relative_path, commonlen);
if (prefix)
- error = git_buf_join3(&base_path, '/',
+ error = git_str_join3(&base_path, '/',
backend->commonpath, prefix,
- git_buf_cstr(&relative_path));
+ git_str_cstr(&relative_path));
else
- error = git_buf_joinpath(&base_path,
+ error = git_str_joinpath(&base_path,
backend->commonpath,
- git_buf_cstr(&relative_path));
+ git_str_cstr(&relative_path));
if (!error)
error = git_path_validate_filesystem(base_path.ptr, base_path.size);
@@ -1367,7 +1367,7 @@ static int refdb_fs_backend__prune_refs(
goto cleanup;
error = git_futils_rmdir_r(ref_name + commonlen,
- git_buf_cstr(&base_path),
+ git_str_cstr(&base_path),
GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
if (error == GIT_ENOTFOUND)
@@ -1375,8 +1375,8 @@ static int refdb_fs_backend__prune_refs(
}
cleanup:
- git_buf_dispose(&relative_path);
- git_buf_dispose(&base_path);
+ git_str_dispose(&relative_path);
+ git_str_dispose(&base_path);
return error;
}
@@ -1405,7 +1405,7 @@ static int refdb_fs_backend__delete(
static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error = 0;
if ((error = loose_path(&path, backend->commonpath, ref_name)) < 0)
@@ -1417,7 +1417,7 @@ static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
else if (error != 0)
error = -1;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1574,17 +1574,17 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
static char *setup_namespace(git_repository *repo, const char *in)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *parts, *start, *end, *out = NULL;
if (!in)
goto done;
- git_buf_puts(&path, in);
+ git_str_puts(&path, in);
/* if the repo is not namespaced, nothing else to do */
if (repo->namespace == NULL) {
- out = git_buf_detach(&path);
+ out = git_str_detach(&path);
goto done;
}
@@ -1599,23 +1599,23 @@ static char *setup_namespace(git_repository *repo, const char *in)
* refs under refs/namespaces/foo/refs/namespaces/bar/
*/
while ((start = git__strsep(&end, "/")) != NULL)
- git_buf_printf(&path, "refs/namespaces/%s/", start);
+ git_str_printf(&path, "refs/namespaces/%s/", start);
- git_buf_printf(&path, "refs/namespaces/%s/refs", end);
+ git_str_printf(&path, "refs/namespaces/%s/refs", end);
git__free(parts);
/* Make sure that the folder with the namespace exists */
- if (git_futils_mkdir_relative(git_buf_cstr(&path), in, 0777,
+ if (git_futils_mkdir_relative(git_str_cstr(&path), in, 0777,
GIT_MKDIR_PATH, NULL) < 0)
goto done;
/* Return root of the namespaced gitpath, i.e. without the trailing 'refs' */
- git_buf_rtruncate_at_char(&path, '/');
- git_buf_putc(&path, '/');
- out = git_buf_detach(&path);
+ git_str_rtruncate_at_char(&path, '/');
+ git_str_putc(&path, '/');
+ out = git_str_detach(&path);
done:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return out;
}
@@ -1716,7 +1716,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
{
refdb_fs_backend *backend;
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(_backend && name);
@@ -1727,8 +1727,8 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
if ((error = reflog_path(&path, repo, name)) < 0)
return error;
- error = create_new_reflog_file(git_buf_cstr(&path));
- git_buf_dispose(&path);
+ error = create_new_reflog_file(git_str_cstr(&path));
+ git_str_dispose(&path);
return error;
}
@@ -1736,15 +1736,15 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
static int has_reflog(git_repository *repo, const char *name)
{
int ret = 0;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (reflog_path(&path, repo, name) < 0)
goto cleanup;
- ret = git_path_isfile(git_buf_cstr(&path));
+ ret = git_path_isfile(git_str_cstr(&path));
cleanup:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return ret;
}
@@ -1763,8 +1763,8 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
{
int error = -1;
- git_buf log_path = GIT_BUF_INIT;
- git_buf log_file = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
+ git_str log_file = GIT_STR_INIT;
git_reflog *log = NULL;
git_repository *repo;
refdb_fs_backend *backend;
@@ -1782,16 +1782,16 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
if (reflog_path(&log_path, repo, name) < 0)
goto cleanup;
- error = git_futils_readbuffer(&log_file, git_buf_cstr(&log_path));
+ error = git_futils_readbuffer(&log_file, git_str_cstr(&log_path));
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
if ((error == GIT_ENOTFOUND) &&
- ((error = create_new_reflog_file(git_buf_cstr(&log_path))) < 0))
+ ((error = create_new_reflog_file(git_str_cstr(&log_path))) < 0))
goto cleanup;
if ((error = reflog_parse(log,
- git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
+ git_str_cstr(&log_file), git_str_len(&log_file))) < 0)
goto cleanup;
*out = log;
@@ -1801,14 +1801,14 @@ cleanup:
git_reflog_free(log);
success:
- git_buf_dispose(&log_file);
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_file);
+ git_str_dispose(&log_path);
return error;
}
static int serialize_reflog_entry(
- git_buf *buf,
+ git_str *buf,
const git_oid *oid_old,
const git_oid *oid_new,
const git_signature *committer,
@@ -1820,38 +1820,38 @@ static int serialize_reflog_entry(
git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);
- git_buf_clear(buf);
+ git_str_clear(buf);
- git_buf_puts(buf, raw_old);
- git_buf_putc(buf, ' ');
- git_buf_puts(buf, raw_new);
+ git_str_puts(buf, raw_old);
+ git_str_putc(buf, ' ');
+ git_str_puts(buf, raw_new);
git_signature__writebuf(buf, " ", committer);
/* drop trailing LF */
- git_buf_rtrim(buf);
+ git_str_rtrim(buf);
if (msg) {
size_t i;
- git_buf_putc(buf, '\t');
- git_buf_puts(buf, msg);
+ git_str_putc(buf, '\t');
+ git_str_puts(buf, msg);
for (i = 0; i < buf->size - 2; i++)
if (buf->ptr[i] == '\n')
buf->ptr[i] = ' ';
- git_buf_rtrim(buf);
+ git_str_rtrim(buf);
}
- git_buf_putc(buf, '\n');
+ git_str_putc(buf, '\n');
- return git_buf_oom(buf);
+ return git_str_oom(buf);
}
static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname)
{
git_repository *repo;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
int error;
repo = backend->repo;
@@ -1864,17 +1864,17 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
if (reflog_path(&log_path, repo, refname) < 0)
return -1;
- if (!git_path_isfile(git_buf_cstr(&log_path))) {
+ if (!git_path_isfile(git_str_cstr(&log_path))) {
git_error_set(GIT_ERROR_INVALID,
"log file for reference '%s' doesn't exist", refname);
error = -1;
goto cleanup;
}
- error = git_filebuf_open(file, git_buf_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
+ error = git_filebuf_open(file, git_str_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
cleanup:
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
return error;
}
@@ -1885,7 +1885,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
unsigned int i;
git_reflog_entry *entry;
refdb_fs_backend *backend;
- git_buf log = GIT_BUF_INIT;
+ git_str log = GIT_STR_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
GIT_ASSERT_ARG(_backend);
@@ -1911,7 +1911,7 @@ cleanup:
git_filebuf_cleanup(&fbuf);
success:
- git_buf_dispose(&log);
+ git_str_dispose(&log);
return error;
}
@@ -1921,7 +1921,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
{
int error, is_symbolic, open_flags;
git_oid old_id = {{0}}, new_id = {{0}};
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
git_repository *repo = backend->repo;
is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC;
@@ -1965,7 +1965,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
if ((error = reflog_path(&path, repo, ref->name)) < 0)
goto cleanup;
- if (((error = git_futils_mkpath2file(git_buf_cstr(&path), 0777)) < 0) &&
+ if (((error = git_futils_mkpath2file(git_str_cstr(&path), 0777)) < 0) &&
(error != GIT_EEXISTS)) {
goto cleanup;
}
@@ -1973,11 +1973,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
/* If the new branch matches part of the namespace of a previously deleted branch,
* there maybe an obsolete/unused directory (or directory hierarchy) in the way.
*/
- if (git_path_isdir(git_buf_cstr(&path))) {
- if ((error = git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
+ if (git_path_isdir(git_str_cstr(&path))) {
+ if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
if (error == GIT_ENOTFOUND)
error = 0;
- } else if (git_path_isdir(git_buf_cstr(&path))) {
+ } else if (git_path_isdir(git_str_cstr(&path))) {
git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
ref->name);
error = GIT_EDIRECTORY;
@@ -1992,11 +1992,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
if (backend->fsync)
open_flags |= O_FSYNC;
- error = git_futils_writebuffer(&buf, git_buf_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
+ error = git_futils_writebuffer(&buf, git_str_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
cleanup:
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
return error;
}
@@ -2004,10 +2004,10 @@ cleanup:
static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name)
{
int error = 0, fd;
- git_buf old_path = GIT_BUF_INIT;
- git_buf new_path = GIT_BUF_INIT;
- git_buf temp_path = GIT_BUF_INIT;
- git_buf normalized = GIT_BUF_INIT;
+ git_str old_path = GIT_STR_INIT;
+ git_str new_path = GIT_STR_INIT;
+ git_str temp_path = GIT_STR_INIT;
+ git_str normalized = GIT_STR_INIT;
git_repository *repo;
refdb_fs_backend *backend;
@@ -2022,16 +2022,16 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
&normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0)
return error;
- if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
+ if (git_str_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
return -1;
- if ((error = loose_path(&old_path, git_buf_cstr(&temp_path), old_name)) < 0)
+ if ((error = loose_path(&old_path, git_str_cstr(&temp_path), old_name)) < 0)
return error;
- if ((error = loose_path(&new_path, git_buf_cstr(&temp_path), git_buf_cstr(&normalized))) < 0)
+ if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0)
return error;
- if (!git_path_exists(git_buf_cstr(&old_path))) {
+ if (!git_path_exists(git_str_cstr(&old_path))) {
error = GIT_ENOTFOUND;
goto cleanup;
}
@@ -2043,43 +2043,43 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
* - a/b -> a/b/c
* - a/b/c/d -> a/b/c
*/
- if ((error = loose_path(&temp_path, git_buf_cstr(&temp_path), "temp_reflog")) < 0)
+ if ((error = loose_path(&temp_path, git_str_cstr(&temp_path), "temp_reflog")) < 0)
return error;
- if ((fd = git_futils_mktmp(&temp_path, git_buf_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
+ if ((fd = git_futils_mktmp(&temp_path, git_str_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
error = -1;
goto cleanup;
}
p_close(fd);
- if (p_rename(git_buf_cstr(&old_path), git_buf_cstr(&temp_path)) < 0) {
+ if (p_rename(git_str_cstr(&old_path), git_str_cstr(&temp_path)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
error = -1;
goto cleanup;
}
- if (git_path_isdir(git_buf_cstr(&new_path)) &&
- (git_futils_rmdir_r(git_buf_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
+ if (git_path_isdir(git_str_cstr(&new_path)) &&
+ (git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
error = -1;
goto cleanup;
}
- if (git_futils_mkpath2file(git_buf_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
+ if (git_futils_mkpath2file(git_str_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
error = -1;
goto cleanup;
}
- if (p_rename(git_buf_cstr(&temp_path), git_buf_cstr(&new_path)) < 0) {
+ if (p_rename(git_str_cstr(&temp_path), git_str_cstr(&new_path)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
error = -1;
}
cleanup:
- git_buf_dispose(&temp_path);
- git_buf_dispose(&old_path);
- git_buf_dispose(&new_path);
- git_buf_dispose(&normalized);
+ git_str_dispose(&temp_path);
+ git_str_dispose(&old_path);
+ git_str_dispose(&new_path);
+ git_str_dispose(&normalized);
return error;
}
@@ -2087,7 +2087,7 @@ cleanup:
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
{
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(_backend);
@@ -2105,7 +2105,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -2115,7 +2115,7 @@ int git_refdb_backend_fs(
git_repository *repository)
{
int t = 0;
- git_buf gitpath = GIT_BUF_INIT;
+ git_str gitpath = GIT_STR_INIT;
refdb_fs_backend *backend;
backend = git__calloc(1, sizeof(refdb_fs_backend));
@@ -2140,13 +2140,13 @@ int git_refdb_backend_fs(
goto fail;
}
- if (git_buf_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
+ if (git_str_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
git_sortedcache_new(
&backend->refcache, offsetof(struct packref, name),
- NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
+ NULL, NULL, packref_cmp, git_str_cstr(&gitpath)) < 0)
goto fail;
- git_buf_dispose(&gitpath);
+ git_str_dispose(&gitpath);
if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
@@ -2182,7 +2182,7 @@ int git_refdb_backend_fs(
return 0;
fail:
- git_buf_dispose(&gitpath);
+ git_str_dispose(&gitpath);
git__free(backend->gitpath);
git__free(backend->commonpath);
git__free(backend);
diff --git a/src/refs.c b/src/refs.c
index 8acfa84a5..0ac455d24 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -247,7 +247,7 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
int error = 0, i, valid;
bool fallbackmode = true, foundvalid = false;
git_reference *ref;
- git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
+ git_str refnamebuf = GIT_STR_INIT, name = GIT_STR_INIT;
static const char *formatters[] = {
"%s",
@@ -260,18 +260,18 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
};
if (*refname)
- git_buf_puts(&name, refname);
+ git_str_puts(&name, refname);
else {
- git_buf_puts(&name, GIT_HEAD_FILE);
+ git_str_puts(&name, GIT_HEAD_FILE);
fallbackmode = false;
}
for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
- git_buf_clear(&refnamebuf);
+ git_str_clear(&refnamebuf);
- if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0 ||
- (error = git_reference_name_is_valid(&valid, git_buf_cstr(&refnamebuf))) < 0)
+ if ((error = git_str_printf(&refnamebuf, formatters[i], git_str_cstr(&name))) < 0 ||
+ (error = git_reference_name_is_valid(&valid, git_str_cstr(&refnamebuf))) < 0)
goto cleanup;
if (!valid) {
@@ -280,7 +280,7 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re
}
foundvalid = true;
- error = git_reference_lookup_resolved(&ref, repo, git_buf_cstr(&refnamebuf), -1);
+ error = git_reference_lookup_resolved(&ref, repo, git_str_cstr(&refnamebuf), -1);
if (!error) {
*out = ref;
@@ -296,14 +296,14 @@ cleanup:
if (error && !foundvalid) {
/* never found a valid reference name */
git_error_set(GIT_ERROR_REFERENCE,
- "could not use '%s' as valid reference name", git_buf_cstr(&name));
+ "could not use '%s' as valid reference name", git_str_cstr(&name));
}
if (error == GIT_ENOTFOUND)
git_error_set(GIT_ERROR_REFERENCE, "no reference found for shorthand '%s'", refname);
- git_buf_dispose(&name);
- git_buf_dispose(&refnamebuf);
+ git_str_dispose(&name);
+ git_str_dispose(&refnamebuf);
return error;
}
@@ -891,7 +891,7 @@ static bool is_all_caps_and_underscore(const char *name, size_t len)
/* Inspired from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/refs.c#L36-100 */
int git_reference__normalize_name(
- git_buf *buf,
+ git_str *buf,
const char *name,
unsigned int flags)
{
@@ -914,7 +914,7 @@ int git_reference__normalize_name(
goto cleanup;
if (normalize)
- git_buf_clear(buf);
+ git_str_clear(buf);
#ifdef GIT_USE_ICONV
if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) {
@@ -927,9 +927,9 @@ int git_reference__normalize_name(
#endif
if (!validate) {
- git_buf_sets(buf, current);
+ git_str_sets(buf, current);
- error = git_buf_oom(buf) ? -1 : 0;
+ error = git_str_oom(buf) ? -1 : 0;
goto cleanup;
}
@@ -949,13 +949,13 @@ int git_reference__normalize_name(
process_flags &= ~GIT_REFERENCE_FORMAT_REFSPEC_PATTERN;
if (normalize) {
- size_t cur_len = git_buf_len(buf);
+ size_t cur_len = git_str_len(buf);
- git_buf_joinpath(buf, git_buf_cstr(buf), current);
- git_buf_truncate(buf,
+ git_str_joinpath(buf, git_str_cstr(buf), current);
+ git_str_truncate(buf,
cur_len + segment_len + (segments_count ? 1 : 0));
- if (git_buf_oom(buf)) {
+ if (git_str_oom(buf)) {
error = -1;
goto cleanup;
}
@@ -1008,7 +1008,7 @@ cleanup:
"the given reference name '%s' is not valid", name);
if (error && normalize)
- git_buf_dispose(buf);
+ git_str_dispose(buf);
#ifdef GIT_USE_ICONV
git_path_iconv_clear(&ic);
@@ -1023,13 +1023,13 @@ int git_reference_normalize_name(
const char *name,
unsigned int flags)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
if ((error = git_reference__normalize_name(&buf, name, flags)) < 0)
goto cleanup;
- if (git_buf_len(&buf) > buffer_size - 1) {
+ if (git_str_len(&buf) > buffer_size - 1) {
git_error_set(
GIT_ERROR_REFERENCE,
"the provided buffer is too short to hold the normalization of '%s'", name);
@@ -1037,13 +1037,13 @@ int git_reference_normalize_name(
goto cleanup;
}
- if ((error = git_buf_copy_cstr(buffer_out, buffer_size, &buf)) < 0)
+ if ((error = git_str_copy_cstr(buffer_out, buffer_size, &buf)) < 0)
goto cleanup;
error = 0;
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -1143,12 +1143,12 @@ int git_reference__update_for_commit(
{
git_reference *ref_new = NULL;
git_commit *commit = NULL;
- git_buf reflog_msg = GIT_BUF_INIT;
+ git_str reflog_msg = GIT_STR_INIT;
const git_signature *who;
int error;
if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
- (error = git_buf_printf(&reflog_msg, "%s%s: %s",
+ (error = git_str_printf(&reflog_msg, "%s%s: %s",
operation ? operation : "commit",
commit_type(commit),
git_commit_summary(commit))) < 0)
@@ -1161,15 +1161,15 @@ int git_reference__update_for_commit(
return error;
error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who,
- git_buf_cstr(&reflog_msg), &ref->target.oid, NULL);
+ git_str_cstr(&reflog_msg), &ref->target.oid, NULL);
}
else
error = git_reference__update_terminal(
- repo, ref_name, id, who, git_buf_cstr(&reflog_msg));
+ repo, ref_name, id, who, git_str_cstr(&reflog_msg));
done:
git_reference_free(ref_new);
- git_buf_dispose(&reflog_msg);
+ git_str_dispose(&reflog_msg);
git_commit_free(commit);
return error;
}
diff --git a/src/refs.h b/src/refs.h
index 376a512f8..cb888bf8f 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -13,7 +13,7 @@
#include "git2/refs.h"
#include "git2/refdb.h"
#include "strmap.h"
-#include "buffer.h"
+#include "str.h"
#include "oid.h"
extern bool git_reference__enable_symbolic_ref_target_validation;
@@ -83,7 +83,7 @@ struct git_reference {
*/
git_reference *git_reference__realloc(git_reference **ptr_to_ref, const char *name);
-int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
+int git_reference__normalize_name(git_str *buf, const char *name, unsigned int flags);
int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message);
int git_reference__name_is_valid(int *valid, const char *name, unsigned int flags);
int git_reference__is_branch(const char *ref_name);
diff --git a/src/refspec.c b/src/refspec.c
index c72721a43..f0a0c2bfb 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -7,8 +7,7 @@
#include "refspec.h"
-#include "git2/errors.h"
-
+#include "buf.h"
#include "refs.h"
#include "util.h"
#include "vector.h"
@@ -243,16 +242,12 @@ int git_refspec_dst_matches(const git_refspec *refspec, const char *refname)
}
static int refspec_transform(
- git_buf *out, const char *from, const char *to, const char *name)
+ git_str *out, const char *from, const char *to, const char *name)
{
const char *from_star, *to_star;
size_t replacement_len, star_offset;
- int error;
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
- git_buf_clear(out);
+ git_str_clear(out);
/*
* There are two parts to each side of a refspec, the bit
@@ -269,72 +264,72 @@ static int refspec_transform(
star_offset = from_star - from;
/* the first half is copied over */
- git_buf_put(out, to, to_star - to);
+ git_str_put(out, to, to_star - to);
/*
* Copy over the name, but exclude the trailing part in "from" starting
* after the glob
*/
replacement_len = strlen(name + star_offset) - strlen(from_star + 1);
- git_buf_put(out, name + star_offset, replacement_len);
+ git_str_put(out, name + star_offset, replacement_len);
- return git_buf_puts(out, to_star + 1);
+ return git_str_puts(out, to_star + 1);
}
int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name)
{
- int error;
+ GIT_BUF_WRAP_PRIVATE(out, git_refspec__transform, spec, name);
+}
+int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name)
+{
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(spec);
GIT_ASSERT_ARG(name);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
if (!git_refspec_src_matches(spec, name)) {
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the source", name);
return -1;
}
if (!spec->pattern)
- return git_buf_puts(out, spec->dst ? spec->dst : "");
+ return git_str_puts(out, spec->dst ? spec->dst : "");
return refspec_transform(out, spec->src, spec->dst, name);
}
int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name)
{
- int error;
+ GIT_BUF_WRAP_PRIVATE(out, git_refspec__rtransform, spec, name);
+}
+int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name)
+{
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(spec);
GIT_ASSERT_ARG(name);
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
if (!git_refspec_dst_matches(spec, name)) {
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the destination", name);
return -1;
}
if (!spec->pattern)
- return git_buf_puts(out, spec->src);
+ return git_str_puts(out, spec->src);
return refspec_transform(out, spec->dst, spec->src, name);
}
-int git_refspec__serialize(git_buf *out, const git_refspec *refspec)
+int git_refspec__serialize(git_str *out, const git_refspec *refspec)
{
if (refspec->force)
- git_buf_putc(out, '+');
+ git_str_putc(out, '+');
- git_buf_printf(out, "%s:%s",
+ git_str_printf(out, "%s:%s",
refspec->src != NULL ? refspec->src : "",
refspec->dst != NULL ? refspec->dst : "");
- return git_buf_oom(out) == false;
+ return git_str_oom(out) == false;
}
int git_refspec_is_wildcard(const git_refspec *spec)
@@ -354,7 +349,7 @@ git_direction git_refspec_direction(const git_refspec *spec)
int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t j, pos;
git_remote_head key;
git_refspec *cur;
@@ -382,14 +377,14 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
/* shorthand on the lhs */
if (git__prefixcmp(spec->src, GIT_REFS_DIR)) {
for (j = 0; formatters[j]; j++) {
- git_buf_clear(&buf);
- git_buf_printf(&buf, formatters[j], spec->src);
- GIT_ERROR_CHECK_ALLOC_BUF(&buf);
+ git_str_clear(&buf);
+ git_str_printf(&buf, formatters[j], spec->src);
+ GIT_ERROR_CHECK_ALLOC_STR(&buf);
- key.name = (char *) git_buf_cstr(&buf);
+ key.name = (char *) git_str_cstr(&buf);
if (!git_vector_search(&pos, refs, &key)) {
/* we found something to match the shorthand, set src to that */
- cur->src = git_buf_detach(&buf);
+ cur->src = git_str_detach(&buf);
}
}
}
@@ -403,18 +398,18 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) {
/* if it starts with "remotes" then we just prepend "refs/" */
if (!git__prefixcmp(spec->dst, "remotes/")) {
- git_buf_puts(&buf, GIT_REFS_DIR);
+ git_str_puts(&buf, GIT_REFS_DIR);
} else {
- git_buf_puts(&buf, GIT_REFS_HEADS_DIR);
+ git_str_puts(&buf, GIT_REFS_HEADS_DIR);
}
- git_buf_puts(&buf, spec->dst);
- GIT_ERROR_CHECK_ALLOC_BUF(&buf);
+ git_str_puts(&buf, spec->dst);
+ GIT_ERROR_CHECK_ALLOC_STR(&buf);
- cur->dst = git_buf_detach(&buf);
+ cur->dst = git_str_detach(&buf);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (cur->dst == NULL && spec->dst != NULL) {
cur->dst = git__strdup(spec->dst);
diff --git a/src/refspec.h b/src/refspec.h
index 2b4111f04..bf4f7fcfb 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "git2/refspec.h"
-#include "buffer.h"
+#include "str.h"
#include "vector.h"
struct git_refspec {
@@ -25,6 +25,9 @@ struct git_refspec {
#define GIT_REFSPEC_TAGS "refs/tags/*:refs/tags/*"
+int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name);
+int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name);
+
int git_refspec__parse(
struct git_refspec *refspec,
const char *str,
@@ -32,7 +35,7 @@ int git_refspec__parse(
void git_refspec__dispose(git_refspec *refspec);
-int git_refspec__serialize(git_buf *out, const git_refspec *refspec);
+int git_refspec__serialize(git_str *out, const git_refspec *refspec);
/**
* Determines if a refspec is a wildcard refspec.
diff --git a/src/remote.c b/src/remote.c
index 56d7e42db..bde4ce779 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -7,11 +7,8 @@
#include "remote.h"
-#include "git2/config.h"
-#include "git2/types.h"
-#include "git2/oid.h"
-#include "git2/net.h"
-
+#include "buf.h"
+#include "branch.h"
#include "config.h"
#include "repository.h"
#include "fetch.h"
@@ -20,6 +17,11 @@
#include "fetchhead.h"
#include "push.h"
+#include "git2/config.h"
+#include "git2/types.h"
+#include "git2/oid.h"
+#include "git2/net.h"
+
#define CONFIG_URL_FMT "remote.%s.url"
#define CONFIG_PUSHURL_FMT "remote.%s.pushurl"
#define CONFIG_FETCH_FMT "remote.%s.fetch"
@@ -60,14 +62,14 @@ static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
static int download_tags_value(git_remote *remote, git_config *cfg)
{
git_config_entry *ce;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
- if (git_buf_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
+ if (git_str_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
return -1;
- error = git_config__lookup_entry(&ce, cfg, git_buf_cstr(&buf), false);
- git_buf_dispose(&buf);
+ error = git_config__lookup_entry(&ce, cfg, git_str_cstr(&buf), false);
+ git_str_dispose(&buf);
if (!error && ce && ce->value) {
if (!strcmp(ce->value, "--no-tags"))
@@ -99,7 +101,7 @@ static int ensure_remote_name_is_valid(const char *name)
static int write_add_refspec(git_repository *repo, const char *name, const char *refspec, bool fetch)
{
git_config *cfg;
- git_buf var = GIT_BUF_INIT;
+ git_str var = GIT_STR_INIT;
git_refspec spec;
const char *fmt;
int error;
@@ -117,7 +119,7 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
git_refspec__dispose(&spec);
- if ((error = git_buf_printf(&var, fmt, name)) < 0)
+ if ((error = git_str_printf(&var, fmt, name)) < 0)
return error;
/*
@@ -130,11 +132,11 @@ static int write_add_refspec(git_repository *repo, const char *name, const char
}
cleanup:
- git_buf_dispose(&var);
+ git_str_dispose(&var);
return 0;
}
-static int canonicalize_url(git_buf *out, const char *in)
+static int canonicalize_url(git_str *out, const char *in)
{
if (in == NULL || strlen(in) == 0) {
git_error_set(GIT_ERROR_INVALID, "cannot set empty URL");
@@ -149,18 +151,18 @@ static int canonicalize_url(git_buf *out, const char *in)
(git__isalpha(in[2]) || git__isdigit(in[2]))) {
const char *c;
for (c = in; *c; c++)
- git_buf_putc(out, *c == '\\' ? '/' : *c);
+ git_str_putc(out, *c == '\\' ? '/' : *c);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
#endif
- return git_buf_puts(out, in);
+ return git_str_puts(out, in);
}
-static int default_fetchspec_for_name(git_buf *buf, const char *name)
+static int default_fetchspec_for_name(git_str *buf, const char *name)
{
- if (git_buf_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
+ if (git_str_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
return -1;
return 0;
@@ -204,9 +206,9 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
{
git_remote *remote = NULL;
git_config *config_ro = NULL, *config_rw;
- git_buf canonical_url = GIT_BUF_INIT;
- git_buf var = GIT_BUF_INIT;
- git_buf specbuf = GIT_BUF_INIT;
+ git_str canonical_url = GIT_STR_INIT;
+ git_str var = GIT_STR_INIT;
+ git_str specbuf = GIT_STR_INIT;
const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
int error = -1;
@@ -254,7 +256,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
GIT_ERROR_CHECK_ALLOC(remote->name);
if (opts->repository &&
- ((error = git_buf_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 ||
+ ((error = git_str_printf(&var, CONFIG_URL_FMT, opts->name)) < 0 ||
(error = git_repository_config__weakptr(&config_rw, opts->repository)) < 0 ||
(error = git_config_set_string(config_rw, var.ptr, canonical_url.ptr)) < 0))
goto on_error;
@@ -269,7 +271,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
if ((error = default_fetchspec_for_name(&specbuf, opts->name)) < 0)
goto on_error;
- fetch = git_buf_cstr(&specbuf);
+ fetch = git_str_cstr(&specbuf);
}
if ((error = add_refspec(remote, fetch, true)) < 0)
@@ -293,7 +295,7 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
- git_buf_dispose(&var);
+ git_str_dispose(&var);
*out = remote;
error = 0;
@@ -303,15 +305,15 @@ on_error:
git_remote_free(remote);
git_config_free(config_ro);
- git_buf_dispose(&specbuf);
- git_buf_dispose(&canonical_url);
- git_buf_dispose(&var);
+ git_str_dispose(&specbuf);
+ git_str_dispose(&canonical_url);
+ git_str_dispose(&var);
return error;
}
int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
@@ -322,14 +324,14 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name,
if (canonicalize_url(&buf, url) < 0)
return GIT_ERROR;
- git_buf_clear(&buf);
+ git_str_clear(&buf);
opts.repository = repo;
opts.name = name;
error = git_remote_create_with_opts(out, url, &opts);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -425,13 +427,13 @@ static int refspec_cb(const git_config_entry *entry, void *payload)
}
static int get_optional_config(
- bool *found, git_config *config, git_buf *buf,
+ bool *found, git_config *config, git_str *buf,
git_config_foreach_cb cb, void *payload)
{
int error = 0;
- const char *key = git_buf_cstr(buf);
+ const char *key = git_str_cstr(buf);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
return -1;
if (cb != NULL)
@@ -453,7 +455,7 @@ static int get_optional_config(
int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
{
git_remote *remote = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
const char *val;
int error = 0;
git_config *config;
@@ -484,7 +486,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
goto cleanup;
}
- if ((error = git_buf_printf(&buf, "remote.%s.url", name)) < 0)
+ if ((error = git_str_printf(&buf, "remote.%s.url", name)) < 0)
goto cleanup;
if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0)
@@ -501,8 +503,8 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
}
val = NULL;
- git_buf_clear(&buf);
- git_buf_printf(&buf, "remote.%s.pushurl", name);
+ git_str_clear(&buf);
+ git_str_printf(&buf, "remote.%s.pushurl", name);
if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0)
goto cleanup;
@@ -523,15 +525,15 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
data.remote = remote;
data.fetch = true;
- git_buf_clear(&buf);
- git_buf_printf(&buf, "remote.%s.fetch", name);
+ git_str_clear(&buf);
+ git_str_printf(&buf, "remote.%s.fetch", name);
if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0)
goto cleanup;
data.fetch = false;
- git_buf_clear(&buf);
- git_buf_printf(&buf, "remote.%s.push", name);
+ git_str_clear(&buf);
+ git_str_printf(&buf, "remote.%s.push", name);
if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0)
goto cleanup;
@@ -550,7 +552,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
cleanup:
git_config_free(config);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
git_remote_free(remote);
@@ -560,12 +562,12 @@ cleanup:
static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
- git_buf_printf(&buf, "remote.%s.prune", name);
+ git_str_printf(&buf, "remote.%s.prune", name);
- if ((error = git_config_get_bool(&remote->prune_refs, config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_get_bool(&remote->prune_refs, config, git_str_cstr(&buf))) < 0) {
if (error == GIT_ENOTFOUND) {
git_error_clear();
@@ -578,7 +580,7 @@ static int lookup_remote_prune_config(git_remote *remote, git_config *config, co
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -619,7 +621,7 @@ int git_remote_set_instance_url(git_remote *remote, const char *url)
static int set_url(git_repository *repo, const char *remote, const char *pattern, const char *url)
{
git_config *cfg;
- git_buf buf = GIT_BUF_INIT, canonical_url = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, canonical_url = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(repo);
@@ -631,7 +633,7 @@ static int set_url(git_repository *repo, const char *remote, const char *pattern
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
- if ((error = git_buf_printf(&buf, pattern, remote)) < 0)
+ if ((error = git_str_printf(&buf, pattern, remote)) < 0)
return error;
if (url) {
@@ -644,8 +646,8 @@ static int set_url(git_repository *repo, const char *remote, const char *pattern
}
cleanup:
- git_buf_dispose(&canonical_url);
- git_buf_dispose(&buf);
+ git_str_dispose(&canonical_url);
+ git_str_dispose(&buf);
return error;
}
@@ -683,7 +685,7 @@ int git_remote_set_pushurl(git_repository *repo, const char *remote, const char
}
static int resolve_url(
- git_buf *resolved_url,
+ git_str *resolved_url,
const char *url,
int direction,
const git_remote_callbacks *callbacks)
@@ -692,27 +694,28 @@ static int resolve_url(
GIT_UNUSED(direction);
GIT_UNUSED(callbacks);
#else
- int status, error;
+ git_buf buf = GIT_BUF_INIT;
+ int error;
if (callbacks && callbacks->resolve_url) {
- git_buf_clear(resolved_url);
- status = callbacks->resolve_url(resolved_url, url, direction, callbacks->payload);
- if (status != GIT_PASSTHROUGH) {
- git_error_set_after_callback_function(status, "git_resolve_url_cb");
+ error = callbacks->resolve_url(&buf, url, direction, callbacks->payload);
- if ((error = git_buf_sanitize(resolved_url)) < 0)
- return error;
+ if (error != GIT_PASSTHROUGH) {
+ git_error_set_after_callback_function(error, "git_resolve_url_cb");
- return status;
+ git_str_set(resolved_url, buf.ptr, buf.size);
+ git_buf_dispose(&buf);
+
+ return error;
}
}
#endif
- return git_buf_sets(resolved_url, url);
+ return git_str_sets(resolved_url, url);
}
int git_remote__urlfordirection(
- git_buf *url_out,
+ git_str *url_out,
struct git_remote *remote,
int direction,
const git_remote_callbacks *callbacks)
@@ -767,7 +770,7 @@ static int set_transport_custom_headers(git_transport *t, const git_strarray *cu
int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn)
{
git_transport *t;
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
int flags = GIT_TRANSPORTFLAGS_NONE;
int error;
void *payload = NULL;
@@ -811,7 +814,7 @@ int git_remote__connect(git_remote *remote, git_direction direction, const git_r
remote->transport = t;
- git_buf_dispose(&url);
+ git_str_dispose(&url);
return 0;
@@ -819,7 +822,7 @@ on_error:
if (t)
t->free(t);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
if (t == remote->transport)
remote->transport = NULL;
@@ -885,7 +888,7 @@ static void url_config_trim(git_net_url *url)
static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
{
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_net_url lookup_url = GIT_NET_URL_INIT;
int error;
@@ -902,19 +905,19 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
/* remote.<name>.proxy config setting */
if (remote->name && remote->name[0]) {
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- if ((error = git_buf_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
+ if ((error = git_str_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
(error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
goto done;
}
while (true) {
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- if ((error = git_buf_puts(&buf, "http.")) < 0 ||
+ if ((error = git_str_puts(&buf, "http.")) < 0 ||
(error = git_net_url_fmt(&buf, &lookup_url)) < 0 ||
- (error = git_buf_puts(&buf, ".proxy")) < 0 ||
+ (error = git_str_puts(&buf, ".proxy")) < 0 ||
(error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
goto done;
@@ -924,20 +927,20 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
url_config_trim(&lookup_url);
}
- git_buf_clear(&buf);
+ git_str_clear(&buf);
error = lookup_config(out, cfg, "http.proxy");
done:
git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_net_url_dispose(&lookup_url);
return error;
}
static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
{
- git_buf proxy_env = GIT_BUF_INIT, no_proxy_env = GIT_BUF_INIT;
+ git_str proxy_env = GIT_STR_INIT, no_proxy_env = GIT_STR_INIT;
bool use_ssl = (strcmp(url->scheme, "https") == 0);
int error;
@@ -963,13 +966,13 @@ static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
goto done;
if (!git_net_url_matches_pattern_list(url, no_proxy_env.ptr))
- *out = git_buf_detach(&proxy_env);
+ *out = git_str_detach(&proxy_env);
else
error = GIT_ENOTFOUND;
done:
- git_buf_dispose(&proxy_env);
- git_buf_dispose(&no_proxy_env);
+ git_str_dispose(&proxy_env);
+ git_str_dispose(&no_proxy_env);
return error;
}
@@ -1135,7 +1138,7 @@ int git_remote_fetch(
int error, update_fetchhead = 1;
git_remote_autotag_option_t tagopt = remote->download_tags;
bool prune = false;
- git_buf reflog_msg_buf = GIT_BUF_INIT;
+ git_str reflog_msg_buf = GIT_STR_INIT;
const git_remote_callbacks *cbs = NULL;
git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
@@ -1164,15 +1167,15 @@ int git_remote_fetch(
/* Default reflog message */
if (reflog_message)
- git_buf_sets(&reflog_msg_buf, reflog_message);
+ git_str_sets(&reflog_msg_buf, reflog_message);
else {
- git_buf_printf(&reflog_msg_buf, "fetch %s",
+ git_str_printf(&reflog_msg_buf, "fetch %s",
remote->name ? remote->name : remote->url);
}
/* Create "remote/foo" branches for all remote branches */
- error = git_remote_update_tips(remote, cbs, update_fetchhead, tagopt, git_buf_cstr(&reflog_msg_buf));
- git_buf_dispose(&reflog_msg_buf);
+ error = git_remote_update_tips(remote, cbs, update_fetchhead, tagopt, git_str_cstr(&reflog_msg_buf));
+ git_str_dispose(&reflog_msg_buf);
if (error < 0)
return error;
@@ -1211,22 +1214,22 @@ static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *upda
return 0;
}
-static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name)
+static int ref_to_update(int *update, git_str *remote_name, git_remote *remote, git_refspec *spec, const char *ref_name)
{
int error = 0;
git_repository *repo;
- git_buf upstream_remote = GIT_BUF_INIT;
- git_buf upstream_name = GIT_BUF_INIT;
+ git_str upstream_remote = GIT_STR_INIT;
+ git_str upstream_name = GIT_STR_INIT;
repo = git_remote_owner(remote);
if ((!git_reference__is_branch(ref_name)) ||
!git_remote_name(remote) ||
- (error = git_branch_upstream_remote(&upstream_remote, repo, ref_name) < 0) ||
- git__strcmp(git_remote_name(remote), git_buf_cstr(&upstream_remote)) ||
- (error = git_branch_upstream_name(&upstream_name, repo, ref_name)) < 0 ||
- !git_refspec_dst_matches(spec, git_buf_cstr(&upstream_name)) ||
- (error = git_refspec_rtransform(remote_name, spec, upstream_name.ptr)) < 0) {
+ (error = git_branch__upstream_remote(&upstream_remote, repo, ref_name) < 0) ||
+ git__strcmp(git_remote_name(remote), git_str_cstr(&upstream_remote)) ||
+ (error = git_branch__upstream_name(&upstream_name, repo, ref_name)) < 0 ||
+ !git_refspec_dst_matches(spec, git_str_cstr(&upstream_name)) ||
+ (error = git_refspec__rtransform(remote_name, spec, upstream_name.ptr)) < 0) {
/* Not an error if there is no upstream */
if (error == GIT_ENOTFOUND) {
git_error_clear();
@@ -1238,15 +1241,15 @@ static int ref_to_update(int *update, git_buf *remote_name, git_remote *remote,
*update = 1;
}
- git_buf_dispose(&upstream_remote);
- git_buf_dispose(&upstream_name);
+ git_str_dispose(&upstream_remote);
+ git_str_dispose(&upstream_name);
return error;
}
static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_refspec *spec, git_vector *update_heads, git_reference *ref)
{
git_reference *resolved_ref = NULL;
- git_buf remote_name = GIT_BUF_INIT;
+ git_str remote_name = GIT_STR_INIT;
git_config *config = NULL;
const char *ref_name;
int error = 0, update;
@@ -1281,10 +1284,10 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
goto cleanup;
if (update)
- error = remote_head_for_fetchspec_src(out, update_heads, git_buf_cstr(&remote_name));
+ error = remote_head_for_fetchspec_src(out, update_heads, git_str_cstr(&remote_name));
cleanup:
- git_buf_dispose(&remote_name);
+ git_str_dispose(&remote_name);
git_reference_free(resolved_ref);
git_config_free(config);
return error;
@@ -1422,7 +1425,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
*/
git_vector_foreach(&candidates, i, refname) {
git_vector_foreach(&remote->active_refspecs, j, spec) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t pos;
char *src_name;
git_remote_head key = {0};
@@ -1430,12 +1433,12 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
if (!git_refspec_dst_matches(spec, refname))
continue;
- if ((error = git_refspec_rtransform(&buf, spec, refname)) < 0)
+ if ((error = git_refspec__rtransform(&buf, spec, refname)) < 0)
goto cleanup;
- key.name = (char *) git_buf_cstr(&buf);
+ key.name = (char *) git_str_cstr(&buf);
error = git_vector_bsearch(&pos, &remote_refs, &key);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
@@ -1508,7 +1511,7 @@ static int update_tips_for_spec(
{
int error = 0, autotag, valid;
unsigned int i = 0;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
git_oid old;
git_odb *odb;
git_remote_head *head;
@@ -1531,7 +1534,7 @@ static int update_tips_for_spec(
for (; i < refs->length; ++i) {
head = git_vector_get(refs, i);
autotag = 0;
- git_buf_clear(&refname);
+ git_str_clear(&refname);
/* Ignore malformed ref names (which also saves us from tag^{} */
if (git_reference_name_is_valid(&valid, head->name) < 0)
@@ -1547,8 +1550,8 @@ static int update_tips_for_spec(
if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_AUTO)
autotag = 1;
- git_buf_clear(&refname);
- if (git_buf_puts(&refname, head->name) < 0)
+ git_str_clear(&refname);
+ if (git_str_puts(&refname, head->name) < 0)
goto on_error;
}
}
@@ -1556,7 +1559,7 @@ static int update_tips_for_spec(
/* If we didn't want to auto-follow the tag, check if the refspec matches */
if (!autotag && git_refspec_src_matches(spec, head->name)) {
if (spec->dst) {
- if (git_refspec_transform(&refname, spec, head->name) < 0)
+ if (git_refspec__transform(&refname, spec, head->name) < 0)
goto on_error;
} else {
/*
@@ -1571,7 +1574,7 @@ static int update_tips_for_spec(
}
/* If we still don't have a refname, we don't want it */
- if (git_buf_len(&refname) == 0) {
+ if (git_str_len(&refname) == 0) {
continue;
}
@@ -1625,13 +1628,13 @@ static int update_tips_for_spec(
git_vector_free(&update_heads);
git_refspec__dispose(&tagspec);
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
return 0;
on_error:
git_vector_free(&update_heads);
git_refspec__dispose(&tagspec);
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
return -1;
}
@@ -1704,7 +1707,7 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
git_refspec *spec;
git_remote_head *head;
git_reference *ref;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
int error = 0;
i = j = k = 0;
@@ -1719,8 +1722,8 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
* FETCH_HEAD
*/
- git_buf_clear(&refname);
- if ((error = git_refspec_transform(&refname, spec, head->name)) < 0)
+ git_str_clear(&refname);
+ if ((error = git_refspec__transform(&refname, spec, head->name)) < 0)
goto cleanup;
error = git_reference_name_to_id(&old, remote->repo, refname.ptr);
@@ -1749,20 +1752,20 @@ static int opportunistic_updates(const git_remote *remote, const git_remote_call
error = 0;
cleanup:
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
return error;
}
static int truncate_fetch_head(const char *gitdir)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
- if ((error = git_buf_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
+ if ((error = git_str_joinpath(&path, gitdir, GIT_FETCH_HEAD_FILE)) < 0)
return error;
error = git_futils_truncate(path.ptr, GIT_REFS_FILE_MODE);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1943,7 +1946,7 @@ git_remote_autotag_option_t git_remote_autotag(const git_remote *remote)
int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value)
{
- git_buf var = GIT_BUF_INIT;
+ git_str var = GIT_STR_INIT;
git_config *config;
int error;
@@ -1955,7 +1958,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
return error;
- if ((error = git_buf_printf(&var, CONFIG_TAGOPT_FMT, remote)))
+ if ((error = git_str_printf(&var, CONFIG_TAGOPT_FMT, remote)))
return error;
switch (value) {
@@ -1975,7 +1978,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
error = -1;
}
- git_buf_dispose(&var);
+ git_str_dispose(&var);
return error;
}
@@ -1989,25 +1992,25 @@ static int rename_remote_config_section(
const char *old_name,
const char *new_name)
{
- git_buf old_section_name = GIT_BUF_INIT,
- new_section_name = GIT_BUF_INIT;
+ git_str old_section_name = GIT_STR_INIT,
+ new_section_name = GIT_STR_INIT;
int error = -1;
- if (git_buf_printf(&old_section_name, "remote.%s", old_name) < 0)
+ if (git_str_printf(&old_section_name, "remote.%s", old_name) < 0)
goto cleanup;
if (new_name &&
- (git_buf_printf(&new_section_name, "remote.%s", new_name) < 0))
+ (git_str_printf(&new_section_name, "remote.%s", new_name) < 0))
goto cleanup;
error = git_config_rename_section(
repo,
- git_buf_cstr(&old_section_name),
- new_name ? git_buf_cstr(&new_section_name) : NULL);
+ git_str_cstr(&old_section_name),
+ new_name ? git_str_cstr(&new_section_name) : NULL);
cleanup:
- git_buf_dispose(&old_section_name);
- git_buf_dispose(&new_section_name);
+ git_str_dispose(&old_section_name);
+ git_str_dispose(&new_section_name);
return error;
}
@@ -2056,27 +2059,27 @@ static int rename_one_remote_reference(
{
int error;
git_reference *ref = NULL, *dummy = NULL;
- git_buf namespace = GIT_BUF_INIT, old_namespace = GIT_BUF_INIT;
- git_buf new_name = GIT_BUF_INIT;
- git_buf log_message = GIT_BUF_INIT;
+ git_str namespace = GIT_STR_INIT, old_namespace = GIT_STR_INIT;
+ git_str new_name = GIT_STR_INIT;
+ git_str log_message = GIT_STR_INIT;
size_t pfx_len;
const char *target;
- if ((error = git_buf_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
+ if ((error = git_str_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
return error;
pfx_len = strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name) + 1;
- git_buf_puts(&new_name, namespace.ptr);
- if ((error = git_buf_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
+ git_str_puts(&new_name, namespace.ptr);
+ if ((error = git_str_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
goto cleanup;
- if ((error = git_buf_printf(&log_message,
+ if ((error = git_str_printf(&log_message,
"renamed remote %s to %s",
old_remote_name, new_remote_name)) < 0)
goto cleanup;
- if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
- git_buf_cstr(&log_message))) < 0)
+ if ((error = git_reference_rename(&ref, reference_in, git_str_cstr(&new_name), 1,
+ git_str_cstr(&log_message))) < 0)
goto cleanup;
if (git_reference_type(ref) != GIT_REFERENCE_SYMBOLIC)
@@ -2084,29 +2087,29 @@ static int rename_one_remote_reference(
/* Handle refs like origin/HEAD -> origin/master */
target = git_reference_symbolic_target(ref);
- if ((error = git_buf_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
+ if ((error = git_str_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
goto cleanup;
if (git__prefixcmp(target, old_namespace.ptr))
goto cleanup;
- git_buf_clear(&new_name);
- git_buf_puts(&new_name, namespace.ptr);
- if ((error = git_buf_puts(&new_name, target + pfx_len)) < 0)
+ git_str_clear(&new_name);
+ git_str_puts(&new_name, namespace.ptr);
+ if ((error = git_str_puts(&new_name, target + pfx_len)) < 0)
goto cleanup;
- error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
- git_buf_cstr(&log_message));
+ error = git_reference_symbolic_set_target(&dummy, ref, git_str_cstr(&new_name),
+ git_str_cstr(&log_message));
git_reference_free(dummy);
cleanup:
git_reference_free(reference_in);
git_reference_free(ref);
- git_buf_dispose(&namespace);
- git_buf_dispose(&old_namespace);
- git_buf_dispose(&new_name);
- git_buf_dispose(&log_message);
+ git_str_dispose(&namespace);
+ git_str_dispose(&old_namespace);
+ git_str_dispose(&new_name);
+ git_str_dispose(&log_message);
return error;
}
@@ -2116,15 +2119,15 @@ static int rename_remote_references(
const char *new_name)
{
int error;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_reference *ref;
git_reference_iterator *iter;
- if ((error = git_buf_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
+ if ((error = git_str_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
return error;
- error = git_reference_iterator_glob_new(&iter, repo, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ error = git_reference_iterator_glob_new(&iter, repo, git_str_cstr(&buf));
+ git_str_dispose(&buf);
if (error < 0)
return error;
@@ -2142,7 +2145,7 @@ static int rename_remote_references(
static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const char *new_name)
{
git_config *config;
- git_buf base = GIT_BUF_INIT, var = GIT_BUF_INIT, val = GIT_BUF_INIT;
+ git_str base = GIT_STR_INIT, var = GIT_STR_INIT, val = GIT_STR_INIT;
const git_refspec *spec;
size_t i;
int error = 0;
@@ -2161,7 +2164,7 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
continue;
/* Does the dst part of the refspec follow the expected format? */
- if (strcmp(git_buf_cstr(&base), spec->string)) {
+ if (strcmp(git_str_cstr(&base), spec->string)) {
char *dup;
dup = git__strdup(spec->string);
@@ -2175,24 +2178,24 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
/* If we do want to move it to the new section */
- git_buf_clear(&val);
- git_buf_clear(&var);
+ git_str_clear(&val);
+ git_str_clear(&var);
if (default_fetchspec_for_name(&val, new_name) < 0 ||
- git_buf_printf(&var, "remote.%s.fetch", new_name) < 0)
+ git_str_printf(&var, "remote.%s.fetch", new_name) < 0)
{
error = -1;
break;
}
if ((error = git_config_set_string(
- config, git_buf_cstr(&var), git_buf_cstr(&val))) < 0)
+ config, git_str_cstr(&var), git_str_cstr(&val))) < 0)
break;
}
- git_buf_dispose(&base);
- git_buf_dispose(&var);
- git_buf_dispose(&val);
+ git_str_dispose(&base);
+ git_str_dispose(&var);
+ git_str_dispose(&val);
if (error < 0) {
char *str;
@@ -2247,7 +2250,7 @@ cleanup:
int git_remote_name_is_valid(int *valid, const char *remote_name)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_refspec refspec = {0};
int error;
@@ -2258,10 +2261,10 @@ int git_remote_name_is_valid(int *valid, const char *remote_name)
if (!remote_name || *remote_name == '\0')
return 0;
- if ((error = git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
+ if ((error = git_str_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
goto done;
- error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
+ error = git_refspec__parse(&refspec, git_str_cstr(&buf), true);
if (!error)
*valid = 1;
@@ -2269,7 +2272,7 @@ int git_remote_name_is_valid(int *valid, const char *remote_name)
error = 0;
done:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_refspec__dispose(&refspec);
return error;
@@ -2401,7 +2404,7 @@ static int remove_branch_config_related_entries(
git_config *config;
git_config_entry *entry;
git_config_iterator *iter;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
return error;
@@ -2422,21 +2425,21 @@ static int remove_branch_config_related_entries(
break;
}
- git_buf_clear(&buf);
- if ((error = git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
+ git_str_clear(&buf);
+ if ((error = git_str_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) {
if (error != GIT_ENOTFOUND)
break;
git_error_clear();
}
- git_buf_clear(&buf);
- if ((error = git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
+ git_str_clear(&buf);
+ if ((error = git_str_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_delete_entry(config, git_str_cstr(&buf))) < 0) {
if (error != GIT_ENOTFOUND)
break;
git_error_clear();
@@ -2446,7 +2449,7 @@ static int remove_branch_config_related_entries(
if (error == GIT_ITEROVER)
error = 0;
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_iterator_free(iter);
return error;
}
@@ -2541,11 +2544,16 @@ int git_remote_delete(git_repository *repo, const char *name)
int git_remote_default_branch(git_buf *out, git_remote *remote)
{
+ GIT_BUF_WRAP_PRIVATE(out, git_remote__default_branch, remote);
+}
+
+int git_remote__default_branch(git_str *out, git_remote *remote)
+{
const git_remote_head **heads;
const git_remote_head *guess = NULL;
const git_oid *head_id;
size_t heads_len, i;
- git_buf local_default = GIT_BUF_INIT;
+ git_str local_default = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
@@ -2558,12 +2566,9 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
goto done;
}
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
/* the first one must be HEAD so if that has the symref info, we're done */
if (heads[0]->symref_target) {
- error = git_buf_puts(out, heads[0]->symref_target);
+ error = git_str_puts(out, heads[0]->symref_target);
goto done;
}
@@ -2601,10 +2606,10 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
goto done;
}
- error = git_buf_puts(out, guess->name);
+ error = git_str_puts(out, guess->name);
done:
- git_buf_dispose(&local_default);
+ git_str_dispose(&local_default);
return error;
}
@@ -2720,7 +2725,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
char *replacement = NULL;
const char *regexp;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
git_config_entry *entry;
git_config_iterator *iter;
@@ -2768,7 +2773,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
if (match_length == 0)
return git__strdup(url);
- git_buf_printf(&result, "%s%s", replacement, url + match_length);
+ git_str_printf(&result, "%s%s", replacement, url + match_length);
git__free(replacement);
diff --git a/src/remote.h b/src/remote.h
index ce92db76a..77eefdf40 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -46,10 +46,12 @@ typedef struct git_remote_connection_opts {
int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn);
-int git_remote__urlfordirection(git_buf *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks);
+int git_remote__urlfordirection(git_str *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks);
int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url);
git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname);
git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname);
+int git_remote__default_branch(git_str *out, git_remote *remote);
+
#endif
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();
diff --git a/src/repository.h b/src/repository.h
index cbc160140..1ea5a44f7 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -19,7 +19,7 @@
#include "array.h"
#include "cache.h"
#include "refs.h"
-#include "buffer.h"
+#include "str.h"
#include "object.h"
#include "attrcache.h"
#include "submodule.h"
@@ -148,7 +148,7 @@ struct git_repository {
char *ident_name;
char *ident_email;
- git_array_t(git_buf) reserved_names;
+ git_array_t(git_str) reserved_names;
unsigned is_bare:1;
unsigned is_worktree:1;
@@ -196,6 +196,8 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo);
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item);
void git_repository__configmap_lookup_cache_clear(git_repository *repo);
+int git_repository__item_path(git_str *out, const git_repository *repo, git_repository_item_t item);
+
GIT_INLINE(int) git_repository__ensure_not_bare(
git_repository *repo,
const char *operation_name)
@@ -216,10 +218,10 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
/* The default "reserved names" for a repository */
-extern git_buf git_repository__reserved_names_win32[];
+extern git_str git_repository__reserved_names_win32[];
extern size_t git_repository__reserved_names_win32_len;
-extern git_buf git_repository__reserved_names_posix[];
+extern git_str git_repository__reserved_names_posix[];
extern size_t git_repository__reserved_names_posix_len;
/*
@@ -233,13 +235,13 @@ extern size_t git_repository__reserved_names_posix_len;
* will still be populated with good defaults.
*/
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);
/*
* The default branch for the repository; the `init.defaultBranch`
* configuration option, if set, or `master` if it is not.
*/
-int git_repository_initialbranch(git_buf *out, git_repository *repo);
+int git_repository_initialbranch(git_str *out, git_repository *repo);
/*
* Given a relative `path`, this makes it absolute based on the
@@ -247,7 +249,7 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo);
* to ensure that the path is not longer than MAX_PATH on Windows
* (unless `core.longpaths` is set in the repo config).
*/
-int git_repository_workdir_path(git_buf *out, git_repository *repo, const char *path);
+int git_repository_workdir_path(git_str *out, git_repository *repo, const char *path);
int git_repository__extensions(char ***out, size_t *out_len);
int git_repository__set_extensions(const char **extensions, size_t len);
diff --git a/src/reset.c b/src/reset.c
index f21a620c6..b8327fe5e 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -111,7 +111,7 @@ static int reset(
git_tree *tree = NULL;
int error = 0;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf log_message = GIT_BUF_INIT;
+ git_str log_message = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(target);
@@ -144,7 +144,7 @@ static int reset(
goto cleanup;
}
- if ((error = git_buf_printf(&log_message, "reset: moving to %s", to)) < 0)
+ if ((error = git_str_printf(&log_message, "reset: moving to %s", to)) < 0)
return error;
if (reset_type == GIT_RESET_HARD) {
@@ -157,7 +157,7 @@ static int reset(
/* move HEAD to the new target */
if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
- git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0)
+ git_object_id(commit), NULL, git_str_cstr(&log_message))) < 0)
goto cleanup;
if (reset_type > GIT_RESET_SOFT) {
@@ -177,7 +177,7 @@ cleanup:
git_object_free(commit);
git_index_free(index);
git_tree_free(tree);
- git_buf_dispose(&log_message);
+ git_str_dispose(&log_message);
return error;
}
diff --git a/src/revert.c b/src/revert.c
index 683f0d70d..d6ab6ae3c 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -25,10 +25,10 @@ static int write_revert_head(
const char *commit_oidstr)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 0;
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 &&
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_REVERT_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);
@@ -36,7 +36,7 @@ static int write_revert_head(
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -47,10 +47,10 @@ static int write_merge_msg(
const char *commit_msgline)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
int error = 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_CREATE_LEADING_DIRS, GIT_REVERT_FILE_MODE)) < 0 ||
(error = git_filebuf_printf(&file, "Revert \"%s\"\n\nThis reverts commit %s.\n",
commit_msgline, commit_oidstr)) < 0)
@@ -62,7 +62,7 @@ cleanup:
if (error < 0)
git_filebuf_cleanup(&file);
- git_buf_dispose(&file_path);
+ git_str_dispose(&file_path);
return error;
}
@@ -178,7 +178,7 @@ int git_revert(
git_commit *our_commit = NULL;
char commit_oidstr[GIT_OID_HEXSZ + 1];
const char *commit_msg;
- git_buf their_label = GIT_BUF_INIT;
+ git_str their_label = GIT_STR_INIT;
git_index *index = NULL;
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
int error;
@@ -199,8 +199,8 @@ int git_revert(
goto on_error;
}
- if ((error = git_buf_printf(&their_label, "parent of %.7s... %s", commit_oidstr, commit_msg)) < 0 ||
- (error = revert_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
+ if ((error = git_str_printf(&their_label, "parent of %.7s... %s", commit_oidstr, commit_msg)) < 0 ||
+ (error = revert_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 ||
(error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 ||
(error = write_revert_head(repo, commit_oidstr)) < 0 ||
(error = write_merge_msg(repo, commit_oidstr, commit_msg)) < 0 ||
@@ -223,7 +223,7 @@ done:
git_index_free(index);
git_commit_free(our_commit);
git_reference_free(our_ref);
- git_buf_dispose(&their_label);
+ git_str_dispose(&their_label);
return error;
}
diff --git a/src/revparse.c b/src/revparse.c
index b4d5d4759..cf39936a5 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -7,7 +7,7 @@
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "tree.h"
#include "refdb.h"
#include "regexp.h"
@@ -145,7 +145,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
size_t i, numentries, cur;
const git_reflog_entry *entry;
const char *msg;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cur = position;
@@ -179,16 +179,16 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
if (cur > 0)
continue;
- if ((git_buf_put(&buf, msg+regexmatches[1].start, regexmatches[1].end - regexmatches[1].start)) < 0)
+ if ((git_str_put(&buf, msg+regexmatches[1].start, regexmatches[1].end - regexmatches[1].start)) < 0)
goto cleanup;
- if ((error = git_reference_dwim(base_ref, repo, git_buf_cstr(&buf))) == 0)
+ if ((error = git_reference_dwim(base_ref, repo, git_str_cstr(&buf))) == 0)
goto cleanup;
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
- error = maybe_abbrev(out, repo, git_buf_cstr(&buf));
+ error = maybe_abbrev(out, repo, git_str_cstr(&buf));
goto cleanup;
}
@@ -197,7 +197,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
cleanup:
git_reference_free(ref);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_regexp_dispose(&preg);
git_reflog_free(reflog);
return error;
@@ -314,12 +314,12 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
{
bool is_numeric;
int parsed = 0, error = -1;
- git_buf identifier = GIT_BUF_INIT;
+ git_str identifier = GIT_STR_INIT;
git_time_t timestamp;
GIT_ASSERT(*out == NULL);
- if (git_buf_put(&identifier, spec, identifier_len) < 0)
+ if (git_str_put(&identifier, spec, identifier_len) < 0)
return -1;
is_numeric = !try_parse_numeric(&parsed, curly_braces_content);
@@ -331,15 +331,15 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
if (is_numeric) {
if (parsed < 0)
- error = retrieve_previously_checked_out_branch_or_revision(out, ref, repo, git_buf_cstr(&identifier), -parsed);
+ error = retrieve_previously_checked_out_branch_or_revision(out, ref, repo, git_str_cstr(&identifier), -parsed);
else
- error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), parsed);
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), parsed);
goto cleanup;
}
if (!strcmp(curly_braces_content, "u") || !strcmp(curly_braces_content, "upstream")) {
- error = retrieve_remote_tracking_reference(ref, git_buf_cstr(&identifier), repo);
+ error = retrieve_remote_tracking_reference(ref, git_str_cstr(&identifier), repo);
goto cleanup;
}
@@ -347,10 +347,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
if (git__date_parse(&timestamp, curly_braces_content) < 0)
goto cleanup;
- error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), (size_t)timestamp);
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);
cleanup:
- git_buf_dispose(&identifier);
+ git_str_dispose(&identifier);
return error;
}
@@ -520,9 +520,9 @@ static int handle_caret_curly_syntax(git_object **out, git_object *obj, const ch
return git_object_peel(out, obj, expected_type);
}
-static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *pos)
+static int extract_curly_braces_content(git_str *buf, const char *spec, size_t *pos)
{
- git_buf_clear(buf);
+ git_str_clear(buf);
GIT_ASSERT_ARG(spec[*pos] == '^' || spec[*pos] == '@');
@@ -537,7 +537,7 @@ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *
if (spec[*pos] == '\0')
return GIT_EINVALIDSPEC;
- if (git_buf_putc(buf, spec[(*pos)++]) < 0)
+ if (git_str_putc(buf, spec[(*pos)++]) < 0)
return -1;
}
@@ -546,18 +546,18 @@ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *
return 0;
}
-static int extract_path(git_buf *buf, const char *spec, size_t *pos)
+static int extract_path(git_str *buf, const char *spec, size_t *pos)
{
- git_buf_clear(buf);
+ git_str_clear(buf);
GIT_ASSERT_ARG(spec[*pos] == ':');
(*pos)++;
- if (git_buf_puts(buf, spec + *pos) < 0)
+ if (git_str_puts(buf, spec + *pos) < 0)
return -1;
- *pos += git_buf_len(buf);
+ *pos += git_str_len(buf);
return 0;
}
@@ -610,7 +610,7 @@ static int object_from_reference(git_object **object, git_reference *reference)
static int ensure_base_rev_loaded(git_object **object, git_reference **reference, const char *spec, size_t identifier_len, git_repository *repo, bool allow_empty_identifier)
{
int error;
- git_buf identifier = GIT_BUF_INIT;
+ git_str identifier = GIT_STR_INIT;
if (*object != NULL)
return 0;
@@ -621,11 +621,11 @@ static int ensure_base_rev_loaded(git_object **object, git_reference **reference
if (!allow_empty_identifier && identifier_len == 0)
return GIT_EINVALIDSPEC;
- if (git_buf_put(&identifier, spec, identifier_len) < 0)
+ if (git_str_put(&identifier, spec, identifier_len) < 0)
return -1;
- error = revparse_lookup_object(object, reference, repo, git_buf_cstr(&identifier));
- git_buf_dispose(&identifier);
+ error = revparse_lookup_object(object, reference, repo, git_str_cstr(&identifier));
+ git_str_dispose(&identifier);
return error;
}
@@ -669,7 +669,7 @@ static int revparse(
{
size_t pos = 0, identifier_len = 0;
int error = -1, n;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_reference *reference = NULL;
git_object *base_rev = NULL;
@@ -698,7 +698,7 @@ static int revparse(
if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
goto cleanup;
- if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
+ if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_str_cstr(&buf))) < 0)
goto cleanup;
git_object_free(base_rev);
@@ -750,11 +750,11 @@ static int revparse(
if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0)
goto cleanup;
- if ((error = handle_colon_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
+ if ((error = handle_colon_syntax(&temp_object, base_rev, git_str_cstr(&buf))) < 0)
goto cleanup;
} else {
- if (*git_buf_cstr(&buf) == '/') {
- if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_buf_cstr(&buf) + 1)) < 0)
+ if (*git_str_cstr(&buf) == '/') {
+ if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_str_cstr(&buf) + 1)) < 0)
goto cleanup;
} else {
@@ -783,7 +783,7 @@ static int revparse(
if ((error = ensure_base_rev_is_not_known_yet(base_rev)) < 0)
goto cleanup;
- if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_buf_cstr(&buf))) < 0)
+ if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_str_cstr(&buf))) < 0)
goto cleanup;
if (temp_object != NULL)
@@ -824,7 +824,7 @@ cleanup:
git_reference_free(reference);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/revwalk.c b/src/revwalk.c
index a686a9f6f..e29e9c9b9 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -131,7 +131,7 @@ int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwal
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
int error = 0;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_reference *ref;
git_reference_iterator *iter;
size_t wildcard;
@@ -144,15 +144,15 @@ int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwal
/* refs/ is implied if not given in the glob */
if (git__prefixcmp(glob, GIT_REFS_DIR) != 0)
- git_buf_joinpath(&buf, GIT_REFS_DIR, glob);
+ git_str_joinpath(&buf, GIT_REFS_DIR, glob);
else
- git_buf_puts(&buf, glob);
- GIT_ERROR_CHECK_ALLOC_BUF(&buf);
+ git_str_puts(&buf, glob);
+ GIT_ERROR_CHECK_ALLOC_STR(&buf);
/* If no '?', '*' or '[' exist, we append '/ *' to the glob */
wildcard = strcspn(glob, "?*[");
if (!glob[wildcard])
- git_buf_put(&buf, "/*", 2);
+ git_str_put(&buf, "/*", 2);
if ((error = git_reference_iterator_glob_new(&iter, walk->repo, buf.ptr)) < 0)
goto out;
@@ -169,7 +169,7 @@ int git_revwalk__push_glob(git_revwalk *walk, const char *glob, const git_revwal
if (error == GIT_ITEROVER)
error = 0;
out:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/src/signature.c b/src/signature.c
index 1efda212a..acd5fd72b 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -299,7 +299,7 @@ int git_signature_from_buffer(git_signature **out, const char *buf)
return error;
}
-void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig)
+void git_signature__writebuf(git_str *buf, const char *header, const git_signature *sig)
{
int offset, hours, mins;
char sign;
@@ -313,7 +313,7 @@ void git_signature__writebuf(git_buf *buf, const char *header, const git_signatu
hours = offset / 60;
mins = offset % 60;
- git_buf_printf(buf, "%s%s <%s> %u %c%02d%02d\n",
+ git_str_printf(buf, "%s%s <%s> %u %c%02d%02d\n",
header ? header : "", sig->name, sig->email,
(unsigned)sig->when.time, sign, hours, mins);
}
diff --git a/src/signature.h b/src/signature.h
index 40d7c54f9..5c8270954 100644
--- a/src/signature.h
+++ b/src/signature.h
@@ -15,7 +15,7 @@
#include <time.h>
int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender);
-void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig);
+void git_signature__writebuf(git_str *buf, const char *header, const git_signature *sig);
bool git_signature__equal(const git_signature *one, const git_signature *two);
int git_signature__pdup(git_signature **dest, const git_signature *source, git_pool *pool);
diff --git a/src/sortedcache.c b/src/sortedcache.c
index ee6363f6d..7ff900efe 100644
--- a/src/sortedcache.c
+++ b/src/sortedcache.c
@@ -201,7 +201,7 @@ void git_sortedcache_runlock(git_sortedcache *sc)
/* if the file has changed, lock cache and load file contents into buf;
* returns <0 on error, >0 if file has not changed
*/
-int git_sortedcache_lockandload(git_sortedcache *sc, git_buf *buf)
+int git_sortedcache_lockandload(git_sortedcache *sc, git_str *buf)
{
int error, fd;
struct stat st;
diff --git a/src/sortedcache.h b/src/sortedcache.h
index 0e1f63ceb..ef260a093 100644
--- a/src/sortedcache.h
+++ b/src/sortedcache.h
@@ -121,7 +121,7 @@ void git_sortedcache_wunlock(git_sortedcache *sc);
* @return 0 if up-to-date, 1 if out-of-date, <0 on error
*/
GIT_WARN_UNUSED_RESULT int git_sortedcache_lockandload(
- git_sortedcache *sc, git_buf *buf);
+ git_sortedcache *sc, git_str *buf);
/* Refresh file timestamp after write completes
* You should already be holding the write lock when you call this.
diff --git a/src/stash.c b/src/stash.c
index 49ea26fdd..5fc01ac36 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -9,7 +9,6 @@
#include "repository.h"
#include "commit.h"
-#include "message.h"
#include "tree.h"
#include "reflog.h"
#include "blob.h"
@@ -43,20 +42,20 @@ static int retrieve_head(git_reference **out, git_repository *repo)
return error;
}
-static int append_abbreviated_oid(git_buf *out, const git_oid *b_commit)
+static int append_abbreviated_oid(git_str *out, const git_oid *b_commit)
{
char *formatted_oid;
formatted_oid = git_oid_allocfmt(b_commit);
GIT_ERROR_CHECK_ALLOC(formatted_oid);
- git_buf_put(out, formatted_oid, 7);
+ git_str_put(out, formatted_oid, 7);
git__free(formatted_oid);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
-static int append_commit_description(git_buf *out, git_commit *commit)
+static int append_commit_description(git_str *out, git_commit *commit)
{
const char *summary = git_commit_summary(commit);
GIT_ERROR_CHECK_ALLOC(summary);
@@ -64,16 +63,16 @@ static int append_commit_description(git_buf *out, git_commit *commit)
if (append_abbreviated_oid(out, git_commit_id(commit)) < 0)
return -1;
- git_buf_putc(out, ' ');
- git_buf_puts(out, summary);
- git_buf_putc(out, '\n');
+ git_str_putc(out, ' ');
+ git_str_puts(out, summary);
+ git_str_putc(out, '\n');
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
static int retrieve_base_commit_and_message(
git_commit **b_commit,
- git_buf *stash_message,
+ git_str *stash_message,
git_repository *repo)
{
git_reference *head = NULL;
@@ -83,9 +82,9 @@ static int retrieve_base_commit_and_message(
return error;
if (strcmp("HEAD", git_reference_name(head)) == 0)
- error = git_buf_puts(stash_message, "(no branch): ");
+ error = git_str_puts(stash_message, "(no branch): ");
else
- error = git_buf_printf(
+ error = git_str_printf(
stash_message,
"%s: ",
git_reference_name(head) + strlen(GIT_REFS_HEADS_DIR));
@@ -128,13 +127,13 @@ static int commit_index(
{
git_tree *i_tree = NULL;
git_oid i_commit_oid;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
int error;
if ((error = build_tree_from_index(&i_tree, repo, index)) < 0)
goto cleanup;
- if ((error = git_buf_printf(&msg, "index on %s\n", message)) < 0)
+ if ((error = git_str_printf(&msg, "index on %s\n", message)) < 0)
goto cleanup;
if ((error = git_commit_create(
@@ -144,7 +143,7 @@ static int commit_index(
stasher,
stasher,
NULL,
- git_buf_cstr(&msg),
+ git_str_cstr(&msg),
i_tree,
1,
&parent)) < 0)
@@ -154,7 +153,7 @@ static int commit_index(
cleanup:
git_tree_free(i_tree);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
return error;
}
@@ -303,13 +302,13 @@ static int commit_untracked(
{
git_tree *u_tree = NULL;
git_oid u_commit_oid;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
int error;
if ((error = build_untracked_tree(&u_tree, repo, i_commit, flags)) < 0)
goto cleanup;
- if ((error = git_buf_printf(&msg, "untracked files on %s\n", message)) < 0)
+ if ((error = git_str_printf(&msg, "untracked files on %s\n", message)) < 0)
goto cleanup;
if ((error = git_commit_create(
@@ -319,7 +318,7 @@ static int commit_untracked(
stasher,
stasher,
NULL,
- git_buf_cstr(&msg),
+ git_str_cstr(&msg),
u_tree,
0,
NULL)) < 0)
@@ -329,7 +328,7 @@ static int commit_untracked(
cleanup:
git_tree_free(u_tree);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
return error;
}
@@ -437,33 +436,33 @@ cleanup:
return error;
}
-static int prepare_worktree_commit_message(git_buf *out, const char *user_message)
+static int prepare_worktree_commit_message(git_str *out, const char *user_message)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
if (!user_message) {
- git_buf_printf(&buf, "WIP on %s", git_buf_cstr(out));
+ git_str_printf(&buf, "WIP on %s", git_str_cstr(out));
} else {
const char *colon;
- if ((colon = strchr(git_buf_cstr(out), ':')) == NULL)
+ if ((colon = strchr(git_str_cstr(out), ':')) == NULL)
goto cleanup;
- git_buf_puts(&buf, "On ");
- git_buf_put(&buf, git_buf_cstr(out), colon - out->ptr);
- git_buf_printf(&buf, ": %s\n", user_message);
+ git_str_puts(&buf, "On ");
+ git_str_put(&buf, git_str_cstr(out), colon - out->ptr);
+ git_str_printf(&buf, ": %s\n", user_message);
}
- if (git_buf_oom(&buf)) {
+ if (git_str_oom(&buf)) {
error = -1;
goto cleanup;
}
- git_buf_swap(out, &buf);
+ git_str_swap(out, &buf);
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -543,7 +542,7 @@ int git_stash_save(
{
git_index *index = NULL;
git_commit *b_commit = NULL, *i_commit = NULL, *u_commit = NULL;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(out);
@@ -563,24 +562,24 @@ int git_stash_save(
goto cleanup;
if ((error = commit_index(&i_commit, repo, index, stasher,
- git_buf_cstr(&msg), b_commit)) < 0)
+ git_str_cstr(&msg), b_commit)) < 0)
goto cleanup;
if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) &&
(error = commit_untracked(&u_commit, repo, stasher,
- git_buf_cstr(&msg), i_commit, flags)) < 0)
+ git_str_cstr(&msg), i_commit, flags)) < 0)
goto cleanup;
if ((error = prepare_worktree_commit_message(&msg, message)) < 0)
goto cleanup;
- if ((error = commit_worktree(out, repo, stasher, git_buf_cstr(&msg),
+ if ((error = commit_worktree(out, repo, stasher, git_str_cstr(&msg),
i_commit, b_commit, u_commit)) < 0)
goto cleanup;
- git_buf_rtrim(&msg);
+ git_str_rtrim(&msg);
- if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0)
+ if ((error = update_reflog(out, repo, git_str_cstr(&msg))) < 0)
goto cleanup;
if ((error = reset_index_and_workdir(repo, (flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit,
@@ -589,7 +588,7 @@ int git_stash_save(
cleanup:
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
git_commit_free(i_commit);
git_commit_free(b_commit);
git_commit_free(u_commit);
diff --git a/src/buffer.c b/src/str.c
index fe087ea11..7b50800c1 100644
--- a/src/buffer.c
+++ b/src/str.c
@@ -4,42 +4,42 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "buffer.h"
+
+#include "str.h"
#include "posix.h"
-#include "git2/buffer.h"
#include <ctype.h>
-/* Used as default value for git_buf->ptr so that people can always
- * assume ptr is non-NULL and zero terminated even for new git_bufs.
+/* Used as default value for git_str->ptr so that people can always
+ * assume ptr is non-NULL and zero terminated even for new git_strs.
*/
-char git_buf__initbuf[1];
+char git_str__initstr[1];
-char git_buf__oom[1];
+char git_str__oom[1];
#define ENSURE_SIZE(b, d) \
- if ((b)->ptr == git_buf__oom || \
- ((d) > (b)->asize && git_buf_grow((b), (d)) < 0))\
+ if ((b)->ptr == git_str__oom || \
+ ((d) > (b)->asize && git_str_grow((b), (d)) < 0))\
return -1;
-int git_buf_init(git_buf *buf, size_t initial_size)
+int git_str_init(git_str *buf, size_t initial_size)
{
buf->asize = 0;
buf->size = 0;
- buf->ptr = git_buf__initbuf;
+ buf->ptr = git_str__initstr;
ENSURE_SIZE(buf, initial_size);
return 0;
}
-int git_buf_try_grow(
- git_buf *buf, size_t target_size, bool mark_oom)
+int git_str_try_grow(
+ git_str *buf, size_t target_size, bool mark_oom)
{
char *new_ptr;
size_t new_size;
- if (buf->ptr == git_buf__oom)
+ if (buf->ptr == git_str__oom)
return -1;
if (buf->asize == 0 && buf->size != 0) {
@@ -74,9 +74,9 @@ int git_buf_try_grow(
if (new_size < buf->size) {
if (mark_oom) {
- if (buf->ptr && buf->ptr != git_buf__initbuf)
+ if (buf->ptr && buf->ptr != git_str__initstr)
git__free(buf->ptr);
- buf->ptr = git_buf__oom;
+ buf->ptr = git_str__oom;
}
git_error_set_oom();
@@ -87,9 +87,9 @@ int git_buf_try_grow(
if (!new_ptr) {
if (mark_oom) {
- if (buf->ptr && (buf->ptr != git_buf__initbuf))
+ if (buf->ptr && (buf->ptr != git_str__initstr))
git__free(buf->ptr);
- buf->ptr = git_buf__oom;
+ buf->ptr = git_str__oom;
}
return -1;
}
@@ -105,59 +105,46 @@ int git_buf_try_grow(
return 0;
}
-int git_buf_grow(git_buf *buffer, size_t target_size)
+int git_str_grow(git_str *buffer, size_t target_size)
{
- return git_buf_try_grow(buffer, target_size, true);
+ return git_str_try_grow(buffer, target_size, true);
}
-int git_buf_grow_by(git_buf *buffer, size_t additional_size)
+int git_str_grow_by(git_str *buffer, size_t additional_size)
{
size_t newsize;
if (GIT_ADD_SIZET_OVERFLOW(&newsize, buffer->size, additional_size)) {
- buffer->ptr = git_buf__oom;
+ buffer->ptr = git_str__oom;
return -1;
}
- return git_buf_try_grow(buffer, newsize, true);
+ return git_str_try_grow(buffer, newsize, true);
}
-void git_buf_dispose(git_buf *buf)
+void git_str_dispose(git_str *buf)
{
if (!buf) return;
- if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_buf__oom)
+ if (buf->asize > 0 && buf->ptr != NULL && buf->ptr != git_str__oom)
git__free(buf->ptr);
- git_buf_init(buf, 0);
+ git_str_init(buf, 0);
}
#ifndef GIT_DEPRECATE_HARD
-void git_buf_free(git_buf *buf)
+void git_str_free(git_str *buf)
{
- git_buf_dispose(buf);
+ git_str_dispose(buf);
}
#endif
-int git_buf_sanitize(git_buf *buf)
-{
- if (buf->ptr == NULL) {
- GIT_ASSERT_ARG(buf->size == 0 && buf->asize == 0);
-
- buf->ptr = git_buf__initbuf;
- } else if (buf->asize > buf->size) {
- buf->ptr[buf->size] = '\0';
- }
-
- return 0;
-}
-
-void git_buf_clear(git_buf *buf)
+void git_str_clear(git_str *buf)
{
buf->size = 0;
if (!buf->ptr) {
- buf->ptr = git_buf__initbuf;
+ buf->ptr = git_str__initstr;
buf->asize = 0;
}
@@ -165,12 +152,12 @@ void git_buf_clear(git_buf *buf)
buf->ptr[0] = '\0';
}
-int git_buf_set(git_buf *buf, const void *data, size_t len)
+int git_str_set(git_str *buf, const void *data, size_t len)
{
size_t alloclen;
if (len == 0 || data == NULL) {
- git_buf_clear(buf);
+ git_str_clear(buf);
} else {
if (data != buf->ptr) {
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
@@ -186,12 +173,12 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
return 0;
}
-int git_buf_sets(git_buf *buf, const char *string)
+int git_str_sets(git_str *buf, const char *string)
{
- return git_buf_set(buf, string, string ? strlen(string) : 0);
+ return git_str_set(buf, string, string ? strlen(string) : 0);
}
-int git_buf_putc(git_buf *buf, char c)
+int git_str_putc(git_str *buf, char c)
{
size_t new_size;
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
@@ -201,7 +188,7 @@ int git_buf_putc(git_buf *buf, char c)
return 0;
}
-int git_buf_putcn(git_buf *buf, char c, size_t len)
+int git_str_putcn(git_str *buf, char c, size_t len)
{
size_t new_size;
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
@@ -213,7 +200,7 @@ int git_buf_putcn(git_buf *buf, char c, size_t len)
return 0;
}
-int git_buf_put(git_buf *buf, const char *data, size_t len)
+int git_str_put(git_str *buf, const char *data, size_t len)
{
if (len) {
size_t new_size;
@@ -230,17 +217,17 @@ int git_buf_put(git_buf *buf, const char *data, size_t len)
return 0;
}
-int git_buf_puts(git_buf *buf, const char *string)
+int git_str_puts(git_str *buf, const char *string)
{
GIT_ASSERT_ARG(string);
- return git_buf_put(buf, string, strlen(string));
+ return git_str_put(buf, string, strlen(string));
}
static const char base64_encode[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-int git_buf_encode_base64(git_buf *buf, const char *data, size_t len)
+int git_str_encode_base64(git_str *buf, const char *data, size_t len)
{
size_t extra = len % 3;
uint8_t *write, a, b, c;
@@ -302,7 +289,7 @@ static const int8_t base64_decode[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
-int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len)
+int git_str_decode_base64(git_str *buf, const char *base64, size_t len)
{
size_t i;
int8_t a, b, c, d;
@@ -342,7 +329,7 @@ int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len)
static const char base85_encode[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
-int git_buf_encode_base85(git_buf *buf, const char *data, size_t len)
+int git_str_encode_base85(git_str *buf, const char *data, size_t len)
{
size_t blocks = (len / 4) + !!(len % 4), alloclen;
@@ -401,8 +388,8 @@ static const int8_t base85_decode[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
-int git_buf_decode_base85(
- git_buf *buf,
+int git_str_decode_base85(
+ git_str *buf,
const char *base85,
size_t base85_len,
size_t output_len)
@@ -465,8 +452,8 @@ on_error:
#define HEX_DECODE(c) ((c | 32) % 39 - 9)
-int git_buf_decode_percent(
- git_buf *buf,
+int git_str_decode_percent(
+ git_str *buf,
const char *str,
size_t str_len)
{
@@ -493,7 +480,7 @@ int git_buf_decode_percent(
return 0;
}
-int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
+int git_str_vprintf(git_str *buf, const char *format, va_list ap)
{
size_t expected_size, new_size;
int len;
@@ -516,7 +503,7 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
if (len < 0) {
git__free(buf->ptr);
- buf->ptr = git_buf__oom;
+ buf->ptr = git_str__oom;
return -1;
}
@@ -533,19 +520,19 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
return 0;
}
-int git_buf_printf(git_buf *buf, const char *format, ...)
+int git_str_printf(git_str *buf, const char *format, ...)
{
int r;
va_list ap;
va_start(ap, format);
- r = git_buf_vprintf(buf, format, ap);
+ r = git_str_vprintf(buf, format, ap);
va_end(ap);
return r;
}
-int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
+int git_str_copy_cstr(char *data, size_t datasize, const git_str *buf)
{
size_t copylen;
@@ -567,12 +554,12 @@ int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
return 0;
}
-void git_buf_consume_bytes(git_buf *buf, size_t len)
+void git_str_consume_bytes(git_str *buf, size_t len)
{
- git_buf_consume(buf, buf->ptr + len);
+ git_str_consume(buf, buf->ptr + len);
}
-void git_buf_consume(git_buf *buf, const char *end)
+void git_str_consume(git_str *buf, const char *end)
{
if (end > buf->ptr && end <= buf->ptr + buf->size) {
size_t consumed = end - buf->ptr;
@@ -582,7 +569,7 @@ void git_buf_consume(git_buf *buf, const char *end)
}
}
-void git_buf_truncate(git_buf *buf, size_t len)
+void git_str_truncate(git_str *buf, size_t len)
{
if (len >= buf->size)
return;
@@ -592,49 +579,49 @@ void git_buf_truncate(git_buf *buf, size_t len)
buf->ptr[buf->size] = '\0';
}
-void git_buf_shorten(git_buf *buf, size_t amount)
+void git_str_shorten(git_str *buf, size_t amount)
{
if (buf->size > amount)
- git_buf_truncate(buf, buf->size - amount);
+ git_str_truncate(buf, buf->size - amount);
else
- git_buf_clear(buf);
+ git_str_clear(buf);
}
-void git_buf_truncate_at_char(git_buf *buf, char separator)
+void git_str_truncate_at_char(git_str *buf, char separator)
{
- ssize_t idx = git_buf_find(buf, separator);
+ ssize_t idx = git_str_find(buf, separator);
if (idx >= 0)
- git_buf_truncate(buf, (size_t)idx);
+ git_str_truncate(buf, (size_t)idx);
}
-void git_buf_rtruncate_at_char(git_buf *buf, char separator)
+void git_str_rtruncate_at_char(git_str *buf, char separator)
{
- ssize_t idx = git_buf_rfind_next(buf, separator);
- git_buf_truncate(buf, idx < 0 ? 0 : (size_t)idx);
+ ssize_t idx = git_str_rfind_next(buf, separator);
+ git_str_truncate(buf, idx < 0 ? 0 : (size_t)idx);
}
-void git_buf_swap(git_buf *buf_a, git_buf *buf_b)
+void git_str_swap(git_str *str_a, git_str *str_b)
{
- git_buf t = *buf_a;
- *buf_a = *buf_b;
- *buf_b = t;
+ git_str t = *str_a;
+ *str_a = *str_b;
+ *str_b = t;
}
-char *git_buf_detach(git_buf *buf)
+char *git_str_detach(git_str *buf)
{
char *data = buf->ptr;
- if (buf->asize == 0 || buf->ptr == git_buf__oom)
+ if (buf->asize == 0 || buf->ptr == git_str__oom)
return NULL;
- git_buf_init(buf, 0);
+ git_str_init(buf, 0);
return data;
}
-int git_buf_attach(git_buf *buf, char *ptr, size_t asize)
+int git_str_attach(git_str *buf, char *ptr, size_t asize)
{
- git_buf_dispose(buf);
+ git_str_dispose(buf);
if (ptr) {
buf->ptr = ptr;
@@ -649,13 +636,13 @@ int git_buf_attach(git_buf *buf, char *ptr, size_t asize)
return 0;
}
-void git_buf_attach_notowned(git_buf *buf, const char *ptr, size_t size)
+void git_str_attach_notowned(git_str *buf, const char *ptr, size_t size)
{
- if (git_buf_is_allocated(buf))
- git_buf_dispose(buf);
+ if (git_str_is_allocated(buf))
+ git_str_dispose(buf);
if (!size) {
- git_buf_init(buf, 0);
+ git_str_init(buf, 0);
} else {
buf->ptr = (char *)ptr;
buf->asize = 0;
@@ -663,7 +650,7 @@ void git_buf_attach_notowned(git_buf *buf, const char *ptr, size_t size)
}
}
-int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
+int git_str_join_n(git_str *buf, char separator, int nbuf, ...)
{
va_list ap;
int i;
@@ -698,7 +685,7 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
return 0;
GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
- if (git_buf_grow_by(buf, total_size) < 0)
+ if (git_str_grow_by(buf, total_size) < 0)
return -1;
out = buf->ptr + buf->size;
@@ -751,8 +738,8 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
return 0;
}
-int git_buf_join(
- git_buf *buf,
+int git_str_join(
+ git_str *buf,
char separator,
const char *str_a,
const char *str_b)
@@ -800,8 +787,8 @@ int git_buf_join(
return 0;
}
-int git_buf_join3(
- git_buf *buf,
+int git_str_join3(
+ git_str *buf,
char separator,
const char *str_a,
const char *str_b,
@@ -860,7 +847,7 @@ int git_buf_join3(
return 0;
}
-void git_buf_rtrim(git_buf *buf)
+void git_str_rtrim(git_str *buf)
{
while (buf->size > 0) {
if (!git__isspace(buf->ptr[buf->size - 1]))
@@ -873,15 +860,15 @@ void git_buf_rtrim(git_buf *buf)
buf->ptr[buf->size] = '\0';
}
-int git_buf_cmp(const git_buf *a, const git_buf *b)
+int git_str_cmp(const git_str *a, const git_str *b)
{
int result = memcmp(a->ptr, b->ptr, min(a->size, b->size));
return (result != 0) ? result :
(a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
}
-int git_buf_splice(
- git_buf *buf,
+int git_str_splice(
+ git_str *buf,
size_t where,
size_t nb_to_remove,
const char *data,
@@ -915,10 +902,10 @@ int git_buf_splice(
}
/* Quote per http://marc.info/?l=git&m=112927316408690&w=2 */
-int git_buf_quote(git_buf *buf)
+int git_str_quote(git_str *buf)
{
const char whitespace[] = { 'a', 'b', 't', 'n', 'v', 'f', 'r' };
- git_buf quoted = GIT_BUF_INIT;
+ git_str quoted = GIT_STR_INIT;
size_t i = 0;
bool quote = false;
int error = 0;
@@ -938,55 +925,55 @@ int git_buf_quote(git_buf *buf)
if (!quote)
goto done;
- git_buf_putc(&quoted, '"');
- git_buf_put(&quoted, buf->ptr, i);
+ git_str_putc(&quoted, '"');
+ git_str_put(&quoted, buf->ptr, i);
for (; i < buf->size; i++) {
/* whitespace - use the map above, which is ordered by ascii value */
if (buf->ptr[i] >= '\a' && buf->ptr[i] <= '\r') {
- git_buf_putc(&quoted, '\\');
- git_buf_putc(&quoted, whitespace[buf->ptr[i] - '\a']);
+ git_str_putc(&quoted, '\\');
+ git_str_putc(&quoted, whitespace[buf->ptr[i] - '\a']);
}
/* double quote and backslash must be escaped */
else if (buf->ptr[i] == '"' || buf->ptr[i] == '\\') {
- git_buf_putc(&quoted, '\\');
- git_buf_putc(&quoted, buf->ptr[i]);
+ git_str_putc(&quoted, '\\');
+ git_str_putc(&quoted, buf->ptr[i]);
}
/* escape anything unprintable as octal */
else if (buf->ptr[i] != ' ' &&
(buf->ptr[i] < '!' || buf->ptr[i] > '~')) {
- git_buf_printf(&quoted, "\\%03o", (unsigned char)buf->ptr[i]);
+ git_str_printf(&quoted, "\\%03o", (unsigned char)buf->ptr[i]);
}
/* yay, printable! */
else {
- git_buf_putc(&quoted, buf->ptr[i]);
+ git_str_putc(&quoted, buf->ptr[i]);
}
}
- git_buf_putc(&quoted, '"');
+ git_str_putc(&quoted, '"');
- if (git_buf_oom(&quoted)) {
+ if (git_str_oom(&quoted)) {
error = -1;
goto done;
}
- git_buf_swap(&quoted, buf);
+ git_str_swap(&quoted, buf);
done:
- git_buf_dispose(&quoted);
+ git_str_dispose(&quoted);
return error;
}
/* Unquote per http://marc.info/?l=git&m=112927316408690&w=2 */
-int git_buf_unquote(git_buf *buf)
+int git_str_unquote(git_str *buf)
{
size_t i, j;
char ch;
- git_buf_rtrim(buf);
+ git_str_rtrim(buf);
if (buf->size < 2 || buf->ptr[0] != '"' || buf->ptr[buf->size-1] != '"')
goto invalid;
@@ -1055,8 +1042,8 @@ invalid:
return -1;
}
-int git_buf_puts_escaped(
- git_buf *buf,
+int git_str_puts_escaped(
+ git_str *buf,
const char *string,
const char *esc_chars,
const char *esc_with)
@@ -1079,7 +1066,7 @@ int git_buf_puts_escaped(
}
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, total, 1);
- if (git_buf_grow_by(buf, alloclen) < 0)
+ if (git_str_grow_by(buf, alloclen) < 0)
return -1;
for (scan = string; *scan; ) {
@@ -1105,12 +1092,12 @@ int git_buf_puts_escaped(
return 0;
}
-void git_buf_unescape(git_buf *buf)
+void git_str_unescape(git_str *buf)
{
buf->size = git__unescape(buf->ptr);
}
-int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src)
+int git_str_crlf_to_lf(git_str *tgt, const git_str *src)
{
const char *scan = src->ptr;
const char *scan_end = src->ptr + src->size;
@@ -1121,11 +1108,11 @@ int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src)
GIT_ASSERT(tgt != src);
if (!next)
- return git_buf_set(tgt, src->ptr, src->size);
+ return git_str_set(tgt, src->ptr, src->size);
/* reduce reallocs while in the loop */
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, src->size, 1);
- if (git_buf_grow(tgt, new_size) < 0)
+ if (git_str_grow(tgt, new_size) < 0)
return -1;
out = tgt->ptr;
@@ -1157,7 +1144,7 @@ int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src)
return 0;
}
-int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
+int git_str_lf_to_crlf(git_str *tgt, const git_str *src)
{
const char *start = src->ptr;
const char *end = start + src->size;
@@ -1168,12 +1155,12 @@ int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
GIT_ASSERT(tgt != src);
if (!next)
- return git_buf_set(tgt, src->ptr, src->size);
+ return git_str_set(tgt, src->ptr, src->size);
/* attempt to reduce reallocs while in the loop */
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4);
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
- if (git_buf_grow(tgt, alloclen) < 0)
+ if (git_str_grow(tgt, alloclen) < 0)
return -1;
tgt->size = 0;
@@ -1185,7 +1172,7 @@ int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
copylen--;
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, copylen, 3);
- if (git_buf_grow_by(tgt, alloclen) < 0)
+ if (git_str_grow_by(tgt, alloclen) < 0)
return -1;
if (copylen) {
@@ -1198,21 +1185,21 @@ int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
}
tgt->ptr[tgt->size] = '\0';
- return git_buf_put(tgt, scan, end - scan);
+ return git_str_put(tgt, scan, end - scan);
}
-int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count)
+int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count)
{
size_t i;
const char *str, *pfx;
- git_buf_clear(buf);
+ git_str_clear(buf);
if (!strings || !count)
return 0;
/* initialize common prefix to first string */
- if (git_buf_sets(buf, strings[0]) < 0)
+ if (git_str_sets(buf, strings[0]) < 0)
return -1;
/* go through the rest of the strings, truncating to shared prefix */
@@ -1223,7 +1210,7 @@ int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count
str++, pfx++)
/* scanning */;
- git_buf_truncate(buf, pfx - buf->ptr);
+ git_str_truncate(buf, pfx - buf->ptr);
if (!buf->size)
break;
@@ -1232,15 +1219,15 @@ int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count
return 0;
}
-int git_buf_is_binary(const git_buf *buf)
+int git_str_is_binary(const git_str *buf)
{
const char *scan = buf->ptr, *end = buf->ptr + buf->size;
- git_buf_bom_t bom;
+ git_str_bom_t bom;
int printable = 0, nonprintable = 0;
- scan += git_buf_detect_bom(&bom, buf);
+ scan += git_str_detect_bom(&bom, buf);
- if (bom > GIT_BUF_BOM_UTF8)
+ if (bom > GIT_STR_BOM_UTF8)
return 1;
while (scan < end) {
@@ -1260,17 +1247,17 @@ int git_buf_is_binary(const git_buf *buf)
return ((printable >> 7) < nonprintable);
}
-int git_buf_contains_nul(const git_buf *buf)
+int git_str_contains_nul(const git_str *buf)
{
return (memchr(buf->ptr, '\0', buf->size) != NULL);
}
-int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
+int git_str_detect_bom(git_str_bom_t *bom, const git_str *buf)
{
const char *ptr;
size_t len;
- *bom = GIT_BUF_BOM_NONE;
+ *bom = GIT_STR_BOM_NONE;
/* need at least 2 bytes to look for any BOM */
if (buf->size < 2)
return 0;
@@ -1281,19 +1268,19 @@ int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
switch (*ptr++) {
case 0:
if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
- *bom = GIT_BUF_BOM_UTF32_BE;
+ *bom = GIT_STR_BOM_UTF32_BE;
return 4;
}
break;
case '\xEF':
if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
- *bom = GIT_BUF_BOM_UTF8;
+ *bom = GIT_STR_BOM_UTF8;
return 3;
}
break;
case '\xFE':
if (*ptr == '\xFF') {
- *bom = GIT_BUF_BOM_UTF16_BE;
+ *bom = GIT_STR_BOM_UTF16_BE;
return 2;
}
break;
@@ -1301,10 +1288,10 @@ int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
if (*ptr != '\xFE')
break;
if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
- *bom = GIT_BUF_BOM_UTF32_LE;
+ *bom = GIT_STR_BOM_UTF32_LE;
return 4;
} else {
- *bom = GIT_BUF_BOM_UTF16_LE;
+ *bom = GIT_STR_BOM_UTF16_LE;
return 2;
}
break;
@@ -1315,8 +1302,8 @@ int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
return 0;
}
-bool git_buf_gather_text_stats(
- git_buf_text_stats *stats, const git_buf *buf, bool skip_bom)
+bool git_str_gather_text_stats(
+ git_str_text_stats *stats, const git_str *buf, bool skip_bom)
{
const char *scan = buf->ptr, *end = buf->ptr + buf->size;
int skip;
@@ -1324,7 +1311,7 @@ bool git_buf_gather_text_stats(
memset(stats, 0, sizeof(*stats));
/* BOM detection */
- skip = git_buf_detect_bom(&stats->bom, buf);
+ skip = git_str_detect_bom(&stats->bom, buf);
if (skip_bom)
scan += skip;
diff --git a/src/str.h b/src/str.h
new file mode 100644
index 000000000..af7acc21f
--- /dev/null
+++ b/src/str.h
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_str_h__
+#define INCLUDE_str_h__
+
+#include "common.h"
+
+struct git_str {
+ char *ptr;
+ size_t asize;
+ size_t size;
+};
+
+typedef enum {
+ GIT_STR_BOM_NONE = 0,
+ GIT_STR_BOM_UTF8 = 1,
+ GIT_STR_BOM_UTF16_LE = 2,
+ GIT_STR_BOM_UTF16_BE = 3,
+ GIT_STR_BOM_UTF32_LE = 4,
+ GIT_STR_BOM_UTF32_BE = 5
+} git_str_bom_t;
+
+typedef struct {
+ git_str_bom_t bom; /* BOM found at head of text */
+ unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
+ unsigned int printable, nonprintable; /* These are just approximations! */
+} git_str_text_stats;
+
+extern char git_str__initstr[];
+extern char git_str__oom[];
+
+/* Use to initialize string buffer structure when git_str is on stack */
+#define GIT_STR_INIT { git_str__initstr, 0, 0 }
+
+/**
+ * Static initializer for git_str from static string buffer
+ */
+#define GIT_STR_INIT_CONST(str, len) { (char *)(str), 0, (size_t)(len) }
+
+GIT_INLINE(bool) git_str_is_allocated(const git_str *str)
+{
+ return (str->ptr != NULL && str->asize > 0);
+}
+
+/**
+ * Initialize a git_str structure.
+ *
+ * For the cases where GIT_STR_INIT cannot be used to do static
+ * initialization.
+ */
+extern int git_str_init(git_str *str, size_t initial_size);
+
+extern void git_str_dispose(git_str *str);
+
+/**
+ * Resize the string buffer allocation to make more space.
+ *
+ * This will attempt to grow the string buffer to accommodate the target
+ * size. The bstring buffer's `ptr` will be replaced with a newly
+ * allocated block of data. Be careful so that memory allocated by the
+ * caller is not lost. As a special variant, if you pass `target_size` as
+ * 0 and the memory is not allocated by libgit2, this will allocate a new
+ * buffer of size `size` and copy the external data into it.
+ *
+ * Currently, this will never shrink a buffer, only expand it.
+ *
+ * If the allocation fails, this will return an error and the buffer will be
+ * marked as invalid for future operations, invaliding the contents.
+ *
+ * @param str The buffer to be resized; may or may not be allocated yet
+ * @param target_size The desired available size
+ * @return 0 on success, -1 on allocation failure
+ */
+int git_str_grow(git_str *str, size_t target_size);
+
+/**
+ * Resize the buffer allocation to make more space.
+ *
+ * This will attempt to grow the string buffer to accommodate the
+ * additional size. It is similar to `git_str_grow`, but performs the
+ * new size calculation, checking for overflow.
+ *
+ * Like `git_str_grow`, if this is a user-supplied string buffer,
+ * this will allocate a new string uffer.
+ */
+extern int git_str_grow_by(git_str *str, size_t additional_size);
+
+/**
+ * Attempt to grow the buffer to hold at least `target_size` bytes.
+ *
+ * If the allocation fails, this will return an error. If `mark_oom` is
+ * true, this will mark the string buffer as invalid for future
+ * operations; if false, existing string buffer content will be preserved,
+ * but calling code must handle that string buffer was not expanded. If
+ * `preserve_external` is true, then any existing data pointed to be
+ * `ptr` even if `asize` is zero will be copied into the newly allocated
+ * string buffer.
+ */
+extern int git_str_try_grow(
+ git_str *str, size_t target_size, bool mark_oom);
+
+extern void git_str_swap(git_str *str_a, git_str *str_b);
+extern char *git_str_detach(git_str *str);
+extern int git_str_attach(git_str *str, char *ptr, size_t asize);
+
+/* Populates a `git_str` where the contents are not "owned" by the string
+ * buffer, and calls to `git_str_dispose` will not free the given str.
+ */
+extern void git_str_attach_notowned(
+ git_str *str, const char *ptr, size_t size);
+
+/**
+ * Test if there have been any reallocation failures with this git_str.
+ *
+ * Any function that writes to a git_str can fail due to memory allocation
+ * issues. If one fails, the git_str will be marked with an OOM error and
+ * further calls to modify the string buffer will fail. Check
+ * git_str_oom() at the end of your sequence and it will be true if you
+ * ran out of memory at any point with that string buffer.
+ *
+ * @return false if no error, true if allocation error
+ */
+GIT_INLINE(bool) git_str_oom(const git_str *str)
+{
+ return (str->ptr == git_str__oom);
+}
+
+/*
+ * Functions below that return int value error codes will return 0 on
+ * success or -1 on failure (which generally means an allocation failed).
+ * Using a git_str where the allocation has failed with result in -1 from
+ * all further calls using that string buffer. As a result, you can
+ * ignore the return code of these functions and call them in a series
+ * then just call git_str_oom at the end.
+ */
+
+int git_str_set(git_str *str, const void *data, size_t datalen);
+
+int git_str_sets(git_str *str, const char *string);
+int git_str_putc(git_str *str, char c);
+int git_str_putcn(git_str *str, char c, size_t len);
+int git_str_put(git_str *str, const char *data, size_t len);
+int git_str_puts(git_str *str, const char *string);
+int git_str_printf(git_str *str, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
+int git_str_vprintf(git_str *str, const char *format, va_list ap);
+void git_str_clear(git_str *str);
+void git_str_consume_bytes(git_str *str, size_t len);
+void git_str_consume(git_str *str, const char *end);
+void git_str_truncate(git_str *str, size_t len);
+void git_str_shorten(git_str *str, size_t amount);
+void git_str_truncate_at_char(git_str *path, char separator);
+void git_str_rtruncate_at_char(git_str *path, char separator);
+
+/** General join with separator */
+int git_str_join_n(git_str *str, char separator, int len, ...);
+/** Fast join of two strings - first may legally point into `str` data */
+int git_str_join(git_str *str, char separator, const char *str_a, const char *str_b);
+/** Fast join of three strings - cannot reference `str` data */
+int git_str_join3(git_str *str, char separator, const char *str_a, const char *str_b, const char *str_c);
+
+/**
+ * Join two strings as paths, inserting a slash between as needed.
+ * @return 0 on success, -1 on failure
+ */
+GIT_INLINE(int) git_str_joinpath(git_str *str, const char *a, const char *b)
+{
+ return git_str_join(str, '/', a, b);
+}
+
+GIT_INLINE(const char *) git_str_cstr(const git_str *str)
+{
+ return str->ptr;
+}
+
+GIT_INLINE(size_t) git_str_len(const git_str *str)
+{
+ return str->size;
+}
+
+int git_str_copy_cstr(char *data, size_t datasize, const git_str *str);
+
+#define git_str_PUTS(str, cstr) git_str_put(str, cstr, sizeof(cstr) - 1)
+
+GIT_INLINE(ssize_t) git_str_rfind_next(const git_str *str, char ch)
+{
+ ssize_t idx = (ssize_t)str->size - 1;
+ while (idx >= 0 && str->ptr[idx] == ch) idx--;
+ while (idx >= 0 && str->ptr[idx] != ch) idx--;
+ return idx;
+}
+
+GIT_INLINE(ssize_t) git_str_rfind(const git_str *str, char ch)
+{
+ ssize_t idx = (ssize_t)str->size - 1;
+ while (idx >= 0 && str->ptr[idx] != ch) idx--;
+ return idx;
+}
+
+GIT_INLINE(ssize_t) git_str_find(const git_str *str, char ch)
+{
+ void *found = memchr(str->ptr, ch, str->size);
+ return found ? (ssize_t)((const char *)found - str->ptr) : -1;
+}
+
+/* Remove whitespace from the end of the string buffer */
+void git_str_rtrim(git_str *str);
+
+int git_str_cmp(const git_str *a, const git_str *b);
+
+/* Quote and unquote a string buffer as specified in
+ * http://marc.info/?l=git&m=112927316408690&w=2
+ */
+int git_str_quote(git_str *str);
+int git_str_unquote(git_str *str);
+
+/* Write data as base64 encoded in string buffer */
+int git_str_encode_base64(git_str *str, const char *data, size_t len);
+/* Decode the given bas64 and write the result to the string buffer */
+int git_str_decode_base64(git_str *str, const char *base64, size_t len);
+
+/* Write data as "base85" encoded in string buffer */
+int git_str_encode_base85(git_str *str, const char *data, size_t len);
+/* Decode the given "base85" and write the result to the string buffer */
+int git_str_decode_base85(git_str *str, const char *base64, size_t len, size_t output_len);
+
+/*
+ * Decode the given percent-encoded string and write the result to the
+ * string buffer.
+ */
+int git_str_decode_percent(git_str *str, const char *encoded, size_t len);
+
+/*
+ * Insert, remove or replace a portion of the string buffer.
+ *
+ * @param str The string buffer to work with
+ *
+ * @param where The location in the string buffer where the transformation
+ * should be applied.
+ *
+ * @param nb_to_remove The number of chars to be removed. 0 to not
+ * remove any character in the string buffer.
+ *
+ * @param data A pointer to the data which should be inserted.
+ *
+ * @param nb_to_insert The number of chars to be inserted. 0 to not
+ * insert any character from the string buffer.
+ *
+ * @return 0 or an error code.
+ */
+int git_str_splice(
+ git_str *str,
+ size_t where,
+ size_t nb_to_remove,
+ const char *data,
+ size_t nb_to_insert);
+
+/**
+ * Append string to string buffer, prefixing each character from
+ * `esc_chars` with `esc_with` string.
+ *
+ * @param str String buffer to append data to
+ * @param string String to escape and append
+ * @param esc_chars Characters to be escaped
+ * @param esc_with String to insert in from of each found character
+ * @return 0 on success, <0 on failure (probably allocation problem)
+ */
+extern int git_str_puts_escaped(
+ git_str *str,
+ const char *string,
+ const char *esc_chars,
+ const char *esc_with);
+
+/**
+ * Append string escaping characters that are regex special
+ */
+GIT_INLINE(int) git_str_puts_escape_regex(git_str *str, const char *string)
+{
+ return git_str_puts_escaped(str, string, "^.[]$()|*+?{}\\", "\\");
+}
+
+/**
+ * Unescape all characters in a string buffer in place
+ *
+ * I.e. remove backslashes
+ */
+extern void git_str_unescape(git_str *str);
+
+/**
+ * Replace all \r\n with \n.
+ *
+ * @return 0 on success, -1 on memory error
+ */
+extern int git_str_crlf_to_lf(git_str *tgt, const git_str *src);
+
+/**
+ * Replace all \n with \r\n. Does not modify existing \r\n.
+ *
+ * @return 0 on success, -1 on memory error
+ */
+extern int git_str_lf_to_crlf(git_str *tgt, const git_str *src);
+
+/**
+ * Fill string buffer with the common prefix of a array of strings
+ *
+ * String buffer will be set to empty if there is no common prefix
+ */
+extern int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count);
+
+/**
+ * Check if a string buffer begins with a UTF BOM
+ *
+ * @param bom Set to the type of BOM detected or GIT_BOM_NONE
+ * @param str String buffer in which to check the first bytes for a BOM
+ * @return Number of bytes of BOM data (or 0 if no BOM found)
+ */
+extern int git_str_detect_bom(git_str_bom_t *bom, const git_str *str);
+
+/**
+ * Gather stats for a piece of text
+ *
+ * Fill the `stats` structure with counts of unreadable characters, carriage
+ * returns, etc, so it can be used in heuristics. This automatically skips
+ * a trailing EOF (\032 character). Also it will look for a BOM at the
+ * start of the text and can be told to skip that as well.
+ *
+ * @param stats Structure to be filled in
+ * @param str Text to process
+ * @param skip_bom Exclude leading BOM from stats if true
+ * @return Does the string buffer heuristically look like binary data
+ */
+extern bool git_str_gather_text_stats(
+ git_str_text_stats *stats, const git_str *str, bool skip_bom);
+
+/**
+* Check quickly if string buffer looks like it contains binary data
+*
+* @param str string buffer to check
+* @return 1 if string buffer looks like non-text data
+*/
+int git_str_is_binary(const git_str *str);
+
+/**
+* Check quickly if buffer contains a NUL byte
+*
+* @param str string buffer to check
+* @return 1 if string buffer contains a NUL byte
+*/
+int git_str_contains_nul(const git_str *str);
+
+#endif
diff --git a/src/submodule.c b/src/submodule.c
index 7cbb9fa3a..b0f7294be 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -7,11 +7,8 @@
#include "submodule.h"
-#include "git2/config.h"
-#include "git2/sys/config.h"
-#include "git2/types.h"
-#include "git2/index.h"
-#include "buffer.h"
+#include "buf.h"
+#include "branch.h"
#include "vector.h"
#include "posix.h"
#include "config_backend.h"
@@ -20,10 +17,16 @@
#include "tree.h"
#include "iterator.h"
#include "path.h"
+#include "str.h"
#include "index.h"
#include "worktree.h"
#include "clone.h"
+#include "git2/config.h"
+#include "git2/sys/config.h"
+#include "git2/types.h"
+#include "git2/index.h"
+
#define GIT_MODULES_FILE ".gitmodules"
static git_configmap _sm_update_map[] = {
@@ -63,8 +66,8 @@ enum {
static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name);
static git_config_backend *open_gitmodules(git_repository *repo, int gitmod);
static int gitmodules_snapshot(git_config **snap, git_repository *repo);
-static int get_url_base(git_buf *url, git_repository *repo);
-static int lookup_head_remote_key(git_buf *remote_key, git_repository *repo);
+static int get_url_base(git_str *url, git_repository *repo);
+static int lookup_head_remote_key(git_str *remote_key, git_repository *repo);
static int lookup_default_remote(git_remote **remote, git_repository *repo);
static int submodule_load_each(const git_config_entry *entry, void *payload);
static int submodule_read_config(git_submodule *sm, git_config *cfg);
@@ -79,11 +82,11 @@ static int submodule_cmp(const void *a, const void *b)
return strcmp(((git_submodule *)a)->name, ((git_submodule *)b)->name);
}
-static int submodule_config_key_trunc_puts(git_buf *key, const char *suffix)
+static int submodule_config_key_trunc_puts(git_str *key, const char *suffix)
{
- ssize_t idx = git_buf_rfind(key, '.');
- git_buf_truncate(key, (size_t)(idx + 1));
- return git_buf_puts(key, suffix);
+ ssize_t idx = git_str_rfind(key, '.');
+ git_str_truncate(key, (size_t)(idx + 1));
+ return git_str_puts(key, suffix);
}
/*
@@ -128,7 +131,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
{
int error = 0;
git_index *index;
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
*occupied = false;
if ((error = git_repository_index__weakptr(&index, repo)) < 0)
@@ -143,7 +146,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
goto out;
}
- if ((error = git_buf_sets(&dir, path)) < 0)
+ if ((error = git_str_sets(&dir, path)) < 0)
goto out;
if ((error = git_path_to_dir(&dir)) < 0)
@@ -161,7 +164,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
error = 0;
out:
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
return error;
}
@@ -195,7 +198,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
const char *key = "submodule\\..*\\.path";
git_config_iterator *iter = NULL;
git_config_entry *entry;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_strmap *names;
int isvalid, error;
@@ -219,8 +222,8 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
goto out;
}
- git_buf_clear(&buf);
- git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
+ git_str_clear(&buf);
+ git_str_put(&buf, fdot + 1, ldot - fdot - 1);
isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
if (isvalid < 0) {
error = isvalid;
@@ -229,7 +232,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
if (!isvalid)
continue;
- if ((error = git_strmap_set(names, git__strdup(entry->value), git_buf_detach(&buf))) < 0) {
+ if ((error = git_strmap_set(names, git__strdup(entry->value), git_str_detach(&buf))) < 0) {
git_error_set(GIT_ERROR_NOMEMORY, "error inserting submodule into hash table");
error = -1;
goto out;
@@ -243,7 +246,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
out:
free_submodule_names(names);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_iterator_free(iter);
return error;
}
@@ -329,10 +332,10 @@ int git_submodule__lookup_with_cache(
if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) {
git_config_backend *mods;
const char *pattern = "submodule\\..*\\.path";
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
fbp_data data = { NULL, NULL };
- git_buf_puts(&path, name);
+ git_str_puts(&path, name);
while (path.ptr[path.size-1] == '/') {
path.ptr[--path.size] = '\0';
}
@@ -347,14 +350,14 @@ int git_submodule__lookup_with_cache(
if (error < 0) {
git_submodule_free(sm);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
if (data.name) {
git__free(sm->name);
sm->name = data.name;
- sm->path = git_buf_detach(&path);
+ sm->path = git_str_detach(&path);
/* Try to load again with the right name */
if ((error = git_submodule_reload(sm, false)) < 0) {
@@ -363,7 +366,7 @@ int git_submodule__lookup_with_cache(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
if ((error = git_submodule_location(&location, sm)) < 0) {
@@ -378,8 +381,8 @@ int git_submodule__lookup_with_cache(
/* If it's not configured, we still check if there's a repo at the path */
if (git_repository_workdir(repo)) {
- git_buf path = GIT_BUF_INIT;
- if (git_buf_join3(&path, '/',
+ git_str path = GIT_STR_INIT;
+ if (git_str_join3(&path, '/',
git_repository_workdir(repo),
name, DOT_GIT) < 0 ||
git_path_validate_workdir_buf(NULL, &path) < 0)
@@ -388,7 +391,7 @@ int git_submodule__lookup_with_cache(
if (git_path_exists(path.ptr))
error = GIT_EEXISTS;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
submodule_set_lookup_error(error, name);
@@ -405,7 +408,7 @@ int git_submodule__lookup_with_cache(
int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error, isvalid;
if (flags == 0)
@@ -416,11 +419,11 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
if ((error = git_path_normalize_slashes(&buf, name)) < 0)
return error;
} else {
- git_buf_attach_notowned(&buf, name, strlen(name));
+ git_str_attach_notowned(&buf, name, strlen(name));
}
isvalid = git_path_validate(repo, buf.ptr, 0, flags);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return isvalid;
}
@@ -554,7 +557,7 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
int error = 0;
git_index *idx = NULL;
git_tree *head = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_submodule *sm;
git_config *mods = NULL;
bool has_workdir;
@@ -613,7 +616,7 @@ cleanup:
/* TODO: if we got an error, mark submodule config as invalid? */
git_index_free(idx);
git_tree_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -682,7 +685,7 @@ static int submodule_repo_init(
bool use_gitlink)
{
int error = 0;
- git_buf workdir = GIT_BUF_INIT, repodir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT;
git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *subrepo = NULL;
@@ -701,10 +704,10 @@ static int submodule_repo_init(
* Old style: sub-repo goes directly into repo/<name>/.git/
*/
if (use_gitlink) {
- error = git_repository_item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
+ error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
if (error < 0)
goto cleanup;
- error = git_buf_joinpath(&repodir, repodir.ptr, path);
+ error = git_str_joinpath(&repodir, repodir.ptr, path);
if (error < 0)
goto cleanup;
@@ -718,14 +721,57 @@ static int submodule_repo_init(
error = git_repository_init_ext(&subrepo, workdir.ptr, &initopt);
cleanup:
- git_buf_dispose(&workdir);
- git_buf_dispose(&repodir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&repodir);
*out = subrepo;
return error;
}
+static int git_submodule__resolve_url(
+ git_str *out,
+ git_repository *repo,
+ const char *url)
+{
+ int error = 0;
+ git_str normalized = GIT_STR_INIT;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(url);
+
+ /* We do this in all platforms in case someone on Windows created the .gitmodules */
+ if (strchr(url, '\\')) {
+ if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
+ return error;
+
+ url = normalized.ptr;
+ }
+
+
+ if (git_path_is_relative(url)) {
+ if (!(error = get_url_base(out, repo)))
+ error = git_path_apply_relative(out, url);
+ } else if (strchr(url, ':') != NULL || url[0] == '/') {
+ error = git_str_sets(out, url);
+ } else {
+ git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL");
+ error = -1;
+ }
+
+ git_str_dispose(&normalized);
+ return error;
+}
+
+int git_submodule_resolve_url(
+ git_buf *out,
+ git_repository *repo,
+ const char *url)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_submodule__resolve_url, repo, url);
+}
+
int git_submodule_add_setup(
git_submodule **out,
git_repository *repo,
@@ -736,7 +782,7 @@ int git_submodule_add_setup(
int error = 0;
git_config_backend *mods = NULL;
git_submodule *sm = NULL;
- git_buf name = GIT_BUF_INIT, real_url = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT, real_url = GIT_STR_INIT;
git_repository *subrepo = NULL;
bool path_occupied;
@@ -781,7 +827,7 @@ int git_submodule_add_setup(
return -1;
}
- if ((error = git_buf_printf(&name, "submodule.%s.path", path)) < 0 ||
+ if ((error = git_str_printf(&name, "submodule.%s.path", path)) < 0 ||
(error = git_config_backend_set_string(mods, name.ptr, path)) < 0)
goto cleanup;
@@ -789,7 +835,7 @@ int git_submodule_add_setup(
(error = git_config_backend_set_string(mods, name.ptr, url)) < 0)
goto cleanup;
- git_buf_clear(&name);
+ git_str_clear(&name);
/* init submodule repository and add origin remote as needed */
@@ -804,7 +850,7 @@ int git_submodule_add_setup(
git_path_contains(&name, DOT_GIT))) {
/* resolve the actual URL to use */
- if ((error = git_submodule_resolve_url(&real_url, repo, url)) < 0)
+ if ((error = git_submodule__resolve_url(&real_url, repo, url)) < 0)
goto cleanup;
if ((error = submodule_repo_init(&subrepo, repo, path, real_url.ptr, use_gitlink)) < 0)
@@ -826,8 +872,8 @@ cleanup:
git_config_backend_free(mods);
git_repository_free(subrepo);
- git_buf_dispose(&real_url);
- git_buf_dispose(&name);
+ git_str_dispose(&real_url);
+ git_str_dispose(&name);
return error;
}
@@ -841,13 +887,13 @@ int git_submodule_repo_init(
git_repository *sub_repo = NULL;
const char *configured_url;
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(sm);
/* get the configured remote url of the submodule */
- if ((error = git_buf_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
+ if ((error = git_str_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
(error = git_repository_config_snapshot(&cfg, sm->repo)) < 0 ||
(error = git_config_get_string(&configured_url, cfg, buf.ptr)) < 0 ||
(error = submodule_repo_init(&sub_repo, sm->repo, sm->path, configured_url, use_gitlink)) < 0)
@@ -857,7 +903,7 @@ int git_submodule_repo_init(
done:
git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -881,7 +927,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
{
int error;
git_repository *clone;
- git_buf rel_path = GIT_BUF_INIT;
+ git_str rel_path = GIT_STR_INIT;
git_submodule_update_options sub_opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
@@ -903,7 +949,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
if (error < 0)
goto cleanup;
- error = git_clone__submodule(&clone, git_submodule_url(submodule), git_buf_cstr(&rel_path), &opts);
+ error = git_clone__submodule(&clone, git_submodule_url(submodule), git_str_cstr(&rel_path), &opts);
if (error < 0)
goto cleanup;
@@ -913,7 +959,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
*out = clone;
cleanup:
- git_buf_dispose(&rel_path);
+ git_str_dispose(&rel_path);
return error;
}
@@ -937,7 +983,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
int error;
git_repository *sm_repo = NULL;
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_commit *head;
git_index_entry entry;
struct stat st;
@@ -997,7 +1043,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
cleanup:
git_repository_free(sm_repo);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1034,44 +1080,9 @@ const char *git_submodule_url(git_submodule *submodule)
return submodule->url;
}
-int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url)
-{
- int error = 0;
- git_buf normalized = GIT_BUF_INIT;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(repo);
- GIT_ASSERT_ARG(url);
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- /* We do this in all platforms in case someone on Windows created the .gitmodules */
- if (strchr(url, '\\')) {
- if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
- return error;
-
- url = normalized.ptr;
- }
-
-
- if (git_path_is_relative(url)) {
- if (!(error = get_url_base(out, repo)))
- error = git_path_apply_relative(out, url);
- } else if (strchr(url, ':') != NULL || url[0] == '/') {
- error = git_buf_sets(out, url);
- } else {
- git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL");
- error = -1;
- }
-
- git_buf_dispose(&normalized);
- return error;
-}
-
static int write_var(git_repository *repo, const char *name, const char *var, const char *val)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
git_config_backend *mods;
int error;
@@ -1079,7 +1090,7 @@ static int write_var(git_repository *repo, const char *name, const char *var, co
if (!mods)
return -1;
- if ((error = git_buf_printf(&key, "submodule.%s.%s", name, var)) < 0)
+ if ((error = git_str_printf(&key, "submodule.%s.%s", name, var)) < 0)
goto cleanup;
if (val)
@@ -1087,7 +1098,7 @@ static int write_var(git_repository *repo, const char *name, const char *var, co
else
error = git_config_backend_delete(mods, key.ptr);
- git_buf_dispose(&key);
+ git_str_dispose(&key);
cleanup:
git_config_backend_free(mods);
@@ -1227,7 +1238,7 @@ static int submodule_repo_create(
const char *path)
{
int error = 0;
- git_buf workdir = GIT_BUF_INIT, repodir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT;
git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *subrepo = NULL;
@@ -1249,18 +1260,18 @@ static int submodule_repo_create(
* <repo-dir>/modules/<name>/ with a gitlink in the
* sub-repo workdir directory to that repository.
*/
- error = git_repository_item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
+ error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
if (error < 0)
goto cleanup;
- error = git_buf_joinpath(&repodir, repodir.ptr, path);
+ error = git_str_joinpath(&repodir, repodir.ptr, path);
if (error < 0)
goto cleanup;
error = git_repository_init_ext(&subrepo, repodir.ptr, &initopt);
cleanup:
- git_buf_dispose(&workdir);
- git_buf_dispose(&repodir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&repodir);
*out = subrepo;
@@ -1309,7 +1320,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
git_repository *sub_repo = NULL;
git_remote *remote = NULL;
git_object *target_commit = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT;
@@ -1337,10 +1348,10 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
* info has been copied into .git/config
*/
if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 ||
- (error = git_buf_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0)
+ (error = git_str_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0)
goto done;
- if ((error = git_config_get_string(&submodule_url, config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0) {
/*
* If the error is not "not found" or if it is "not found" and we are not
* initializing the submodule, then return error.
@@ -1362,7 +1373,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
config = NULL;
if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 ||
- (error = git_config_get_string(&submodule_url, config, git_buf_cstr(&buf))) < 0)
+ (error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0)
goto done;
}
@@ -1420,7 +1431,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
}
done:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_free(config);
git_object_free(target_commit);
git_remote_free(remote);
@@ -1433,7 +1444,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
{
int error;
const char *val;
- git_buf key = GIT_BUF_INIT, effective_submodule_url = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, effective_submodule_url = GIT_STR_INIT;
git_config *cfg = NULL;
if (!sm->url) {
@@ -1447,8 +1458,8 @@ int git_submodule_init(git_submodule *sm, int overwrite)
/* write "submodule.NAME.url" */
- if ((error = git_submodule_resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
- (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ if ((error = git_submodule__resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
+ (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
(error = git_config__update_entry(
cfg, key.ptr, effective_submodule_url.ptr, overwrite != 0, false)) < 0)
goto cleanup;
@@ -1458,7 +1469,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
val = (sm->update == GIT_SUBMODULE_UPDATE_CHECKOUT) ?
NULL : submodule_update_to_str(sm->update);
- if ((error = git_buf_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
+ if ((error = git_str_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
(error = git_config__update_entry(
cfg, key.ptr, val, overwrite != 0, false)) < 0)
goto cleanup;
@@ -1467,15 +1478,15 @@ int git_submodule_init(git_submodule *sm, int overwrite)
cleanup:
git_config_free(cfg);
- git_buf_dispose(&key);
- git_buf_dispose(&effective_submodule_url);
+ git_str_dispose(&key);
+ git_str_dispose(&effective_submodule_url);
return error;
}
int git_submodule_sync(git_submodule *sm)
{
- git_buf key = GIT_BUF_INIT, url = GIT_BUF_INIT, remote_name = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, url = GIT_STR_INIT, remote_name = GIT_STR_INIT;
git_repository *smrepo = NULL;
git_config *cfg = NULL;
int error = 0;
@@ -1487,8 +1498,8 @@ int git_submodule_sync(git_submodule *sm)
/* copy URL over to config only if it already exists */
if ((error = git_repository_config__weakptr(&cfg, sm->repo)) < 0 ||
- (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
- (error = git_submodule_resolve_url(&url, sm->repo, sm->url)) < 0 ||
+ (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ (error = git_submodule__resolve_url(&url, sm->repo, sm->url)) < 0 ||
(error = git_config__update_entry(cfg, key.ptr, url.ptr, true, true)) < 0)
goto out;
@@ -1501,9 +1512,9 @@ int git_submodule_sync(git_submodule *sm)
goto out;
if (lookup_head_remote_key(&remote_name, smrepo) == 0) {
- if ((error = git_buf_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0)
+ if ((error = git_str_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0)
goto out;
- } else if ((error = git_buf_sets(&key, "remote.origin.url")) < 0) {
+ } else if ((error = git_str_sets(&key, "remote.origin.url")) < 0) {
goto out;
}
@@ -1512,9 +1523,9 @@ int git_submodule_sync(git_submodule *sm)
out:
git_repository_free(smrepo);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&key);
- git_buf_dispose(&url);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&key);
+ git_str_dispose(&url);
return error;
}
@@ -1522,7 +1533,7 @@ static int git_submodule__open(
git_repository **subrepo, git_submodule *sm, bool bare)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned int flags = GIT_REPOSITORY_OPEN_NO_SEARCH;
const char *wd;
@@ -1535,7 +1546,7 @@ static int git_submodule__open(
wd = git_repository_workdir(sm->repo);
- if (git_buf_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
+ if (git_str_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
return -1;
sm->flags = sm->flags &
@@ -1561,13 +1572,13 @@ static int git_submodule__open(
sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED |
GIT_SUBMODULE_STATUS_IN_WD;
} else {
- git_buf_rtruncate_at_char(&path, '/'); /* remove "/.git" */
+ git_str_rtruncate_at_char(&path, '/'); /* remove "/.git" */
if (git_path_isdir(path.ptr))
sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1921,13 +1932,13 @@ static int submodule_parse_recurse(git_submodule_recurse_t *out, const char *val
return 0;
}
-static int get_value(const char **out, git_config *cfg, git_buf *buf, const char *name, const char *field)
+static int get_value(const char **out, git_config *cfg, git_str *buf, const char *name, const char *field)
{
int error;
- git_buf_clear(buf);
+ git_str_clear(buf);
- if ((error = git_buf_printf(buf, "submodule.%s.%s", name, field)) < 0 ||
+ if ((error = git_str_printf(buf, "submodule.%s.%s", name, field)) < 0 ||
(error = git_config_get_string(out, cfg, buf->ptr)) < 0)
return error;
@@ -1944,7 +1955,7 @@ static bool looks_like_command_line_option(const char *s)
static int submodule_read_config(git_submodule *sm, git_config *cfg)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
const char *value;
int error, in_config = 0;
@@ -2025,7 +2036,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg)
error = 0;
cleanup:
- git_buf_dispose(&key);
+ git_str_dispose(&key);
return error;
}
@@ -2034,7 +2045,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
lfc_data *data = payload;
const char *namestart, *property;
git_strmap *map = data->map;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
git_submodule *sm;
int error, isvalid;
@@ -2049,7 +2060,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
property++;
- if ((error = git_buf_set(&name, namestart, property - namestart -1)) < 0)
+ if ((error = git_str_set(&name, namestart, property - namestart -1)) < 0)
return error;
isvalid = git_submodule_name_is_valid(data->repo, name.ptr, 0);
@@ -2083,13 +2094,13 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
error = 0;
done:
- git_buf_dispose(&name);
+ git_str_dispose(&name);
return error;
}
static int submodule_load_from_wd_lite(git_submodule *sm)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0)
return -1;
@@ -2100,7 +2111,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
if (git_path_contains(&path, DOT_GIT))
sm->flags |= GIT_SUBMODULE_STATUS_IN_WD;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
@@ -2112,7 +2123,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
static int gitmodules_snapshot(git_config **snap, git_repository *repo)
{
git_config *mods = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if (git_repository_workdir(repo) == NULL)
@@ -2123,7 +2134,7 @@ static int gitmodules_snapshot(git_config **snap, git_repository *repo)
if ((error = git_config_open_ondisk(&mods, path.ptr)) < 0)
goto cleanup;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if ((error = git_config_snapshot(snap, mods)) < 0)
goto cleanup;
@@ -2133,7 +2144,7 @@ static int gitmodules_snapshot(git_config **snap, git_repository *repo)
cleanup:
if (mods)
git_config_free(mods);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -2142,7 +2153,7 @@ static git_config_backend *open_gitmodules(
git_repository *repo,
int okay_to_create)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config_backend *mods = NULL;
if (git_repository_workdir(repo) != NULL) {
@@ -2161,17 +2172,17 @@ static git_config_backend *open_gitmodules(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return mods;
}
/* Lookup name of remote of the local tracking branch HEAD points to */
-static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo)
+static int lookup_head_remote_key(git_str *remote_name, git_repository *repo)
{
int error;
git_reference *head = NULL;
- git_buf upstream_name = GIT_BUF_INIT;
+ git_str upstream_name = GIT_STR_INIT;
/* lookup and dereference HEAD */
if ((error = git_repository_head(&head, repo)) < 0)
@@ -2190,18 +2201,18 @@ static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo)
}
/* lookup remote tracking branch of HEAD */
- if ((error = git_branch_upstream_name(
+ if ((error = git_branch__upstream_name(
&upstream_name,
repo,
git_reference_name(head))) < 0)
goto done;
/* lookup remote of remote tracking branch */
- if ((error = git_branch_remote_name(remote_name, repo, upstream_name.ptr)) < 0)
+ if ((error = git_branch__remote_name(remote_name, repo, upstream_name.ptr)) < 0)
goto done;
done:
- git_buf_dispose(&upstream_name);
+ git_str_dispose(&upstream_name);
git_reference_free(head);
return error;
@@ -2211,13 +2222,13 @@ done:
static int lookup_head_remote(git_remote **remote, git_repository *repo)
{
int error;
- git_buf remote_name = GIT_BUF_INIT;
+ git_str remote_name = GIT_STR_INIT;
/* lookup remote of remote tracking branch name */
if (!(error = lookup_head_remote_key(&remote_name, repo)))
error = git_remote_lookup(remote, repo, remote_name.ptr);
- git_buf_dispose(&remote_name);
+ git_str_dispose(&remote_name);
return error;
}
@@ -2240,14 +2251,14 @@ static int lookup_default_remote(git_remote **remote, git_repository *repo)
return error;
}
-static int get_url_base(git_buf *url, git_repository *repo)
+static int get_url_base(git_str *url, git_repository *repo)
{
int error;
git_worktree *wt = NULL;
git_remote *remote = NULL;
if ((error = lookup_default_remote(&remote, repo)) == 0) {
- error = git_buf_sets(url, git_remote_url(remote));
+ error = git_str_sets(url, git_remote_url(remote));
goto out;
} else if (error != GIT_ENOTFOUND)
goto out;
@@ -2258,9 +2269,9 @@ static int get_url_base(git_buf *url, git_repository *repo)
if (git_repository_is_worktree(repo)) {
if ((error = git_worktree_open_from_repository(&wt, repo)) < 0)
goto out;
- error = git_buf_sets(url, wt->parent_path);
+ error = git_str_sets(url, wt->parent_path);
} else {
- error = git_buf_sets(url, git_repository_workdir(repo));
+ error = git_str_sets(url, git_repository_workdir(repo));
}
out:
diff --git a/src/sysdir.c b/src/sysdir.c
index dcbd48bc3..457d7f8a8 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -8,7 +8,7 @@
#include "sysdir.h"
#include "runtime.h"
-#include "buffer.h"
+#include "str.h"
#include "path.h"
#include <ctype.h>
#if GIT_WIN32
@@ -18,27 +18,27 @@
#include <pwd.h>
#endif
-static int git_sysdir_guess_programdata_dirs(git_buf *out)
+static int git_sysdir_guess_programdata_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_programdata_dirs(out);
#else
- git_buf_clear(out);
+ git_str_clear(out);
return 0;
#endif
}
-static int git_sysdir_guess_system_dirs(git_buf *out)
+static int git_sysdir_guess_system_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_system_dirs(out, L"etc\\");
#else
- return git_buf_sets(out, "/etc");
+ return git_str_sets(out, "/etc");
#endif
}
#ifndef GIT_WIN32
-static int get_passwd_home(git_buf *out, uid_t uid)
+static int get_passwd_home(git_str *out, uid_t uid)
{
struct passwd pwd, *pwdptr;
char *buf = NULL;
@@ -66,7 +66,7 @@ static int get_passwd_home(git_buf *out, uid_t uid)
goto out;
}
- if ((error = git_buf_puts(out, pwdptr->pw_dir)) < 0)
+ if ((error = git_str_puts(out, pwdptr->pw_dir)) < 0)
goto out;
out:
@@ -75,7 +75,7 @@ out:
}
#endif
-static int git_sysdir_guess_global_dirs(git_buf *out)
+static int git_sysdir_guess_global_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_global_dirs(out);
@@ -114,12 +114,12 @@ static int git_sysdir_guess_global_dirs(git_buf *out)
#endif
}
-static int git_sysdir_guess_xdg_dirs(git_buf *out)
+static int git_sysdir_guess_xdg_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_xdg_dirs(out);
#else
- git_buf env = GIT_BUF_INIT;
+ git_str env = GIT_STR_INIT;
int error;
uid_t uid, euid;
@@ -132,13 +132,13 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
*/
if (uid == euid) {
if ((error = git__getenv(&env, "XDG_CONFIG_HOME")) == 0)
- error = git_buf_joinpath(out, env.ptr, "git");
+ error = git_str_joinpath(out, env.ptr, "git");
if (error == GIT_ENOTFOUND && (error = git__getenv(&env, "HOME")) == 0)
- error = git_buf_joinpath(out, env.ptr, ".config/git");
+ error = git_str_joinpath(out, env.ptr, ".config/git");
} else {
if ((error = get_passwd_home(&env, euid)) == 0)
- error = git_buf_joinpath(out, env.ptr, ".config/git");
+ error = git_str_joinpath(out, env.ptr, ".config/git");
}
if (error == GIT_ENOTFOUND) {
@@ -146,31 +146,31 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
error = 0;
}
- git_buf_dispose(&env);
+ git_str_dispose(&env);
return error;
#endif
}
-static int git_sysdir_guess_template_dirs(git_buf *out)
+static int git_sysdir_guess_template_dirs(git_str *out)
{
#ifdef GIT_WIN32
return git_win32__find_system_dirs(out, L"share\\git-core\\templates");
#else
- return git_buf_sets(out, "/usr/share/git-core/templates");
+ return git_str_sets(out, "/usr/share/git-core/templates");
#endif
}
struct git_sysdir__dir {
- git_buf buf;
- int (*guess)(git_buf *out);
+ git_str buf;
+ int (*guess)(git_str *out);
};
static struct git_sysdir__dir git_sysdir__dirs[] = {
- { GIT_BUF_INIT, git_sysdir_guess_system_dirs },
- { GIT_BUF_INIT, git_sysdir_guess_global_dirs },
- { GIT_BUF_INIT, git_sysdir_guess_xdg_dirs },
- { GIT_BUF_INIT, git_sysdir_guess_programdata_dirs },
- { GIT_BUF_INIT, git_sysdir_guess_template_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_system_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_global_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_xdg_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_programdata_dirs },
+ { GIT_STR_INIT, git_sysdir_guess_template_dirs },
};
static void git_sysdir_global_shutdown(void)
@@ -178,7 +178,7 @@ static void git_sysdir_global_shutdown(void)
size_t i;
for (i = 0; i < ARRAY_SIZE(git_sysdir__dirs); ++i)
- git_buf_dispose(&git_sysdir__dirs[i].buf);
+ git_str_dispose(&git_sysdir__dirs[i].buf);
}
int git_sysdir_global_init(void)
@@ -202,7 +202,7 @@ static int git_sysdir_check_selector(git_sysdir_t which)
}
-int git_sysdir_get(const git_buf **out, git_sysdir_t which)
+int git_sysdir_get(const git_str **out, git_sysdir_t which)
{
GIT_ASSERT_ARG(out);
@@ -219,7 +219,7 @@ int git_sysdir_get(const git_buf **out, git_sysdir_t which)
int git_sysdir_set(git_sysdir_t which, const char *search_path)
{
const char *expand_path = NULL;
- git_buf merge = GIT_BUF_INIT;
+ git_str merge = GIT_STR_INIT;
GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which));
@@ -233,48 +233,48 @@ int git_sysdir_set(git_sysdir_t which, const char *search_path)
/* if $PATH is not referenced, then just set the path */
if (!expand_path) {
if (search_path)
- git_buf_sets(&git_sysdir__dirs[which].buf, search_path);
+ git_str_sets(&git_sysdir__dirs[which].buf, search_path);
goto done;
}
/* otherwise set to join(before $PATH, old value, after $PATH) */
if (expand_path > search_path)
- git_buf_set(&merge, search_path, expand_path - search_path);
+ git_str_set(&merge, search_path, expand_path - search_path);
- if (git_buf_len(&git_sysdir__dirs[which].buf))
- git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR,
+ if (git_str_len(&git_sysdir__dirs[which].buf))
+ git_str_join(&merge, GIT_PATH_LIST_SEPARATOR,
merge.ptr, git_sysdir__dirs[which].buf.ptr);
expand_path += strlen(PATH_MAGIC);
if (*expand_path)
- git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path);
+ git_str_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path);
- git_buf_swap(&git_sysdir__dirs[which].buf, &merge);
- git_buf_dispose(&merge);
+ git_str_swap(&git_sysdir__dirs[which].buf, &merge);
+ git_str_dispose(&merge);
done:
- if (git_buf_oom(&git_sysdir__dirs[which].buf))
+ if (git_str_oom(&git_sysdir__dirs[which].buf))
return -1;
return 0;
}
static int git_sysdir_find_in_dirlist(
- git_buf *path,
+ git_str *path,
const char *name,
git_sysdir_t which,
const char *label)
{
size_t len;
const char *scan, *next = NULL;
- const git_buf *syspath;
+ const git_str *syspath;
GIT_ERROR_CHECK_ERROR(git_sysdir_get(&syspath, which));
- if (!syspath || !git_buf_len(syspath))
+ if (!syspath || !git_str_len(syspath))
goto done;
- for (scan = git_buf_cstr(syspath); scan; scan = next) {
+ for (scan = git_str_cstr(syspath); scan; scan = next) {
/* find unescaped separator or end of string */
for (next = scan; *next; ++next) {
if (*next == GIT_PATH_LIST_SEPARATOR &&
@@ -287,9 +287,9 @@ static int git_sysdir_find_in_dirlist(
if (!len)
continue;
- GIT_ERROR_CHECK_ERROR(git_buf_set(path, scan, len));
+ GIT_ERROR_CHECK_ERROR(git_str_set(path, scan, len));
if (name)
- GIT_ERROR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
+ GIT_ERROR_CHECK_ERROR(git_str_joinpath(path, path->ptr, name));
if (git_path_exists(path->ptr))
return 0;
@@ -300,47 +300,47 @@ done:
git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name);
else
git_error_set(GIT_ERROR_OS, "the %s directory doesn't exist", label);
- git_buf_dispose(path);
+ git_str_dispose(path);
return GIT_ENOTFOUND;
}
-int git_sysdir_find_system_file(git_buf *path, const char *filename)
+int git_sysdir_find_system_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_SYSTEM, "system");
}
-int git_sysdir_find_global_file(git_buf *path, const char *filename)
+int git_sysdir_find_global_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_GLOBAL, "global");
}
-int git_sysdir_find_xdg_file(git_buf *path, const char *filename)
+int git_sysdir_find_xdg_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_XDG, "global/xdg");
}
-int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
+int git_sysdir_find_programdata_file(git_str *path, const char *filename)
{
return git_sysdir_find_in_dirlist(
path, filename, GIT_SYSDIR_PROGRAMDATA, "ProgramData");
}
-int git_sysdir_find_template_dir(git_buf *path)
+int git_sysdir_find_template_dir(git_str *path)
{
return git_sysdir_find_in_dirlist(
path, NULL, GIT_SYSDIR_TEMPLATE, "template");
}
-int git_sysdir_expand_global_file(git_buf *path, const char *filename)
+int git_sysdir_expand_global_file(git_str *path, const char *filename)
{
int error;
if ((error = git_sysdir_find_global_file(path, NULL)) == 0) {
if (filename)
- error = git_buf_joinpath(path, path->ptr, filename);
+ error = git_str_joinpath(path, path->ptr, filename);
}
return error;
diff --git a/src/sysdir.h b/src/sysdir.h
index cc5599e38..d12bac9d9 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -10,7 +10,7 @@
#include "common.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
/**
* Find a "global" file (i.e. one in a user's home directory).
@@ -19,7 +19,7 @@
* @param filename name of file to find in the home directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_global_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_global_file(git_str *path, const char *filename);
/**
* Find an "XDG" file (i.e. one in user's XDG config path).
@@ -28,7 +28,7 @@ extern int git_sysdir_find_global_file(git_buf *path, const char *filename);
* @param filename name of file to find in the home directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_xdg_file(git_str *path, const char *filename);
/**
* Find a "system" file (i.e. one shared for all users of the system).
@@ -37,7 +37,7 @@ extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
* @param filename name of file to find in the home directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_system_file(git_str *path, const char *filename);
/**
* Find a "ProgramData" file (i.e. one in %PROGRAMDATA%)
@@ -46,7 +46,7 @@ extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
* @param filename name of file to find in the ProgramData directory
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename);
+extern int git_sysdir_find_programdata_file(git_str *path, const char *filename);
/**
* Find template directory.
@@ -54,7 +54,7 @@ extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
* @param path buffer to write the full path into
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
-extern int git_sysdir_find_template_dir(git_buf *path);
+extern int git_sysdir_find_template_dir(git_str *path);
/**
* Expand the name of a "global" file (i.e. one in a user's home
@@ -66,7 +66,7 @@ extern int git_sysdir_find_template_dir(git_buf *path);
* @param filename name of file in the home directory
* @return 0 on success or -1 on error
*/
-extern int git_sysdir_expand_global_file(git_buf *path, const char *filename);
+extern int git_sysdir_expand_global_file(git_str *path, const char *filename);
typedef enum {
GIT_SYSDIR_SYSTEM = 0,
@@ -87,11 +87,11 @@ extern int git_sysdir_global_init(void);
/**
* Get the search path for global/system/xdg files
*
- * @param out pointer to git_buf containing search path
+ * @param out pointer to git_str containing search path
* @param which which list of paths to return
* @return 0 on success, <0 on failure
*/
-extern int git_sysdir_get(const git_buf **out, git_sysdir_t which);
+extern int git_sysdir_get(const git_str **out, git_sysdir_t which);
/**
* Set search paths for global/system/xdg files
diff --git a/src/tag.c b/src/tag.c
index ee91e5091..7a155147d 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -9,7 +9,6 @@
#include "commit.h"
#include "signature.h"
-#include "message.h"
#include "wildmatch.h"
#include "git2/object.h"
#include "git2/repository.h"
@@ -176,7 +175,7 @@ int git_tag__parse(void *_tag, git_odb_object *odb_obj)
static int retrieve_tag_reference(
git_reference **tag_reference_out,
- git_buf *ref_name_out,
+ git_str *ref_name_out,
git_repository *repo,
const char *tag_name)
{
@@ -185,7 +184,7 @@ static int retrieve_tag_reference(
*tag_reference_out = NULL;
- if (git_buf_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
+ if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
return -1;
error = git_reference_lookup(&tag_ref, repo, ref_name_out->ptr);
@@ -199,11 +198,11 @@ static int retrieve_tag_reference(
static int retrieve_tag_reference_oid(
git_oid *oid,
- git_buf *ref_name_out,
+ git_str *ref_name_out,
git_repository *repo,
const char *tag_name)
{
- if (git_buf_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
+ if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
return -1;
return git_reference_name_to_id(oid, repo, ref_name_out->ptr);
@@ -217,16 +216,16 @@ static int write_tag_annotation(
const git_signature *tagger,
const char *message)
{
- git_buf tag = GIT_BUF_INIT;
+ git_str tag = GIT_STR_INIT;
git_odb *odb;
git_oid__writebuf(&tag, "object ", git_object_id(target));
- git_buf_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target)));
- git_buf_printf(&tag, "tag %s\n", tag_name);
+ git_str_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target)));
+ git_str_printf(&tag, "tag %s\n", tag_name);
git_signature__writebuf(&tag, "tagger ", tagger);
- git_buf_putc(&tag, '\n');
+ git_str_putc(&tag, '\n');
- if (git_buf_puts(&tag, message) < 0)
+ if (git_str_puts(&tag, message) < 0)
goto on_error;
if (git_repository_odb__weakptr(&odb, repo) < 0)
@@ -235,11 +234,11 @@ static int write_tag_annotation(
if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJECT_TAG) < 0)
goto on_error;
- git_buf_dispose(&tag);
+ git_str_dispose(&tag);
return 0;
on_error:
- git_buf_dispose(&tag);
+ git_str_dispose(&tag);
git_error_set(GIT_ERROR_OBJECT, "failed to create tag annotation");
return -1;
}
@@ -255,7 +254,7 @@ static int git_tag_create__internal(
int create_tag_annotation)
{
git_reference *new_ref = NULL;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error;
@@ -276,7 +275,7 @@ static int git_tag_create__internal(
/** Ensure the tag name doesn't conflict with an already existing
* reference unless overwriting has explicitly been requested **/
if (error == 0 && !allow_ref_overwrite) {
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
git_error_set(GIT_ERROR_TAG, "tag already exists");
return GIT_EEXISTS;
}
@@ -291,7 +290,7 @@ static int git_tag_create__internal(
cleanup:
git_reference_free(new_ref);
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
@@ -344,7 +343,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b
git_odb_object *target_obj;
git_reference *new_ref = NULL;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
GIT_ASSERT_ARG(oid);
GIT_ASSERT_ARG(buffer);
@@ -395,7 +394,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b
git_odb_stream_free(stream);
if (error < 0) {
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
@@ -403,7 +402,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b
&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL);
git_reference_free(new_ref);
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
@@ -418,12 +417,12 @@ on_error:
int git_tag_delete(git_repository *repo, const char *tag_name)
{
git_reference *tag_ref;
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error;
error = retrieve_tag_reference(&tag_ref, &ref_name, repo, tag_name);
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
if (error < 0)
return error;
@@ -535,7 +534,7 @@ int git_tag_peel(git_object **tag_target, const git_tag *tag)
int git_tag_name_is_valid(int *valid, const char *name)
{
- git_buf ref_name = GIT_BUF_INIT;
+ git_str ref_name = GIT_STR_INIT;
int error = 0;
GIT_ASSERT(valid);
@@ -547,14 +546,14 @@ int git_tag_name_is_valid(int *valid, const char *name)
if (!name || name[0] == '-')
goto done;
- if ((error = git_buf_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 ||
- (error = git_buf_puts(&ref_name, name)) < 0)
+ if ((error = git_str_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 ||
+ (error = git_str_puts(&ref_name, name)) < 0)
goto done;
error = git_reference_name_is_valid(valid, ref_name.ptr);
done:
- git_buf_dispose(&ref_name);
+ git_str_dispose(&ref_name);
return error;
}
diff --git a/src/threadstate.c b/src/threadstate.c
index e2c08975f..f67cf082b 100644
--- a/src/threadstate.c
+++ b/src/threadstate.c
@@ -36,7 +36,7 @@ static void threadstate_dispose(git_threadstate *threadstate)
if (!threadstate)
return;
- if (threadstate->error_t.message != git_buf__initbuf)
+ if (threadstate->error_t.message != git_str__initstr)
git__free(threadstate->error_t.message);
threadstate->error_t.message = NULL;
}
@@ -76,7 +76,7 @@ git_threadstate *git_threadstate_get(void)
return threadstate;
if ((threadstate = git__calloc(1, sizeof(git_threadstate))) == NULL ||
- git_buf_init(&threadstate->error_buf, 0) < 0)
+ git_str_init(&threadstate->error_buf, 0) < 0)
return NULL;
git_tlsdata_set(tls_key, threadstate);
diff --git a/src/threadstate.h b/src/threadstate.h
index 51810a939..c10f26b59 100644
--- a/src/threadstate.h
+++ b/src/threadstate.h
@@ -12,7 +12,7 @@
typedef struct {
git_error *last_error;
git_error error_t;
- git_buf error_buf;
+ git_str error_buf;
char oid_fmt[GIT_OID_HEXSZ+1];
} git_threadstate;
diff --git a/src/trace.c b/src/trace.c
index efc7b01a2..c316bcacf 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -7,7 +7,7 @@
#include "trace.h"
-#include "buffer.h"
+#include "str.h"
#include "runtime.h"
#include "git2/trace.h"
diff --git a/src/trace.h b/src/trace.h
index a233aa225..eb20ec57b 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -10,7 +10,7 @@
#include "common.h"
#include <git2/trace.h>
-#include "buffer.h"
+#include "str.h"
#ifdef GIT_TRACE
@@ -27,13 +27,13 @@ GIT_INLINE(void) git_trace__write_fmt(
va_list ap)
{
git_trace_cb callback = git_trace__data.callback;
- git_buf message = GIT_BUF_INIT;
+ git_str message = GIT_STR_INIT;
- git_buf_vprintf(&message, fmt, ap);
+ git_str_vprintf(&message, fmt, ap);
- callback(level, git_buf_cstr(&message));
+ callback(level, git_str_cstr(&message));
- git_buf_dispose(&message);
+ git_str_dispose(&message);
}
#define git_trace_level() (git_trace__data.level)
diff --git a/src/transport.c b/src/transport.c
index e128aa6c7..fa1d35fce 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -143,7 +143,7 @@ int git_transport_register(
git_transport_cb cb,
void *param)
{
- git_buf prefix = GIT_BUF_INIT;
+ git_str prefix = GIT_STR_INIT;
transport_definition *d, *definition = NULL;
size_t i;
int error = 0;
@@ -151,7 +151,7 @@ int git_transport_register(
GIT_ASSERT_ARG(scheme);
GIT_ASSERT_ARG(cb);
- if ((error = git_buf_printf(&prefix, "%s://", scheme)) < 0)
+ if ((error = git_str_printf(&prefix, "%s://", scheme)) < 0)
goto on_error;
git_vector_foreach(&custom_transports, i, d) {
@@ -164,7 +164,7 @@ int git_transport_register(
definition = git__calloc(1, sizeof(transport_definition));
GIT_ERROR_CHECK_ALLOC(definition);
- definition->prefix = git_buf_detach(&prefix);
+ definition->prefix = git_str_detach(&prefix);
definition->fn = cb;
definition->param = param;
@@ -174,21 +174,21 @@ int git_transport_register(
return 0;
on_error:
- git_buf_dispose(&prefix);
+ git_str_dispose(&prefix);
git__free(definition);
return error;
}
int git_transport_unregister(const char *scheme)
{
- git_buf prefix = GIT_BUF_INIT;
+ git_str prefix = GIT_STR_INIT;
transport_definition *d;
size_t i;
int error = 0;
GIT_ASSERT_ARG(scheme);
- if ((error = git_buf_printf(&prefix, "%s://", scheme)) < 0)
+ if ((error = git_str_printf(&prefix, "%s://", scheme)) < 0)
goto done;
git_vector_foreach(&custom_transports, i, d) {
@@ -210,7 +210,7 @@ int git_transport_unregister(const char *scheme)
error = GIT_ENOTFOUND;
done:
- git_buf_dispose(&prefix);
+ git_str_dispose(&prefix);
return error;
}
diff --git a/src/transports/auth.c b/src/transports/auth.c
index 51763e359..90b6b124f 100644
--- a/src/transports/auth.c
+++ b/src/transports/auth.c
@@ -7,17 +7,15 @@
#include "auth.h"
-#include "git2.h"
-#include "buffer.h"
#include "git2/sys/credential.h"
static int basic_next_token(
- git_buf *out,
+ git_str *out,
git_http_auth_context *ctx,
git_credential *c)
{
git_credential_userpass_plaintext *cred;
- git_buf raw = GIT_BUF_INIT;
+ git_str raw = GIT_STR_INIT;
int error = GIT_EAUTH;
GIT_UNUSED(ctx);
@@ -29,11 +27,11 @@ static int basic_next_token(
cred = (git_credential_userpass_plaintext *)c;
- git_buf_printf(&raw, "%s:%s", cred->username, cred->password);
+ git_str_printf(&raw, "%s:%s", cred->username, cred->password);
- if (git_buf_oom(&raw) ||
- git_buf_puts(out, "Basic ") < 0 ||
- git_buf_encode_base64(out, git_buf_cstr(&raw), raw.size) < 0)
+ if (git_str_oom(&raw) ||
+ git_str_puts(out, "Basic ") < 0 ||
+ git_str_encode_base64(out, git_str_cstr(&raw), raw.size) < 0)
goto on_error;
error = 0;
@@ -42,7 +40,7 @@ on_error:
if (raw.size)
git__memzero(raw.ptr, raw.size);
- git_buf_dispose(&raw);
+ git_str_dispose(&raw);
return error;
}
diff --git a/src/transports/auth.h b/src/transports/auth.h
index 9caac4676..824d7198c 100644
--- a/src/transports/auth.h
+++ b/src/transports/auth.h
@@ -10,7 +10,6 @@
#include "common.h"
-#include "git2.h"
#include "netops.h"
typedef enum {
@@ -35,7 +34,7 @@ struct git_http_auth_context {
int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
/** Gets the next authentication token from the context */
- int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_credential *cred);
+ int (*next_token)(git_str *out, git_http_auth_context *ctx, git_credential *cred);
/** Examines if all tokens have been presented. */
int (*is_complete)(git_http_auth_context *ctx);
diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c
index 31469933e..6380504be 100644
--- a/src/transports/auth_negotiate.c
+++ b/src/transports/auth_negotiate.c
@@ -10,7 +10,6 @@
#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK)
#include "git2.h"
-#include "buffer.h"
#include "auth.h"
#include "git2/sys/credential.h"
@@ -33,7 +32,7 @@ typedef struct {
git_http_auth_context parent;
unsigned configured : 1,
complete : 1;
- git_buf target;
+ git_str target;
char *challenge;
gss_ctx_id_t gss_context;
gss_OID oid;
@@ -87,14 +86,14 @@ static void negotiate_context_dispose(http_auth_negotiate_context *ctx)
ctx->gss_context = GSS_C_NO_CONTEXT;
}
- git_buf_dispose(&ctx->target);
+ git_str_dispose(&ctx->target);
git__free(ctx->challenge);
ctx->challenge = NULL;
}
static int negotiate_next_token(
- git_buf *buf,
+ git_str *buf,
git_http_auth_context *c,
git_credential *cred)
{
@@ -104,7 +103,7 @@ static int negotiate_next_token(
input_token = GSS_C_EMPTY_BUFFER,
output_token = GSS_C_EMPTY_BUFFER;
gss_buffer_t input_token_ptr = GSS_C_NO_BUFFER;
- git_buf input_buf = GIT_BUF_INIT;
+ git_str input_buf = GIT_STR_INIT;
gss_name_t server = NULL;
gss_OID mech;
size_t challenge_len;
@@ -142,7 +141,7 @@ static int negotiate_next_token(
}
if (challenge_len > 9) {
- if (git_buf_decode_base64(&input_buf,
+ if (git_str_decode_base64(&input_buf,
ctx->challenge + 10, challenge_len - 10) < 0) {
git_error_set(GIT_ERROR_NET, "invalid negotiate challenge from server");
error = -1;
@@ -192,16 +191,16 @@ static int negotiate_next_token(
goto done;
}
- git_buf_puts(buf, "Negotiate ");
- git_buf_encode_base64(buf, output_token.value, output_token.length);
+ git_str_puts(buf, "Negotiate ");
+ git_str_encode_base64(buf, output_token.value, output_token.length);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
error = -1;
done:
gss_release_name(&status_minor, &server);
gss_release_buffer(&status_minor, (gss_buffer_t) &output_token);
- git_buf_dispose(&input_buf);
+ git_str_dispose(&input_buf);
return error;
}
@@ -270,10 +269,10 @@ static int negotiate_init_context(
return GIT_EAUTH;
}
- git_buf_puts(&ctx->target, "HTTP@");
- git_buf_puts(&ctx->target, url->host);
+ git_str_puts(&ctx->target, "HTTP@");
+ git_str_puts(&ctx->target, url->host);
- if (git_buf_oom(&ctx->target))
+ if (git_str_oom(&ctx->target))
return -1;
ctx->gss_context = GSS_C_NO_CONTEXT;
diff --git a/src/transports/auth_ntlm.c b/src/transports/auth_ntlm.c
index 742db75b3..f49ce101a 100644
--- a/src/transports/auth_ntlm.c
+++ b/src/transports/auth_ntlm.c
@@ -5,11 +5,11 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "git2.h"
+#include "auth_ntlm.h"
+
#include "common.h"
-#include "buffer.h"
+#include "str.h"
#include "auth.h"
-#include "auth_ntlm.h"
#include "git2/sys/credential.h"
#ifdef GIT_NTLM
@@ -77,12 +77,12 @@ done:
}
static int ntlm_next_token(
- git_buf *buf,
+ git_str *buf,
git_http_auth_context *c,
git_credential *cred)
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
- git_buf input_buf = GIT_BUF_INIT;
+ git_str input_buf = GIT_STR_INIT;
const unsigned char *msg;
size_t challenge_len, msg_len;
int error = GIT_EAUTH;
@@ -129,7 +129,7 @@ static int ntlm_next_token(
goto done;
}
- if (git_buf_decode_base64(&input_buf,
+ if (git_str_decode_base64(&input_buf,
ctx->challenge + 5, challenge_len - 5) < 0) {
git_error_set(GIT_ERROR_NET, "invalid NTLM challenge from server");
goto done;
@@ -149,16 +149,16 @@ static int ntlm_next_token(
}
}
- git_buf_puts(buf, "NTLM ");
- git_buf_encode_base64(buf, (const char *)msg, msg_len);
+ git_str_puts(buf, "NTLM ");
+ git_str_encode_base64(buf, (const char *)msg, msg_len);
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
goto done;
error = 0;
done:
- git_buf_dispose(&input_buf);
+ git_str_dispose(&input_buf);
return error;
}
diff --git a/src/transports/auth_ntlm.h b/src/transports/auth_ntlm.h
index a7cd6d795..40689498c 100644
--- a/src/transports/auth_ntlm.h
+++ b/src/transports/auth_ntlm.h
@@ -8,7 +8,6 @@
#ifndef INCLUDE_transports_auth_ntlm_h__
#define INCLUDE_transports_auth_ntlm_h__
-#include "git2.h"
#include "auth.h"
/* NTLM requires a full request/challenge/response */
diff --git a/src/transports/git.c b/src/transports/git.c
index 7c93155a8..591e2ab03 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -7,12 +7,10 @@
#include "common.h"
-#include "git2.h"
-#include "buffer.h"
#include "netops.h"
-#include "git2/sys/transport.h"
#include "stream.h"
#include "streams/socket.h"
+#include "git2/sys/transport.h"
#define OWNING_SUBTRANSPORT(s) ((git_subtransport *)(s)->parent.subtransport)
@@ -39,7 +37,7 @@ typedef struct {
*
* For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0
*/
-static int gen_proto(git_buf *request, const char *cmd, const char *url)
+static int gen_proto(git_str *request, const char *cmd, const char *url)
{
char *delim, *repo;
char host[] = "host=";
@@ -61,13 +59,13 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1;
- git_buf_grow(request, len);
- git_buf_printf(request, "%04x%s %s%c%s",
+ git_str_grow(request, len);
+ git_str_printf(request, "%04x%s %s%c%s",
(unsigned int)(len & 0x0FFFF), cmd, repo, 0, host);
- git_buf_put(request, url, delim - url);
- git_buf_putc(request, '\0');
+ git_str_put(request, url, delim - url);
+ git_str_putc(request, '\0');
- if (git_buf_oom(request))
+ if (git_str_oom(request))
return -1;
return 0;
@@ -75,7 +73,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
static int send_command(git_proto_stream *s)
{
- git_buf request = GIT_BUF_INIT;
+ git_str request = GIT_STR_INIT;
int error;
if ((error = gen_proto(&request, s->cmd, s->url)) < 0)
@@ -87,7 +85,7 @@ static int send_command(git_proto_stream *s)
s->sent_command = 1;
cleanup:
- git_buf_dispose(&request);
+ git_str_dispose(&request);
return error;
}
diff --git a/src/transports/http.c b/src/transports/http.c
index 914335aba..adcb1ac43 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -9,13 +9,10 @@
#ifndef GIT_WINHTTP
-#include "git2.h"
#include "http_parser.h"
-#include "buffer.h"
#include "net.h"
#include "netops.h"
#include "remote.h"
-#include "git2/sys/credential.h"
#include "smart.h"
#include "auth.h"
#include "http.h"
@@ -25,6 +22,7 @@
#include "streams/tls.h"
#include "streams/socket.h"
#include "httpclient.h"
+#include "git2/sys/credential.h"
bool git_http__expect_continue = false;
diff --git a/src/transports/http.h b/src/transports/http.h
index 5c360b883..8e8e7226e 100644
--- a/src/transports/http.h
+++ b/src/transports/http.h
@@ -8,7 +8,6 @@
#ifndef INCLUDE_transports_http_h__
#define INCLUDE_transports_http_h__
-#include "buffer.h"
#include "settings.h"
#include "httpclient.h"
@@ -16,14 +15,14 @@
extern bool git_http__expect_continue;
-GIT_INLINE(int) git_http__user_agent(git_buf *buf)
+GIT_INLINE(int) git_http__user_agent(git_str *buf)
{
const char *ua = git_libgit2__user_agent();
if (!ua)
ua = "libgit2 " LIBGIT2_VERSION;
- return git_buf_printf(buf, "git/2.0 (%s)", ua);
+ return git_str_printf(buf, "git/2.0 (%s)", ua);
}
#endif
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index 5b8949a04..75782da82 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -84,8 +84,8 @@ typedef struct {
git_http_response *response;
/* Temporary buffers to avoid extra mallocs */
- git_buf parse_header_name;
- git_buf parse_header_value;
+ git_str parse_header_name;
+ git_str parse_header_value;
/* Parser state */
int error;
@@ -120,8 +120,8 @@ struct git_http_client {
request_chunked : 1;
/* Temporary buffers to avoid extra mallocs */
- git_buf request_msg;
- git_buf read_buf;
+ git_str request_msg;
+ git_str read_buf;
/* A subset of information from the request */
size_t request_body_len,
@@ -160,8 +160,8 @@ static int on_header_complete(http_parser *parser)
git_http_client *client = ctx->client;
git_http_response *response = ctx->response;
- git_buf *name = &ctx->parse_header_name;
- git_buf *value = &ctx->parse_header_value;
+ git_str *name = &ctx->parse_header_name;
+ git_str *value = &ctx->parse_header_value;
if (!strcasecmp("Content-Type", name->ptr)) {
if (response->content_type) {
@@ -193,7 +193,7 @@ static int on_header_complete(http_parser *parser)
} else if (!strcasecmp("Transfer-Encoding", name->ptr) &&
!strcasecmp("chunked", value->ptr)) {
ctx->response->chunked = 1;
- } else if (!strcasecmp("Proxy-Authenticate", git_buf_cstr(name))) {
+ } else if (!strcasecmp("Proxy-Authenticate", git_str_cstr(name))) {
char *dup = git__strndup(value->ptr, value->size);
GIT_ERROR_CHECK_ALLOC(dup);
@@ -232,15 +232,15 @@ static int on_header_field(http_parser *parser, const char *str, size_t len)
if (on_header_complete(parser) < 0)
return ctx->parse_status = PARSE_STATUS_ERROR;
- git_buf_clear(&ctx->parse_header_name);
- git_buf_clear(&ctx->parse_header_value);
+ git_str_clear(&ctx->parse_header_name);
+ git_str_clear(&ctx->parse_header_value);
/* Fall through */
case PARSE_HEADER_NONE:
case PARSE_HEADER_NAME:
ctx->parse_header_state = PARSE_HEADER_NAME;
- if (git_buf_put(&ctx->parse_header_name, str, len) < 0)
+ if (git_str_put(&ctx->parse_header_name, str, len) < 0)
return ctx->parse_status = PARSE_STATUS_ERROR;
break;
@@ -263,7 +263,7 @@ static int on_header_value(http_parser *parser, const char *str, size_t len)
case PARSE_HEADER_VALUE:
ctx->parse_header_state = PARSE_HEADER_VALUE;
- if (git_buf_put(&ctx->parse_header_value, str, len) < 0)
+ if (git_str_put(&ctx->parse_header_value, str, len) < 0)
return ctx->parse_status = PARSE_STATUS_ERROR;
break;
@@ -548,7 +548,7 @@ static void free_auth_context(git_http_server *server)
}
static int apply_credentials(
- git_buf *buf,
+ git_str *buf,
git_http_server *server,
const char *header_name,
git_credential *credentials)
@@ -556,7 +556,7 @@ static int apply_credentials(
git_http_auth_context *auth = server->auth_context;
git_vector *challenges = &server->auth_challenges;
const char *challenge;
- git_buf token = GIT_BUF_INIT;
+ git_str token = GIT_STR_INIT;
int error = 0;
/* We've started a new request without creds; free the context. */
@@ -602,15 +602,15 @@ static int apply_credentials(
}
if (token.size > 0)
- error = git_buf_printf(buf, "%s: %s\r\n", header_name, token.ptr);
+ error = git_str_printf(buf, "%s: %s\r\n", header_name, token.ptr);
done:
- git_buf_dispose(&token);
+ git_str_dispose(&token);
return error;
}
GIT_INLINE(int) apply_server_credentials(
- git_buf *buf,
+ git_str *buf,
git_http_client *client,
git_http_request *request)
{
@@ -621,7 +621,7 @@ GIT_INLINE(int) apply_server_credentials(
}
GIT_INLINE(int) apply_proxy_credentials(
- git_buf *buf,
+ git_str *buf,
git_http_client *client,
git_http_request *request)
{
@@ -631,54 +631,54 @@ GIT_INLINE(int) apply_proxy_credentials(
request->proxy_credentials);
}
-static int puts_host_and_port(git_buf *buf, git_net_url *url, bool force_port)
+static int puts_host_and_port(git_str *buf, git_net_url *url, bool force_port)
{
bool ipv6 = git_net_url_is_ipv6(url);
if (ipv6)
- git_buf_putc(buf, '[');
+ git_str_putc(buf, '[');
- git_buf_puts(buf, url->host);
+ git_str_puts(buf, url->host);
if (ipv6)
- git_buf_putc(buf, ']');
+ git_str_putc(buf, ']');
if (force_port || !git_net_url_is_default_port(url)) {
- git_buf_putc(buf, ':');
- git_buf_puts(buf, url->port);
+ git_str_putc(buf, ':');
+ git_str_puts(buf, url->port);
}
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
static int generate_connect_request(
git_http_client *client,
git_http_request *request)
{
- git_buf *buf;
+ git_str *buf;
int error;
- git_buf_clear(&client->request_msg);
+ git_str_clear(&client->request_msg);
buf = &client->request_msg;
- git_buf_puts(buf, "CONNECT ");
+ git_str_puts(buf, "CONNECT ");
puts_host_and_port(buf, &client->server.url, true);
- git_buf_puts(buf, " HTTP/1.1\r\n");
+ git_str_puts(buf, " HTTP/1.1\r\n");
- git_buf_puts(buf, "User-Agent: ");
+ git_str_puts(buf, "User-Agent: ");
git_http__user_agent(buf);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- git_buf_puts(buf, "Host: ");
+ git_str_puts(buf, "Host: ");
puts_host_and_port(buf, &client->server.url, true);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
if ((error = apply_proxy_credentials(buf, client, request) < 0))
return -1;
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
static bool use_connect_proxy(git_http_client *client)
@@ -690,53 +690,53 @@ static int generate_request(
git_http_client *client,
git_http_request *request)
{
- git_buf *buf;
+ git_str *buf;
size_t i;
int error;
GIT_ASSERT_ARG(client);
GIT_ASSERT_ARG(request);
- git_buf_clear(&client->request_msg);
+ git_str_clear(&client->request_msg);
buf = &client->request_msg;
/* GET|POST path HTTP/1.1 */
- git_buf_puts(buf, name_for_method(request->method));
- git_buf_putc(buf, ' ');
+ git_str_puts(buf, name_for_method(request->method));
+ git_str_putc(buf, ' ');
if (request->proxy && strcmp(request->url->scheme, "https"))
git_net_url_fmt(buf, request->url);
else
git_net_url_fmt_path(buf, request->url);
- git_buf_puts(buf, " HTTP/1.1\r\n");
+ git_str_puts(buf, " HTTP/1.1\r\n");
- git_buf_puts(buf, "User-Agent: ");
+ git_str_puts(buf, "User-Agent: ");
git_http__user_agent(buf);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- git_buf_puts(buf, "Host: ");
+ git_str_puts(buf, "Host: ");
puts_host_and_port(buf, request->url, false);
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
if (request->accept)
- git_buf_printf(buf, "Accept: %s\r\n", request->accept);
+ git_str_printf(buf, "Accept: %s\r\n", request->accept);
else
- git_buf_puts(buf, "Accept: */*\r\n");
+ git_str_puts(buf, "Accept: */*\r\n");
if (request->content_type)
- git_buf_printf(buf, "Content-Type: %s\r\n",
+ git_str_printf(buf, "Content-Type: %s\r\n",
request->content_type);
if (request->chunked)
- git_buf_puts(buf, "Transfer-Encoding: chunked\r\n");
+ git_str_puts(buf, "Transfer-Encoding: chunked\r\n");
if (request->content_length > 0)
- git_buf_printf(buf, "Content-Length: %"PRIuZ "\r\n",
+ git_str_printf(buf, "Content-Length: %"PRIuZ "\r\n",
request->content_length);
if (request->expect_continue)
- git_buf_printf(buf, "Expect: 100-continue\r\n");
+ git_str_printf(buf, "Expect: 100-continue\r\n");
if ((error = apply_server_credentials(buf, client, request)) < 0 ||
(!use_connect_proxy(client) &&
@@ -748,13 +748,13 @@ static int generate_request(
const char *hdr = request->custom_headers->strings[i];
if (hdr)
- git_buf_printf(buf, "%s\r\n", hdr);
+ git_str_printf(buf, "%s\r\n", hdr);
}
}
- git_buf_puts(buf, "\r\n");
+ git_str_puts(buf, "\r\n");
- if (git_buf_oom(buf))
+ if (git_str_oom(buf))
return -1;
return 0;
@@ -1077,7 +1077,7 @@ GIT_INLINE(int) client_read(git_http_client *client)
client->proxy.stream : client->server.stream;
/*
- * We use a git_buf for convenience, but statically allocate it and
+ * We use a git_str for convenience, but statically allocate it and
* don't resize. Limit our consumption to INT_MAX since calling
* functions use an int return type to return number of bytes read.
*/
@@ -1198,7 +1198,7 @@ GIT_INLINE(int) client_read_and_parse(git_http_client *client)
return -1;
}
- git_buf_consume_bytes(&client->read_buf, parsed_len);
+ git_str_consume_bytes(&client->read_buf, parsed_len);
return (int)parsed_len;
}
@@ -1235,7 +1235,7 @@ static void complete_response_body(git_http_client *client)
}
done:
- git_buf_clear(&client->read_buf);
+ git_str_clear(&client->read_buf);
}
int git_http_client_send_request(
@@ -1257,12 +1257,12 @@ int git_http_client_send_request(
return 0;
if (git_trace_level() >= GIT_TRACE_DEBUG) {
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_net_url_fmt(&url, request->url);
git_trace(GIT_TRACE_DEBUG, "Sending %s request to %s",
name_for_method(request->method),
url.ptr ? url.ptr : "<invalid>");
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
if ((error = http_client_connect(client, request)) < 0 ||
@@ -1314,7 +1314,7 @@ int git_http_client_send_body(
size_t buffer_len)
{
git_http_server *server;
- git_buf hdr = GIT_BUF_INIT;
+ git_str hdr = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(client);
@@ -1341,7 +1341,7 @@ int git_http_client_send_body(
client->request_body_remain -= buffer_len;
} else {
- if ((error = git_buf_printf(&hdr, "%" PRIxZ "\r\n", buffer_len)) < 0 ||
+ if ((error = git_str_printf(&hdr, "%" PRIxZ "\r\n", buffer_len)) < 0 ||
(error = stream_write(server, hdr.ptr, hdr.size)) < 0 ||
(error = stream_write(server, buffer, buffer_len)) < 0 ||
(error = stream_write(server, "\r\n", 2)) < 0)
@@ -1349,7 +1349,7 @@ int git_http_client_send_body(
}
done:
- git_buf_dispose(&hdr);
+ git_str_dispose(&hdr);
return error;
}
@@ -1422,8 +1422,8 @@ int git_http_client_read_response(
GIT_ASSERT(client->state == READING_BODY || client->state == DONE);
done:
- git_buf_dispose(&parser_context.parse_header_name);
- git_buf_dispose(&parser_context.parse_header_value);
+ git_str_dispose(&parser_context.parse_header_name);
+ git_str_dispose(&parser_context.parse_header_value);
return error;
}
@@ -1531,7 +1531,7 @@ int git_http_client_new(
client = git__calloc(1, sizeof(git_http_client));
GIT_ERROR_CHECK_ALLOC(client);
- git_buf_init(&client->read_buf, GIT_READ_BUFFER_SIZE);
+ git_str_init(&client->read_buf, GIT_READ_BUFFER_SIZE);
GIT_ERROR_CHECK_ALLOC(client->read_buf.ptr);
if (opts)
@@ -1560,7 +1560,7 @@ static void http_client_close(git_http_client *client)
http_server_close(&client->server);
http_server_close(&client->proxy);
- git_buf_dispose(&client->request_msg);
+ git_str_dispose(&client->request_msg);
client->state = 0;
client->request_count = 0;
@@ -1574,6 +1574,6 @@ void git_http_client_free(git_http_client *client)
return;
http_client_close(client);
- git_buf_dispose(&client->read_buf);
+ git_str_dispose(&client->read_buf);
git__free(client);
}
diff --git a/src/transports/local.c b/src/transports/local.c
index bb31b1345..0656ea592 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -7,6 +7,16 @@
#include "common.h"
+#include "pack-objects.h"
+#include "refs.h"
+#include "posix.h"
+#include "path.h"
+#include "repository.h"
+#include "odb.h"
+#include "push.h"
+#include "remote.h"
+#include "proxy.h"
+
#include "git2/types.h"
#include "git2/net.h"
#include "git2/repository.h"
@@ -19,17 +29,6 @@
#include "git2/commit.h"
#include "git2/revparse.h"
-#include "pack-objects.h"
-#include "refs.h"
-#include "posix.h"
-#include "path.h"
-#include "buffer.h"
-#include "repository.h"
-#include "odb.h"
-#include "push.h"
-#include "remote.h"
-#include "proxy.h"
-
typedef struct {
git_transport parent;
git_remote *owner;
@@ -71,7 +70,7 @@ static int add_ref(transport_local *t, const char *name)
git_remote_head *head;
git_oid obj_id;
git_object *obj = NULL, *target = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
if ((error = git_reference_lookup(&ref, t->repo, name)) < 0)
@@ -132,11 +131,11 @@ static int add_ref(transport_local *t, const char *name)
head = git__calloc(1, sizeof(git_remote_head));
GIT_ERROR_CHECK_ALLOC(head);
- if (git_buf_join(&buf, 0, name, peeled) < 0) {
+ if (git_str_join(&buf, 0, name, peeled) < 0) {
free_head(head);
return -1;
}
- head->name = git_buf_detach(&buf);
+ head->name = git_str_detach(&buf);
if (!(error = git_tag_peel(&target, (git_tag *)obj))) {
git_oid_cpy(&head->oid, git_object_id(target));
@@ -210,7 +209,7 @@ static int local_connect(
int error;
transport_local *t = (transport_local *) transport;
const char *path;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
GIT_UNUSED(cred_acquire_cb);
GIT_UNUSED(cred_acquire_payload);
@@ -228,14 +227,14 @@ static int local_connect(
/* 'url' may be a url or path; convert to a path */
if ((error = git_path_from_url_or_path(&buf, url)) < 0) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
- path = git_buf_cstr(&buf);
+ path = git_str_cstr(&buf);
error = git_repository_open(&repo, path);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
return -1;
@@ -346,7 +345,7 @@ static int local_push(
push_spec *spec;
char *url = NULL;
const char *path;
- git_buf buf = GIT_BUF_INIT, odb_path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, odb_path = GIT_STR_INIT;
int error;
size_t j;
@@ -354,14 +353,14 @@ static int local_push(
/* 'push->remote->url' may be a url or path; convert to a path */
if ((error = git_path_from_url_or_path(&buf, push->remote->url)) < 0) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
- path = git_buf_cstr(&buf);
+ path = git_str_cstr(&buf);
error = git_repository_open(&remote_repo, path);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
return error;
@@ -378,12 +377,12 @@ static int local_push(
goto on_error;
}
- if ((error = git_repository_item_path(&odb_path, remote_repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
- || (error = git_buf_joinpath(&odb_path, odb_path.ptr, "pack")) < 0)
+ if ((error = git_repository__item_path(&odb_path, remote_repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0
+ || (error = git_str_joinpath(&odb_path, odb_path.ptr, "pack")) < 0)
goto on_error;
error = git_packbuilder_write(push->pb, odb_path.ptr, 0, transfer_to_push_transfer, (void *) cbs);
- git_buf_dispose(&odb_path);
+ git_str_dispose(&odb_path);
if (error < 0)
goto on_error;
@@ -479,7 +478,7 @@ static const char *compressing_objects_fmt = "Compressing objects: %.0f%% (%d/%d
static int local_counting(int stage, unsigned int current, unsigned int total, void *payload)
{
- git_buf progress_info = GIT_BUF_INIT;
+ git_str progress_info = GIT_STR_INIT;
transport_local *t = payload;
int error;
@@ -487,22 +486,22 @@ static int local_counting(int stage, unsigned int current, unsigned int total, v
return 0;
if (stage == GIT_PACKBUILDER_ADDING_OBJECTS) {
- git_buf_printf(&progress_info, counting_objects_fmt, current);
+ git_str_printf(&progress_info, counting_objects_fmt, current);
} else if (stage == GIT_PACKBUILDER_DELTAFICATION) {
float perc = (((float) current) / total) * 100;
- git_buf_printf(&progress_info, compressing_objects_fmt, perc, current, total);
+ git_str_printf(&progress_info, compressing_objects_fmt, perc, current, total);
if (current == total)
- git_buf_printf(&progress_info, ", done\n");
+ git_str_printf(&progress_info, ", done\n");
else
- git_buf_putc(&progress_info, '\r');
+ git_str_putc(&progress_info, '\r');
}
- if (git_buf_oom(&progress_info))
+ if (git_str_oom(&progress_info))
return -1;
- error = t->progress_cb(git_buf_cstr(&progress_info), (int)git_buf_len(&progress_info), t->message_cb_payload);
- git_buf_dispose(&progress_info);
+ error = t->progress_cb(git_str_cstr(&progress_info), (int)git_str_len(&progress_info), t->message_cb_payload);
+ git_str_dispose(&progress_info);
return error;
}
@@ -545,7 +544,7 @@ static int local_download_pack(
git_packbuilder *pack = NULL;
git_odb_writepack *writepack = NULL;
git_odb *odb = NULL;
- git_buf progress_info = GIT_BUF_INIT;
+ git_str progress_info = GIT_STR_INIT;
if ((error = git_revwalk_new(&walk, t->repo)) < 0)
goto cleanup;
@@ -584,11 +583,11 @@ static int local_download_pack(
if ((error = git_packbuilder_insert_walk(pack, walk)))
goto cleanup;
- if ((error = git_buf_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack))) < 0)
+ if ((error = git_str_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack))) < 0)
goto cleanup;
if (t->progress_cb &&
- (error = t->progress_cb(git_buf_cstr(&progress_info), (int)git_buf_len(&progress_info), t->message_cb_payload)) < 0)
+ (error = t->progress_cb(git_str_cstr(&progress_info), (int)git_str_len(&progress_info), t->message_cb_payload)) < 0)
goto cleanup;
/* Walk the objects, building a packfile */
@@ -596,13 +595,13 @@ static int local_download_pack(
goto cleanup;
/* One last one with the newline */
- git_buf_clear(&progress_info);
- git_buf_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack));
- if ((error = git_buf_putc(&progress_info, '\n')) < 0)
+ git_str_clear(&progress_info);
+ git_str_printf(&progress_info, counting_objects_fmt, git_packbuilder_object_count(pack));
+ if ((error = git_str_putc(&progress_info, '\n')) < 0)
goto cleanup;
if (t->progress_cb &&
- (error = t->progress_cb(git_buf_cstr(&progress_info), (int)git_buf_len(&progress_info), t->message_cb_payload)) < 0)
+ (error = t->progress_cb(git_str_cstr(&progress_info), (int)git_str_len(&progress_info), t->message_cb_payload)) < 0)
goto cleanup;
if ((error = git_odb_write_pack(&writepack, odb, progress_cb, progress_payload)) != 0)
@@ -627,7 +626,7 @@ static int local_download_pack(
cleanup:
if (writepack) writepack->free(writepack);
- git_buf_dispose(&progress_info);
+ git_str_dispose(&progress_info);
git_packbuilder_free(pack);
git_revwalk_free(walk);
return error;
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 587f14358..fe024de2f 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -164,20 +164,20 @@ int git_smart__update_heads(transport_smart *t, git_vector *symrefs)
if (symrefs) {
git_refspec *spec;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t j;
int error = 0;
git_vector_foreach(symrefs, j, spec) {
- git_buf_clear(&buf);
+ git_str_clear(&buf);
if (git_refspec_src_matches(spec, ref->head.name) &&
- !(error = git_refspec_transform(&buf, spec, ref->head.name))) {
+ !(error = git_refspec__transform(&buf, spec, ref->head.name))) {
git__free(ref->head.symref_target);
- ref->head.symref_target = git_buf_detach(&buf);
+ ref->head.symref_target = git_str_detach(&buf);
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
if (error < 0)
return error;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index a05d4c9e3..225e64996 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -12,8 +12,8 @@
#include "git2.h"
#include "vector.h"
#include "netops.h"
-#include "buffer.h"
#include "push.h"
+#include "str.h"
#include "git2/sys/transport.h"
#define GIT_SIDE_BAND_DATA 1
@@ -189,11 +189,11 @@ int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
/* smart_pkt.c */
int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen);
-int git_pkt_buffer_flush(git_buf *buf);
+int git_pkt_buffer_flush(git_str *buf);
int git_pkt_send_flush(GIT_SOCKET s);
-int git_pkt_buffer_done(git_buf *buf);
-int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_buf *buf);
-int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
+int git_pkt_buffer_done(git_str *buf);
+int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_str *buf);
+int git_pkt_buffer_have(git_oid *oid, git_str *buf);
void git_pkt_free(git_pkt *pkt);
#endif
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 56b680d28..b42edd0d6 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -7,16 +7,16 @@
#include "common.h"
-#include "git2/types.h"
-#include "git2/errors.h"
-#include "git2/refs.h"
-#include "git2/revwalk.h"
-
#include "smart.h"
#include "util.h"
#include "netops.h"
#include "posix.h"
-#include "buffer.h"
+#include "str.h"
+
+#include "git2/types.h"
+#include "git2/errors.h"
+#include "git2/refs.h"
+#include "git2/revwalk.h"
#include <ctype.h>
@@ -522,43 +522,43 @@ void git_pkt_free(git_pkt *pkt)
git__free(pkt);
}
-int git_pkt_buffer_flush(git_buf *buf)
+int git_pkt_buffer_flush(git_str *buf)
{
- return git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str));
+ return git_str_put(buf, pkt_flush_str, strlen(pkt_flush_str));
}
-static int buffer_want_with_caps(const git_remote_head *head, transport_smart_caps *caps, git_buf *buf)
+static int buffer_want_with_caps(const git_remote_head *head, transport_smart_caps *caps, git_str *buf)
{
- git_buf str = GIT_BUF_INIT;
+ git_str str = GIT_STR_INIT;
char oid[GIT_OID_HEXSZ +1] = {0};
size_t len;
/* Prefer multi_ack_detailed */
if (caps->multi_ack_detailed)
- git_buf_puts(&str, GIT_CAP_MULTI_ACK_DETAILED " ");
+ git_str_puts(&str, GIT_CAP_MULTI_ACK_DETAILED " ");
else if (caps->multi_ack)
- git_buf_puts(&str, GIT_CAP_MULTI_ACK " ");
+ git_str_puts(&str, GIT_CAP_MULTI_ACK " ");
/* Prefer side-band-64k if the server supports both */
if (caps->side_band_64k)
- git_buf_printf(&str, "%s ", GIT_CAP_SIDE_BAND_64K);
+ git_str_printf(&str, "%s ", GIT_CAP_SIDE_BAND_64K);
else if (caps->side_band)
- git_buf_printf(&str, "%s ", GIT_CAP_SIDE_BAND);
+ git_str_printf(&str, "%s ", GIT_CAP_SIDE_BAND);
if (caps->include_tag)
- git_buf_puts(&str, GIT_CAP_INCLUDE_TAG " ");
+ git_str_puts(&str, GIT_CAP_INCLUDE_TAG " ");
if (caps->thin_pack)
- git_buf_puts(&str, GIT_CAP_THIN_PACK " ");
+ git_str_puts(&str, GIT_CAP_THIN_PACK " ");
if (caps->ofs_delta)
- git_buf_puts(&str, GIT_CAP_OFS_DELTA " ");
+ git_str_puts(&str, GIT_CAP_OFS_DELTA " ");
- if (git_buf_oom(&str))
+ if (git_str_oom(&str))
return -1;
len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ +
- git_buf_len(&str) + 1 /* LF */;
+ git_str_len(&str) + 1 /* LF */;
if (len > 0xffff) {
git_error_set(GIT_ERROR_NET,
@@ -566,13 +566,13 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca
return -1;
}
- git_buf_grow_by(buf, len);
+ git_str_grow_by(buf, len);
git_oid_fmt(oid, &head->oid);
- git_buf_printf(buf,
- "%04xwant %s %s\n", (unsigned int)len, oid, git_buf_cstr(&str));
- git_buf_dispose(&str);
+ git_str_printf(buf,
+ "%04xwant %s %s\n", (unsigned int)len, oid, git_str_cstr(&str));
+ git_str_dispose(&str);
- GIT_ERROR_CHECK_ALLOC_BUF(buf);
+ GIT_ERROR_CHECK_ALLOC_STR(buf);
return 0;
}
@@ -586,7 +586,7 @@ int git_pkt_buffer_wants(
const git_remote_head * const *refs,
size_t count,
transport_smart_caps *caps,
- git_buf *buf)
+ git_str *buf)
{
size_t i = 0;
const git_remote_head *head;
@@ -612,26 +612,26 @@ int git_pkt_buffer_wants(
continue;
git_oid_fmt(oid, &head->oid);
- git_buf_put(buf, pkt_want_prefix, strlen(pkt_want_prefix));
- git_buf_put(buf, oid, GIT_OID_HEXSZ);
- git_buf_putc(buf, '\n');
- if (git_buf_oom(buf))
+ git_str_put(buf, pkt_want_prefix, strlen(pkt_want_prefix));
+ git_str_put(buf, oid, GIT_OID_HEXSZ);
+ git_str_putc(buf, '\n');
+ if (git_str_oom(buf))
return -1;
}
return git_pkt_buffer_flush(buf);
}
-int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
+int git_pkt_buffer_have(git_oid *oid, git_str *buf)
{
char oidhex[GIT_OID_HEXSZ + 1];
memset(oidhex, 0x0, sizeof(oidhex));
git_oid_fmt(oidhex, oid);
- return git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
+ return git_str_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
}
-int git_pkt_buffer_done(git_buf *buf)
+int git_pkt_buffer_done(git_str *buf)
{
- return git_buf_puts(buf, pkt_done_str);
+ return git_str_puts(buf, pkt_done_str);
}
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 91de163e9..a9a623cc7 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -89,7 +89,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
{
int error;
const char *end;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_refspec *mapping = NULL;
ptr += strlen(GIT_CAP_SYMREF);
@@ -101,15 +101,15 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
!(end = strchr(ptr, '\0')))
goto on_invalid;
- if ((error = git_buf_put(&buf, ptr, end - ptr)) < 0)
+ if ((error = git_str_put(&buf, ptr, end - ptr)) < 0)
return error;
/* symref mapping has refspec format */
mapping = git__calloc(1, sizeof(git_refspec));
GIT_ERROR_CHECK_ALLOC(mapping);
- error = git_refspec__parse(mapping, git_buf_cstr(&buf), true);
- git_buf_dispose(&buf);
+ error = git_refspec__parse(mapping, git_str_cstr(&buf), true);
+ git_str_dispose(&buf);
/* if the error isn't OOM, then it's a parse error; let's use a nicer message */
if (error < 0) {
@@ -310,7 +310,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
transport_smart *t = (transport_smart *)transport;
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
gitno_buffer *buf = &t->buffer;
- git_buf data = GIT_BUF_INIT;
+ git_str data = GIT_STR_INIT;
git_revwalk *walk = NULL;
int error = -1;
git_pkt_type pkt_type;
@@ -354,7 +354,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
}
git_pkt_buffer_flush(&data);
- if (git_buf_oom(&data)) {
+ if (git_str_oom(&data)) {
error = -1;
goto on_error;
}
@@ -362,7 +362,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
goto on_error;
- git_buf_clear(&data);
+ git_str_clear(&data);
if (t->caps.multi_ack || t->caps.multi_ack_detailed) {
if ((error = store_common(t)) < 0)
goto on_error;
@@ -397,7 +397,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
goto on_error;
}
- if (git_buf_oom(&data)) {
+ if (git_str_oom(&data)) {
error = -1;
goto on_error;
}
@@ -417,7 +417,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
goto on_error;
}
- if (git_buf_oom(&data)) {
+ if (git_str_oom(&data)) {
error = -1;
goto on_error;
}
@@ -434,7 +434,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
goto on_error;
- git_buf_dispose(&data);
+ git_str_dispose(&data);
git_revwalk_free(walk);
/* Now let's eat up whatever the server gives us */
@@ -454,7 +454,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
on_error:
git_revwalk_free(walk);
- git_buf_dispose(&data);
+ git_str_dispose(&data);
return error;
}
@@ -626,7 +626,7 @@ done:
return error;
}
-static int gen_pktline(git_buf *buf, git_push *push)
+static int gen_pktline(git_str *buf, git_push *push)
{
push_spec *spec;
size_t i, len;
@@ -647,24 +647,24 @@ static int gen_pktline(git_buf *buf, git_push *push)
git_oid_fmt(old_id, &spec->roid);
git_oid_fmt(new_id, &spec->loid);
- git_buf_printf(buf, "%04"PRIxZ"%s %s %s", len, old_id, new_id, spec->refspec.dst);
+ git_str_printf(buf, "%04"PRIxZ"%s %s %s", len, old_id, new_id, spec->refspec.dst);
if (i == 0) {
- git_buf_putc(buf, '\0');
+ git_str_putc(buf, '\0');
/* Core git always starts their capabilities string with a space */
if (push->report_status) {
- git_buf_putc(buf, ' ');
- git_buf_printf(buf, GIT_CAP_REPORT_STATUS);
+ git_str_putc(buf, ' ');
+ git_str_printf(buf, GIT_CAP_REPORT_STATUS);
}
- git_buf_putc(buf, ' ');
- git_buf_printf(buf, GIT_CAP_SIDE_BAND_64K);
+ git_str_putc(buf, ' ');
+ git_str_printf(buf, GIT_CAP_SIDE_BAND_64K);
}
- git_buf_putc(buf, '\n');
+ git_str_putc(buf, '\n');
}
- git_buf_puts(buf, "0000");
- return git_buf_oom(buf) ? -1 : 0;
+ git_str_puts(buf, "0000");
+ return git_str_oom(buf) ? -1 : 0;
}
static int add_push_report_pkt(git_push *push, git_pkt *pkt)
@@ -707,7 +707,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt)
return 0;
}
-static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, git_buf *data_pkt_buf)
+static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, git_str *data_pkt_buf)
{
git_pkt *pkt;
const char *line, *line_end = NULL;
@@ -718,7 +718,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
if (reading_from_buf) {
/* We had an existing partial packet, so add the new
* packet to the buffer and parse the whole thing */
- git_buf_put(data_pkt_buf, data_pkt->data, data_pkt->len);
+ git_str_put(data_pkt_buf, data_pkt->data, data_pkt->len);
line = data_pkt_buf->ptr;
line_len = data_pkt_buf->size;
}
@@ -734,7 +734,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
/* Buffer the data when the inner packet is split
* across multiple sideband packets */
if (!reading_from_buf)
- git_buf_put(data_pkt_buf, line, line_len);
+ git_str_put(data_pkt_buf, line, line_len);
error = 0;
goto done;
}
@@ -757,7 +757,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
done:
if (reading_from_buf)
- git_buf_consume(data_pkt_buf, line_end);
+ git_str_consume(data_pkt_buf, line_end);
return error;
}
@@ -767,7 +767,7 @@ static int parse_report(transport_smart *transport, git_push *push)
const char *line_end = NULL;
gitno_buffer *buf = &transport->buffer;
int error, recvd;
- git_buf data_pkt_buf = GIT_BUF_INIT;
+ git_str data_pkt_buf = GIT_STR_INIT;
for (;;) {
if (buf->offset > 0)
@@ -847,7 +847,7 @@ static int parse_report(transport_smart *transport, git_push *push)
}
}
done:
- git_buf_dispose(&data_pkt_buf);
+ git_str_dispose(&data_pkt_buf);
return error;
}
@@ -991,7 +991,7 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
{
transport_smart *t = (transport_smart *)transport;
struct push_packbuilder_payload packbuilder_payload = {0};
- git_buf pktline = GIT_BUF_INIT;
+ git_str pktline = GIT_STR_INIT;
int error = 0, need_pack = 0;
push_spec *spec;
unsigned int i;
@@ -1036,7 +1036,7 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
if ((error = git_smart__get_push_stream(t, &packbuilder_payload.stream)) < 0 ||
(error = gen_pktline(&pktline, push)) < 0 ||
- (error = packbuilder_payload.stream->write(packbuilder_payload.stream, git_buf_cstr(&pktline), git_buf_len(&pktline))) < 0)
+ (error = packbuilder_payload.stream->write(packbuilder_payload.stream, git_str_cstr(&pktline), git_str_len(&pktline))) < 0)
goto done;
if (need_pack &&
@@ -1071,6 +1071,6 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
}
done:
- git_buf_dispose(&pktline);
+ git_str_dispose(&pktline);
return error;
}
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 1b00be79c..e3bb5eef6 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -12,8 +12,6 @@
#endif
#include "runtime.h"
-#include "git2.h"
-#include "buffer.h"
#include "net.h"
#include "netops.h"
#include "smart.h"
@@ -65,7 +63,7 @@ static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg)
*
* For example: git-upload-pack '/libgit2/libgit2'
*/
-static int gen_proto(git_buf *request, const char *cmd, const char *url)
+static int gen_proto(git_str *request, const char *cmd, const char *url)
{
const char *repo;
int len;
@@ -94,13 +92,13 @@ done:
len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1;
- git_buf_grow(request, len);
- git_buf_puts(request, cmd);
- git_buf_puts(request, " '");
- git_buf_decode_percent(request, repo, strlen(repo));
- git_buf_puts(request, "'");
+ git_str_grow(request, len);
+ git_str_puts(request, cmd);
+ git_str_puts(request, " '");
+ git_str_decode_percent(request, repo, strlen(repo));
+ git_str_puts(request, "'");
- if (git_buf_oom(request))
+ if (git_str_oom(request))
return -1;
return 0;
@@ -109,7 +107,7 @@ done:
static int send_command(ssh_stream *s)
{
int error;
- git_buf request = GIT_BUF_INIT;
+ git_str request = GIT_STR_INIT;
error = gen_proto(&request, s->cmd, s->url);
if (error < 0)
@@ -124,7 +122,7 @@ static int send_command(ssh_stream *s)
s->sent_command = 1;
cleanup:
- git_buf_dispose(&request);
+ git_str_dispose(&request);
return error;
}
@@ -580,7 +578,7 @@ post_extract:
case LIBSSH2_HOSTKEY_TYPE_DSS:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_DSS;
break;
-
+
#ifdef LIBSSH2_HOSTKEY_TYPE_ECDSA_256
case LIBSSH2_HOSTKEY_TYPE_ECDSA_256:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256;
@@ -592,7 +590,7 @@ post_extract:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521;
break;
#endif
-
+
#ifdef LIBSSH2_HOSTKEY_TYPE_ED25519
case LIBSSH2_HOSTKEY_TYPE_ED25519:
cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ED25519;
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index f4801a451..efbaf0298 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -11,8 +11,8 @@
#include "git2.h"
#include "git2/transport.h"
-#include "buffer.h"
#include "posix.h"
+#include "str.h"
#include "netops.h"
#include "smart.h"
#include "remote.h"
@@ -372,7 +372,7 @@ static int apply_credentials(
static int winhttp_stream_connect(winhttp_stream *s)
{
winhttp_subtransport *t = OWNING_SUBTRANSPORT(s);
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *proxy_url = NULL;
wchar_t ct[MAX_CONTENT_TYPE_LEN];
LPCWSTR types[] = { L"*/*", NULL };
@@ -391,13 +391,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
if ((git__suffixcmp(t->server.url.path, "/") == 0) && (git__prefixcmp(service_url, "/") == 0))
service_url++;
/* Prepare URL */
- git_buf_printf(&buf, "%s%s", t->server.url.path, service_url);
+ git_str_printf(&buf, "%s%s", t->server.url.path, service_url);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
/* Convert URL to wide characters */
- if (git__utf8_to_16_alloc(&s->request_uri, git_buf_cstr(&buf)) < 0) {
+ if (git__utf8_to_16_alloc(&s->request_uri, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert string to wide form");
goto on_error;
}
@@ -438,7 +438,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
}
if (proxy_url) {
- git_buf processed_url = GIT_BUF_INIT;
+ git_str processed_url = GIT_STR_INIT;
WINHTTP_PROXY_INFO proxy_info;
wchar_t *proxy_wide;
@@ -453,28 +453,28 @@ static int winhttp_stream_connect(winhttp_stream *s)
goto on_error;
}
- git_buf_puts(&processed_url, t->proxy.url.scheme);
- git_buf_PUTS(&processed_url, "://");
+ git_str_puts(&processed_url, t->proxy.url.scheme);
+ git_str_PUTS(&processed_url, "://");
if (git_net_url_is_ipv6(&t->proxy.url))
- git_buf_putc(&processed_url, '[');
+ git_str_putc(&processed_url, '[');
- git_buf_puts(&processed_url, t->proxy.url.host);
+ git_str_puts(&processed_url, t->proxy.url.host);
if (git_net_url_is_ipv6(&t->proxy.url))
- git_buf_putc(&processed_url, ']');
+ git_str_putc(&processed_url, ']');
if (!git_net_url_is_default_port(&t->proxy.url))
- git_buf_printf(&processed_url, ":%s", t->proxy.url.port);
+ git_str_printf(&processed_url, ":%s", t->proxy.url.port);
- if (git_buf_oom(&processed_url)) {
+ if (git_str_oom(&processed_url)) {
error = -1;
goto on_error;
}
/* Convert URL to wide characters */
error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
- git_buf_dispose(&processed_url);
+ git_str_dispose(&processed_url);
if (error < 0)
goto on_error;
@@ -525,13 +525,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
if (post_verb == s->verb) {
/* Send Content-Type and Accept headers -- only necessary on a POST */
- git_buf_clear(&buf);
- if (git_buf_printf(&buf,
+ git_str_clear(&buf);
+ if (git_str_printf(&buf,
"Content-Type: application/x-git-%s-request",
s->service) < 0)
goto on_error;
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters");
goto on_error;
}
@@ -542,13 +542,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
goto on_error;
}
- git_buf_clear(&buf);
- if (git_buf_printf(&buf,
+ git_str_clear(&buf);
+ if (git_str_printf(&buf,
"Accept: application/x-git-%s-result",
s->service) < 0)
goto on_error;
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters");
goto on_error;
}
@@ -562,9 +562,9 @@ static int winhttp_stream_connect(winhttp_stream *s)
for (i = 0; i < t->owner->custom_headers.count; i++) {
if (t->owner->custom_headers.strings[i]) {
- git_buf_clear(&buf);
- git_buf_puts(&buf, t->owner->custom_headers.strings[i]);
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
+ git_str_clear(&buf);
+ git_str_puts(&buf, t->owner->custom_headers.strings[i]);
+ if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert custom header to wide characters");
goto on_error;
}
@@ -597,7 +597,7 @@ on_error:
winhttp_stream_close(s);
git__free(proxy_url);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -646,23 +646,23 @@ static int parse_unauthorized_response(
static int write_chunk(HINTERNET request, const char *buffer, size_t len)
{
DWORD bytes_written;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* Chunk header */
- git_buf_printf(&buf, "%"PRIXZ"\r\n", len);
+ git_str_printf(&buf, "%"PRIXZ"\r\n", len);
- if (git_buf_oom(&buf))
+ if (git_str_oom(&buf))
return -1;
if (!WinHttpWriteData(request,
- git_buf_cstr(&buf), (DWORD)git_buf_len(&buf),
+ git_str_cstr(&buf), (DWORD)git_str_len(&buf),
&bytes_written)) {
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_error_set(GIT_ERROR_OS, "failed to write chunk header");
return -1;
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Chunk body */
if (!WinHttpWriteData(request,
@@ -756,7 +756,7 @@ static int winhttp_connect(
wchar_t *wide_host = NULL;
int32_t port;
wchar_t *wide_ua = NULL;
- git_buf ipv6 = GIT_BUF_INIT, ua = GIT_BUF_INIT;
+ git_str ipv6 = GIT_STR_INIT, ua = GIT_STR_INIT;
const char *host;
int error = -1;
int default_timeout = TIMEOUT_INFINITE;
@@ -777,7 +777,7 @@ static int winhttp_connect(
/* IPv6? Add braces around the host. */
if (git_net_url_is_ipv6(&t->server.url)) {
- if (git_buf_printf(&ipv6, "[%s]", t->server.url.host) < 0)
+ if (git_str_printf(&ipv6, "[%s]", t->server.url.host) < 0)
goto on_error;
host = ipv6.ptr;
@@ -795,7 +795,7 @@ static int winhttp_connect(
if (git_http__user_agent(&ua) < 0)
goto on_error;
- if (git__utf8_to_16_alloc(&wide_ua, git_buf_cstr(&ua)) < 0) {
+ if (git__utf8_to_16_alloc(&wide_ua, git_str_cstr(&ua)) < 0) {
git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
goto on_error;
}
@@ -863,8 +863,8 @@ on_error:
if (error < 0)
winhttp_close_connection(t);
- git_buf_dispose(&ua);
- git_buf_dispose(&ipv6);
+ git_str_dispose(&ua);
+ git_str_dispose(&ipv6);
git__free(wide_host);
git__free(wide_ua);
diff --git a/src/tree-cache.c b/src/tree-cache.c
index 04d86fd36..0977c92f3 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -256,22 +256,22 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
return 0;
}
-static void write_tree(git_buf *out, git_tree_cache *tree)
+static void write_tree(git_str *out, git_tree_cache *tree)
{
size_t i;
- git_buf_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
+ git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
if (tree->entry_count != -1)
- git_buf_put(out, (const char *) &tree->oid, GIT_OID_RAWSZ);
+ git_str_put(out, (const char *) &tree->oid, GIT_OID_RAWSZ);
for (i = 0; i < tree->children_count; i++)
write_tree(out, tree->children[i]);
}
-int git_tree_cache_write(git_buf *out, git_tree_cache *tree)
+int git_tree_cache_write(git_str *out, git_tree_cache *tree)
{
write_tree(out, tree);
- return git_buf_oom(out) ? -1 : 0;
+ return git_str_oom(out) ? -1 : 0;
}
diff --git a/src/tree-cache.h b/src/tree-cache.h
index e02300e6e..a27e30466 100644
--- a/src/tree-cache.h
+++ b/src/tree-cache.h
@@ -11,7 +11,7 @@
#include "common.h"
#include "pool.h"
-#include "buffer.h"
+#include "str.h"
#include "git2/oid.h"
typedef struct git_tree_cache {
@@ -24,7 +24,7 @@ typedef struct git_tree_cache {
char name[GIT_FLEX_ARRAY];
} git_tree_cache;
-int git_tree_cache_write(git_buf *out, git_tree_cache *tree);
+int git_tree_cache_write(git_str *out, git_tree_cache *tree);
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool);
void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path);
const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path);
diff --git a/src/tree.c b/src/tree.c
index b1df79eac..c1e39158d 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -495,7 +495,7 @@ static int check_entry(git_repository *repo, const char *filename, const git_oid
static int git_treebuilder__write_with_buffer(
git_oid *oid,
git_treebuilder *bld,
- git_buf *buf)
+ git_str *buf)
{
int error = 0;
size_t i, entrycount;
@@ -503,14 +503,14 @@ static int git_treebuilder__write_with_buffer(
git_tree_entry *entry;
git_vector entries = GIT_VECTOR_INIT;
- git_buf_clear(buf);
+ git_str_clear(buf);
entrycount = git_strmap_size(bld->map);
if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
goto out;
if (buf->asize == 0 &&
- (error = git_buf_grow(buf, entrycount * 72)) < 0)
+ (error = git_str_grow(buf, entrycount * 72)) < 0)
goto out;
git_strmap_foreach_value(bld->map, entry, {
@@ -523,11 +523,11 @@ static int git_treebuilder__write_with_buffer(
for (i = 0; i < entries.length && !error; ++i) {
entry = git_vector_get(&entries, i);
- git_buf_printf(buf, "%o ", entry->attr);
- git_buf_put(buf, entry->filename, entry->filename_len + 1);
- git_buf_put(buf, (char *)entry->oid->id, GIT_OID_RAWSZ);
+ git_str_printf(buf, "%o ", entry->attr);
+ git_str_put(buf, entry->filename, entry->filename_len + 1);
+ git_str_put(buf, (char *)entry->oid->id, GIT_OID_RAWSZ);
- if (git_buf_oom(buf)) {
+ if (git_str_oom(buf)) {
error = -1;
goto out;
}
@@ -575,7 +575,7 @@ static int write_tree(
git_index *index,
const char *dirname,
size_t start,
- git_buf *shared_buf)
+ git_str *shared_buf)
{
git_treebuilder *bld = NULL;
size_t i, entries = git_index_entrycount(index);
@@ -676,7 +676,7 @@ int git_tree__write_index(
{
int ret;
git_tree *tree;
- git_buf shared_buf = GIT_BUF_INIT;
+ git_str shared_buf = GIT_STR_INIT;
bool old_ignore_case = false;
GIT_ASSERT_ARG(oid);
@@ -705,7 +705,7 @@ int git_tree__write_index(
}
ret = write_tree(oid, repo, index, "", 0, &shared_buf);
- git_buf_dispose(&shared_buf);
+ git_str_dispose(&shared_buf);
if (old_ignore_case)
git_index__set_ignore_case(index, true);
@@ -879,7 +879,7 @@ void git_treebuilder_free(git_treebuilder *bld)
if (bld == NULL)
return;
- git_buf_dispose(&bld->write_cache);
+ git_str_dispose(&bld->write_cache);
git_treebuilder_clear(bld);
git_strmap_free(bld->map);
git__free(bld);
@@ -959,7 +959,7 @@ int git_tree_entry_bypath(
static int tree_walk(
const git_tree *tree,
git_treewalk_cb callback,
- git_buf *path,
+ git_str *path,
void *payload,
bool preorder)
{
@@ -982,17 +982,17 @@ static int tree_walk(
if (git_tree_entry__is_tree(entry)) {
git_tree *subtree;
- size_t path_len = git_buf_len(path);
+ size_t path_len = git_str_len(path);
error = git_tree_lookup(&subtree, tree->object.repo, entry->oid);
if (error < 0)
break;
/* append the next entry to the path */
- git_buf_puts(path, entry->filename);
- git_buf_putc(path, '/');
+ git_str_puts(path, entry->filename);
+ git_str_putc(path, '/');
- if (git_buf_oom(path))
+ if (git_str_oom(path))
error = -1;
else
error = tree_walk(subtree, callback, path, payload, preorder);
@@ -1001,7 +1001,7 @@ static int tree_walk(
if (error != 0)
break;
- git_buf_truncate(path, path_len);
+ git_str_truncate(path, path_len);
}
if (!preorder) {
@@ -1024,7 +1024,7 @@ int git_tree_walk(
void *payload)
{
int error = 0;
- git_buf root_path = GIT_BUF_INIT;
+ git_str root_path = GIT_STR_INIT;
if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) {
git_error_set(GIT_ERROR_INVALID, "invalid walking mode for tree walk");
@@ -1034,7 +1034,7 @@ int git_tree_walk(
error = tree_walk(
tree, callback, &root_path, payload, (mode == GIT_TREEWALK_PRE));
- git_buf_dispose(&root_path);
+ git_str_dispose(&root_path);
return error;
}
@@ -1080,19 +1080,19 @@ GIT_INLINE(size_t) count_slashes(const char *path)
return count;
}
-static bool next_component(git_buf *out, const char *in)
+static bool next_component(git_str *out, const char *in)
{
const char *slash = strchr(in, '/');
- git_buf_clear(out);
+ git_str_clear(out);
if (slash)
- git_buf_put(out, in, slash - in);
+ git_str_put(out, in, slash - in);
return !!slash;
}
-static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *popped, git_buf *component)
+static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *popped, git_str *component)
{
int error;
git_oid new_tree;
@@ -1116,8 +1116,8 @@ static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *poppe
}
/* We've written out the tree, now we have to put the new value into its parent */
- git_buf_clear(component);
- git_buf_puts(component, popped->name);
+ git_str_clear(component);
+ git_str_puts(component, popped->name);
git__free(popped->name);
GIT_ERROR_CHECK_ALLOC(component->ptr);
@@ -1142,7 +1142,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli
git_vector entries;
int error;
size_t i;
- git_buf component = GIT_BUF_INIT;
+ git_str component = GIT_STR_INIT;
if ((error = git_vector_init(&entries, nupdates, compare_entries)) < 0)
return error;
@@ -1300,7 +1300,7 @@ cleanup:
}
}
- git_buf_dispose(&component);
+ git_str_dispose(&component);
git_array_clear(stack);
git_vector_free(&entries);
return error;
diff --git a/src/tree.h b/src/tree.h
index 2f3027b5a..6bd9ed652 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -32,7 +32,7 @@ struct git_tree {
struct git_treebuilder {
git_repository *repo;
git_strmap *map;
- git_buf write_cache;
+ git_str write_cache;
};
GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
diff --git a/src/util.c b/src/util.c
index 9b0c45ce8..2b1dadfe8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -735,13 +735,13 @@ void git__qsort_r(
}
#ifdef GIT_WIN32
-int git__getenv(git_buf *out, const char *name)
+int git__getenv(git_str *out, const char *name)
{
wchar_t *wide_name = NULL, *wide_value = NULL;
DWORD value_len;
int error = -1;
- git_buf_clear(out);
+ git_str_clear(out);
if (git__utf8_to_16_alloc(&wide_name, name) < 0)
return -1;
@@ -754,7 +754,7 @@ int git__getenv(git_buf *out, const char *name)
}
if (value_len)
- error = git_buf_put_w(out, wide_value, value_len);
+ error = git_str_put_w(out, wide_value, value_len);
else if (GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_ENVVAR_NOT_FOUND)
error = GIT_ENOTFOUND;
else
@@ -765,16 +765,16 @@ int git__getenv(git_buf *out, const char *name)
return error;
}
#else
-int git__getenv(git_buf *out, const char *name)
+int git__getenv(git_str *out, const char *name)
{
const char *val = getenv(name);
- git_buf_clear(out);
+ git_str_clear(out);
if (!val)
return GIT_ENOTFOUND;
- return git_buf_puts(out, val);
+ return git_str_puts(out, val);
}
#endif
diff --git a/src/util.h b/src/util.h
index e8074fcb9..30cdd0ddf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -7,15 +7,11 @@
#ifndef INCLUDE_util_h__
#define INCLUDE_util_h__
-#include "common.h"
-
#ifndef GIT_WIN32
# include <ctype.h>
#endif
-#include "git2/buffer.h"
-
-#include "buffer.h"
+#include "str.h"
#include "common.h"
#include "strnlen.h"
#include "thread.h"
@@ -402,7 +398,7 @@ GIT_INLINE(double) git__timer(void)
#endif
-extern int git__getenv(git_buf *out, const char *name);
+extern int git__getenv(git_str *out, const char *name);
extern int git__online_cpus(void);
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index 40d2d518a..caa79398a 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -34,7 +34,7 @@ static int git_win32__expand_path(_findfile_path *dest, const wchar_t *src)
return 0;
}
-static int win32_path_to_8(git_buf *dest, const wchar_t *src)
+static int win32_path_to_8(git_str *dest, const wchar_t *src)
{
git_win32_utf8_path utf8_path;
@@ -46,7 +46,7 @@ static int win32_path_to_8(git_buf *dest, const wchar_t *src)
/* Convert backslashes to forward slashes */
git_path_mkposix(utf8_path);
- return git_buf_sets(dest, utf8_path);
+ return git_str_sets(dest, utf8_path);
}
static wchar_t *win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
@@ -70,7 +70,7 @@ static wchar_t *win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
return (path != base) ? path : NULL;
}
-static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wchar_t *subdir)
+static int win32_find_git_in_path(git_str *buf, const wchar_t *gitexe, const wchar_t *subdir)
{
wchar_t *env = _wgetenv(L"PATH"), lastch;
_findfile_path root;
@@ -106,7 +106,7 @@ static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wch
}
static int win32_find_git_in_registry(
- git_buf *buf, const HKEY hive, const wchar_t *key, const wchar_t *subdir)
+ git_str *buf, const HKEY hive, const wchar_t *key, const wchar_t *subdir)
{
HKEY hKey;
int error = GIT_ENOTFOUND;
@@ -141,12 +141,12 @@ static int win32_find_git_in_registry(
}
static int win32_find_existing_dirs(
- git_buf *out, const wchar_t *tmpl[])
+ git_str *out, const wchar_t *tmpl[])
{
_findfile_path path16;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_clear(out);
+ git_str_clear(out);
for (; *tmpl != NULL; tmpl++) {
if (!git_win32__expand_path(&path16, *tmpl) &&
@@ -156,43 +156,43 @@ static int win32_find_existing_dirs(
win32_path_to_8(&buf, path16.path);
if (buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
-int git_win32__find_system_dirs(git_buf *out, const wchar_t *subdir)
+int git_win32__find_system_dirs(git_str *out, const wchar_t *subdir)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* directories where git.exe & git.cmd are found */
if (!win32_find_git_in_path(&buf, L"git.exe", subdir) && buf.size)
- git_buf_set(out, buf.ptr, buf.size);
+ git_str_set(out, buf.ptr, buf.size);
else
- git_buf_clear(out);
+ git_str_clear(out);
if (!win32_find_git_in_path(&buf, L"git.cmd", subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
/* directories where git is installed according to registry */
if (!win32_find_git_in_registry(
&buf, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL, subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
if (!win32_find_git_in_registry(
&buf, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
-int git_win32__find_global_dirs(git_buf *out)
+int git_win32__find_global_dirs(git_str *out)
{
static const wchar_t *global_tmpls[4] = {
L"%HOME%\\",
@@ -204,7 +204,7 @@ int git_win32__find_global_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
-int git_win32__find_xdg_dirs(git_buf *out)
+int git_win32__find_xdg_dirs(git_str *out)
{
static const wchar_t *global_tmpls[7] = {
L"%XDG_CONFIG_HOME%\\git",
@@ -219,7 +219,7 @@ int git_win32__find_xdg_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
-int git_win32__find_programdata_dirs(git_buf *out)
+int git_win32__find_programdata_dirs(git_str *out)
{
static const wchar_t *programdata_tmpls[2] = {
L"%PROGRAMDATA%\\Git",
diff --git a/src/win32/findfile.h b/src/win32/findfile.h
index e7bcf948a..e11ccebc5 100644
--- a/src/win32/findfile.h
+++ b/src/win32/findfile.h
@@ -10,10 +10,10 @@
#include "common.h"
-extern int git_win32__find_system_dirs(git_buf *out, const wchar_t *subpath);
-extern int git_win32__find_global_dirs(git_buf *out);
-extern int git_win32__find_xdg_dirs(git_buf *out);
-extern int git_win32__find_programdata_dirs(git_buf *out);
+extern int git_win32__find_system_dirs(git_str *out, const wchar_t *subpath);
+extern int git_win32__find_global_dirs(git_str *out);
+extern int git_win32__find_xdg_dirs(git_str *out);
+extern int git_win32__find_programdata_dirs(git_str *out);
#endif
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 8af07e6fa..f26983d97 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -14,7 +14,6 @@
#include "utf-conv.h"
#include "repository.h"
#include "reparse.h"
-#include "buffer.h"
#include <errno.h>
#include <io.h>
#include <fcntl.h>
@@ -415,7 +414,7 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
static bool target_is_dir(const char *target, const char *path)
{
- git_buf resolved = GIT_BUF_INIT;
+ git_str resolved = GIT_STR_INIT;
git_win32_path resolved_w;
bool isdir = true;
@@ -429,7 +428,7 @@ static bool target_is_dir(const char *target, const char *path)
isdir = GetFileAttributesW(resolved_w) & FILE_ATTRIBUTE_DIRECTORY;
out:
- git_buf_dispose(&resolved);
+ git_str_dispose(&resolved);
return isdir;
}
@@ -1003,7 +1002,7 @@ ssize_t p_pread(int fd, void *data, size_t size, off64_t offset)
/* Fail if the final offset would have overflowed to match POSIX semantics. */
if (!git__is_ssizet(size) || git__add_int64_overflow(&final_offset, offset, (int64_t)size)) {
errno = EINVAL;
- return -1;
+ return -1;
}
/*
@@ -1038,7 +1037,7 @@ ssize_t p_pwrite(int fd, const void *data, size_t size, off64_t offset)
/* Fail if the final offset would have overflowed to match POSIX semantics. */
if (!git__is_ssizet(size) || git__add_int64_overflow(&final_offset, offset, (int64_t)size)) {
errno = EINVAL;
- return -1;
+ return -1;
}
/*
diff --git a/src/win32/w32_buffer.c b/src/win32/w32_buffer.c
index f270a1e6a..6fee8203c 100644
--- a/src/win32/w32_buffer.c
+++ b/src/win32/w32_buffer.c
@@ -7,7 +7,6 @@
#include "w32_buffer.h"
-#include "../buffer.h"
#include "utf-conv.h"
GIT_INLINE(int) handle_wc_error(void)
@@ -20,7 +19,7 @@ GIT_INLINE(int) handle_wc_error(void)
return -1;
}
-int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
+int git_str_put_w(git_str *buf, const wchar_t *string_w, size_t len_w)
{
int utf8_len, utf8_write_len;
size_t new_size;
@@ -43,7 +42,7 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
- if (git_buf_grow(buf, new_size) < 0)
+ if (git_str_grow(buf, new_size) < 0)
return -1;
if ((utf8_write_len = WideCharToMultiByte(
diff --git a/src/win32/w32_buffer.h b/src/win32/w32_buffer.h
index 43298e4a7..4227296d8 100644
--- a/src/win32/w32_buffer.h
+++ b/src/win32/w32_buffer.h
@@ -8,13 +8,12 @@
#define INCLUDE_win32_w32_buffer_h__
#include "common.h"
-
-#include "../buffer.h"
+#include "str.h"
/**
* Convert a wide character string to UTF-8 and append the results to the
* buffer.
*/
-int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w);
+int git_str_put_w(git_str *buf, const wchar_t *string_w, size_t len_w);
#endif
diff --git a/src/worktree.c b/src/worktree.c
index fe8db7743..92a0900b0 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -7,32 +7,33 @@
#include "worktree.h"
+#include "buf.h"
+#include "repository.h"
+
#include "git2/branch.h"
#include "git2/commit.h"
#include "git2/worktree.h"
-#include "repository.h"
-
static bool is_worktree_dir(const char *dir)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error;
- if (git_buf_sets(&buf, dir) < 0)
+ if (git_str_sets(&buf, dir) < 0)
return -1;
error = git_path_contains_file(&buf, "commondir")
&& git_path_contains_file(&buf, "gitdir")
&& git_path_contains_file(&buf, "HEAD");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
int git_worktree_list(git_strarray *wts, git_repository *repo)
{
git_vector worktrees = GIT_VECTOR_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *worktree;
size_t i, len;
int error;
@@ -43,7 +44,7 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
wts->count = 0;
wts->strings = NULL;
- if ((error = git_buf_joinpath(&path, repo->commondir, "worktrees/")) < 0)
+ if ((error = git_str_joinpath(&path, repo->commondir, "worktrees/")) < 0)
goto exit;
if (!git_path_exists(path.ptr) || git_path_is_empty_dir(path.ptr))
goto exit;
@@ -53,8 +54,8 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
len = path.size;
git_vector_foreach(&worktrees, i, worktree) {
- git_buf_truncate(&path, len);
- git_buf_puts(&path, worktree);
+ git_str_truncate(&path, len);
+ git_str_puts(&path, worktree);
if (!is_worktree_dir(path.ptr)) {
git_vector_remove(&worktrees, i);
@@ -65,68 +66,68 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
wts->strings = (char **)git_vector_detach(&wts->count, NULL, &worktrees);
exit:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
char *git_worktree__read_link(const char *base, const char *file)
{
- git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, buf = GIT_STR_INIT;
GIT_ASSERT_ARG_WITH_RETVAL(base, NULL);
GIT_ASSERT_ARG_WITH_RETVAL(file, NULL);
- if (git_buf_joinpath(&path, base, file) < 0)
+ if (git_str_joinpath(&path, base, file) < 0)
goto err;
if (git_futils_readbuffer(&buf, path.ptr) < 0)
goto err;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
- git_buf_rtrim(&buf);
+ git_str_rtrim(&buf);
if (!git_path_is_relative(buf.ptr))
- return git_buf_detach(&buf);
+ return git_str_detach(&buf);
- if (git_buf_sets(&path, base) < 0)
+ if (git_str_sets(&path, base) < 0)
goto err;
if (git_path_apply_relative(&path, buf.ptr) < 0)
goto err;
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return git_buf_detach(&path);
+ return git_str_detach(&path);
err:
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
return NULL;
}
-static int write_wtfile(const char *base, const char *file, const git_buf *buf)
+static int write_wtfile(const char *base, const char *file, const git_str *buf)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int err;
GIT_ASSERT_ARG(base);
GIT_ASSERT_ARG(file);
GIT_ASSERT_ARG(buf);
- if ((err = git_buf_joinpath(&path, base, file)) < 0)
+ if ((err = git_str_joinpath(&path, base, file)) < 0)
goto out;
if ((err = git_futils_writebuffer(buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
goto out;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return err;
}
static int open_worktree_dir(git_worktree **out, const char *parent, const char *dir, const char *name)
{
- git_buf gitdir = GIT_BUF_INIT;
+ git_str gitdir = GIT_STR_INIT;
git_worktree *wt = NULL;
int error = 0;
@@ -154,7 +155,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
if ((error = git_path_prettify_dir(&gitdir, dir, NULL)) < 0)
goto out;
- wt->gitdir_path = git_buf_detach(&gitdir);
+ wt->gitdir_path = git_str_detach(&gitdir);
if ((error = git_worktree_is_locked(NULL, wt)) < 0)
goto out;
@@ -166,14 +167,14 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
out:
if (error)
git_worktree_free(wt);
- git_buf_dispose(&gitdir);
+ git_str_dispose(&gitdir);
return error;
}
int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *name)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree *wt = NULL;
int error;
@@ -182,14 +183,14 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
*out = NULL;
- if ((error = git_buf_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
+ if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
goto out;
if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0)
goto out;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if (error)
git_worktree_free(wt);
@@ -199,7 +200,7 @@ out:
int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
{
- git_buf parent = GIT_BUF_INIT;
+ git_str parent = GIT_STR_INIT;
const char *gitdir, *commondir;
char *name = NULL;
int error = 0;
@@ -224,7 +225,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
out:
git__free(name);
- git_buf_dispose(&parent);
+ git_str_dispose(&parent);
return error;
}
@@ -298,7 +299,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
const char *name, const char *worktree,
const git_worktree_add_options *opts)
{
- git_buf gitdir = GIT_BUF_INIT, wddir = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str gitdir = GIT_STR_INIT, wddir = GIT_STR_INIT, buf = GIT_STR_INIT;
git_reference *ref = NULL, *head = NULL;
git_commit *commit = NULL;
git_repository *wt = NULL;
@@ -334,12 +335,12 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
}
/* Create gitdir directory ".git/worktrees/<name>" */
- if ((err = git_buf_joinpath(&gitdir, repo->commondir, "worktrees")) < 0)
+ if ((err = git_str_joinpath(&gitdir, repo->commondir, "worktrees")) < 0)
goto out;
if (!git_path_exists(gitdir.ptr))
if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
goto out;
- if ((err = git_buf_joinpath(&gitdir, gitdir.ptr, name)) < 0)
+ if ((err = git_str_joinpath(&gitdir, gitdir.ptr, name)) < 0)
goto out;
if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
goto out;
@@ -355,7 +356,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
if (wtopts.lock) {
int fd;
- if ((err = git_buf_joinpath(&buf, gitdir.ptr, "locked")) < 0)
+ if ((err = git_str_joinpath(&buf, gitdir.ptr, "locked")) < 0)
goto out;
if ((fd = p_creat(buf.ptr, 0644)) < 0) {
@@ -364,22 +365,22 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
}
p_close(fd);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
}
/* Create worktree .git file */
- if ((err = git_buf_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0)
+ if ((err = git_str_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0)
goto out;
if ((err = write_wtfile(wddir.ptr, ".git", &buf)) < 0)
goto out;
/* Create gitdir files */
if ((err = git_path_prettify_dir(&buf, repo->commondir, NULL) < 0)
- || (err = git_buf_putc(&buf, '\n')) < 0
+ || (err = git_str_putc(&buf, '\n')) < 0
|| (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0)
goto out;
- if ((err = git_buf_joinpath(&buf, wddir.ptr, ".git")) < 0
- || (err = git_buf_putc(&buf, '\n')) < 0
+ if ((err = git_str_joinpath(&buf, wddir.ptr, ".git")) < 0
+ || (err = git_str_putc(&buf, '\n')) < 0
|| (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0)
goto out;
@@ -412,9 +413,9 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
goto out;
out:
- git_buf_dispose(&gitdir);
- git_buf_dispose(&wddir);
- git_buf_dispose(&buf);
+ git_str_dispose(&gitdir);
+ git_str_dispose(&wddir);
+ git_str_dispose(&buf);
git_reference_free(ref);
git_reference_free(head);
git_commit_free(commit);
@@ -425,7 +426,7 @@ out:
int git_worktree_lock(git_worktree *wt, const char *reason)
{
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(wt);
@@ -437,11 +438,11 @@ int git_worktree_lock(git_worktree *wt, const char *reason)
goto out;
}
- if ((error = git_buf_joinpath(&path, wt->gitdir_path, "locked")) < 0)
+ if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
goto out;
if (reason)
- git_buf_attach_notowned(&buf, reason, strlen(reason));
+ git_str_attach_notowned(&buf, reason, strlen(reason));
if ((error = git_futils_writebuffer(&buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
goto out;
@@ -449,14 +450,14 @@ int git_worktree_lock(git_worktree *wt, const char *reason)
wt->locked = 1;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
int git_worktree_unlock(git_worktree *wt)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
GIT_ASSERT_ARG(wt);
@@ -466,32 +467,32 @@ int git_worktree_unlock(git_worktree *wt)
if (!error)
return 1;
- if (git_buf_joinpath(&path, wt->gitdir_path, "locked") < 0)
+ if (git_str_joinpath(&path, wt->gitdir_path, "locked") < 0)
return -1;
if (p_unlink(path.ptr) != 0) {
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return -1;
}
wt->locked = 0;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
-int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
+static int git_worktree__is_locked(git_str *reason, const git_worktree *wt)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error, locked;
GIT_ASSERT_ARG(wt);
if (reason)
- git_buf_clear(reason);
+ git_str_clear(reason);
- if ((error = git_buf_joinpath(&path, wt->gitdir_path, "locked")) < 0)
+ if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
goto out;
locked = git_path_exists(path.ptr);
if (locked && reason &&
@@ -500,8 +501,27 @@ int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
error = locked;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
+
+ return error;
+}
+
+int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
+{
+ git_str str = GIT_STR_INIT;
+ int error = 0;
+
+ if (reason && (error = git_buf_tostr(&str, reason)) < 0)
+ return error;
+
+ error = git_worktree__is_locked(reason ? &str : NULL, wt);
+
+ if (error >= 0 && reason) {
+ if (git_buf_fromstr(reason, &str) < 0)
+ error = -1;
+ }
+ git_str_dispose(&str);
return error;
}
@@ -547,17 +567,17 @@ int git_worktree_is_prunable(git_worktree *wt,
memcpy(&popts, opts, sizeof(popts));
if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0) {
- git_buf reason = GIT_BUF_INIT;
+ git_str reason = GIT_STR_INIT;
int error;
- if ((error = git_worktree_is_locked(&reason, wt)) < 0)
+ if ((error = git_worktree__is_locked(&reason, wt)) < 0)
return error;
if (error) {
if (!reason.size)
- git_buf_attach_notowned(&reason, "no reason given", 15);
+ git_str_attach_notowned(&reason, "no reason given", 15);
git_error_set(GIT_ERROR_WORKTREE, "not pruning locked working tree: '%s'", reason.ptr);
- git_buf_dispose(&reason);
+ git_str_dispose(&reason);
return 0;
}
}
@@ -575,7 +595,7 @@ int git_worktree_prune(git_worktree *wt,
git_worktree_prune_options *opts)
{
git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *wtpath;
int err;
@@ -592,7 +612,7 @@ int git_worktree_prune(git_worktree *wt,
}
/* Delete gitdir in parent repository */
- if ((err = git_buf_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
+ if ((err = git_str_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
goto out;
if (!git_path_exists(path.ptr))
{
@@ -613,7 +633,7 @@ int git_worktree_prune(git_worktree *wt,
if ((wtpath = git_path_dirname(wt->gitlink_path)) == NULL)
goto out;
- git_buf_attach(&path, wtpath, 0);
+ git_str_attach(&path, wtpath, 0);
if (!git_path_exists(path.ptr))
{
git_error_set(GIT_ERROR_WORKTREE, "working tree '%s' does not exist", path.ptr);
@@ -624,7 +644,7 @@ int git_worktree_prune(git_worktree *wt,
goto out;
out:
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return err;
}
diff --git a/src/zstream.c b/src/zstream.c
index a5675676e..cb8b125ed 100644
--- a/src/zstream.c
+++ b/src/zstream.c
@@ -9,7 +9,7 @@
#include <zlib.h>
-#include "buffer.h"
+#include "str.h"
#define ZSTREAM_BUFFER_SIZE (1024 * 1024)
#define ZSTREAM_BUFFER_MIN_EXTRA 8
@@ -164,7 +164,7 @@ int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream)
return 0;
}
-static int zstream_buf(git_buf *out, const void *in, size_t in_len, git_zstream_t type)
+static int zstream_buf(git_str *out, const void *in, size_t in_len, git_zstream_t type)
{
git_zstream zs = GIT_ZSTREAM_INIT;
int error = 0;
@@ -178,7 +178,7 @@ static int zstream_buf(git_buf *out, const void *in, size_t in_len, git_zstream_
while (!git_zstream_done(&zs)) {
size_t step = git_zstream_suggest_output_len(&zs), written;
- if ((error = git_buf_grow_by(out, step)) < 0)
+ if ((error = git_str_grow_by(out, step)) < 0)
goto done;
written = out->asize - out->size;
@@ -199,12 +199,12 @@ done:
return error;
}
-int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
+int git_zstream_deflatebuf(git_str *out, const void *in, size_t in_len)
{
return zstream_buf(out, in, in_len, GIT_ZSTREAM_DEFLATE);
}
-int git_zstream_inflatebuf(git_buf *out, const void *in, size_t in_len)
+int git_zstream_inflatebuf(git_str *out, const void *in, size_t in_len)
{
return zstream_buf(out, in, in_len, GIT_ZSTREAM_INFLATE);
}
diff --git a/src/zstream.h b/src/zstream.h
index db0cc477c..3a59d9a36 100644
--- a/src/zstream.h
+++ b/src/zstream.h
@@ -11,7 +11,7 @@
#include <zlib.h>
-#include "buffer.h"
+#include "str.h"
typedef enum {
GIT_ZSTREAM_INFLATE,
@@ -48,7 +48,7 @@ bool git_zstream_eos(git_zstream *zstream);
void git_zstream_reset(git_zstream *zstream);
-int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len);
-int git_zstream_inflatebuf(git_buf *out, const void *in, size_t in_len);
+int git_zstream_deflatebuf(git_str *out, const void *in, size_t in_len);
+int git_zstream_inflatebuf(git_str *out, const void *in, size_t in_len);
#endif