summaryrefslogtreecommitdiff
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
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-ethomson/gitstr.tar.gz
str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstr
libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
-rw-r--r--examples/diff.c2
-rw-r--r--fuzzers/commit_graph_fuzzer.c14
-rw-r--r--fuzzers/midx_fuzzer.c11
-rw-r--r--fuzzers/packfile_fuzzer.c16
-rw-r--r--fuzzers/standalone_driver.c4
-rw-r--r--include/git2/buffer.h96
-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
-rw-r--r--tests/apply/fromdiff.c26
-rw-r--r--tests/apply/fromfile.c8
-rw-r--r--tests/apply/partial.c8
-rw-r--r--tests/attr/repo.c26
-rw-r--r--tests/buf/basic.c51
-rw-r--r--tests/buf/splice.c93
-rw-r--r--tests/checkout/checkout_helpers.c6
-rw-r--r--tests/checkout/checkout_helpers.h1
-rw-r--r--tests/checkout/conflict.c38
-rw-r--r--tests/checkout/crlf.c84
-rw-r--r--tests/checkout/icase.c8
-rw-r--r--tests/checkout/index.c18
-rw-r--r--tests/checkout/nasty.c13
-rw-r--r--tests/checkout/tree.c23
-rw-r--r--tests/checkout/typechange.c22
-rw-r--r--tests/cherrypick/bare.c1
-rw-r--r--tests/cherrypick/workdir.c19
-rw-r--r--tests/clar_libgit2.c74
-rw-r--r--tests/clar_libgit2_timer.c1
-rw-r--r--tests/clone/local.c57
-rw-r--r--tests/clone/nonetwork.c14
-rw-r--r--tests/commit/parse.c18
-rw-r--r--tests/config/conditionals.c34
-rw-r--r--tests/config/config_helpers.c5
-rw-r--r--tests/config/configlevel.c2
-rw-r--r--tests/config/global.c19
-rw-r--r--tests/config/include.c45
-rw-r--r--tests/config/new.c6
-rw-r--r--tests/config/read.c55
-rw-r--r--tests/config/stress.c4
-rw-r--r--tests/config/write.c49
-rw-r--r--tests/core/buf.c54
-rw-r--r--tests/core/dirent.c18
-rw-r--r--tests/core/env.c50
-rw-r--r--tests/core/filebuf.c10
-rw-r--r--tests/core/futils.c28
-rw-r--r--tests/core/gitstr.c (renamed from tests/core/buffer.c)793
-rw-r--r--tests/core/link.c119
-rw-r--r--tests/core/mkdir.c20
-rw-r--r--tests/core/path.c106
-rw-r--r--tests/core/posix.c12
-rw-r--r--tests/core/rmdir.c66
-rw-r--r--tests/core/sortedcache.c4
-rw-r--r--tests/core/stat.c6
-rw-r--r--tests/core/useragent.c4
-rw-r--r--tests/core/zstream.c35
-rw-r--r--tests/describe/describe.c4
-rw-r--r--tests/describe/describe_helpers.c4
-rw-r--r--tests/describe/describe_helpers.h1
-rw-r--r--tests/diff/binary.c35
-rw-r--r--tests/diff/blob.c16
-rw-r--r--tests/diff/drivers.c19
-rw-r--r--tests/diff/format_email.c9
-rw-r--r--tests/diff/parse.c14
-rw-r--r--tests/diff/patch.c50
-rw-r--r--tests/diff/rename.c70
-rw-r--r--tests/diff/stats.c37
-rw-r--r--tests/diff/submodules.c2
-rw-r--r--tests/diff/workdir.c29
-rw-r--r--tests/email/create.c17
-rw-r--r--tests/fetchhead/nonetwork.c16
-rw-r--r--tests/filter/crlf.c1
-rw-r--r--tests/filter/custom_helpers.c12
-rw-r--r--tests/filter/custom_helpers.h8
-rw-r--r--tests/filter/file.c7
-rw-r--r--tests/filter/query.c1
-rw-r--r--tests/filter/stream.c6
-rw-r--r--tests/filter/systemattrs.c14
-rw-r--r--tests/filter/wildcard.c4
-rw-r--r--tests/graph/commit_graph.c37
-rw-r--r--tests/graph/reachable_from_any.c10
-rw-r--r--tests/ignore/status.c8
-rw-r--r--tests/index/crlf.c84
-rw-r--r--tests/index/filemodes.c11
-rw-r--r--tests/index/nsec.c6
-rw-r--r--tests/index/racy.c25
-rw-r--r--tests/index/tests.c30
-rw-r--r--tests/iterator/index.c18
-rw-r--r--tests/iterator/tree.c6
-rw-r--r--tests/iterator/workdir.c18
-rw-r--r--tests/mailmap/parsing.c10
-rw-r--r--tests/merge/analysis.c24
-rw-r--r--tests/merge/driver.c28
-rw-r--r--tests/merge/files.c1
-rw-r--r--tests/merge/merge_helpers.c32
-rw-r--r--tests/merge/trees/automerge.c1
-rw-r--r--tests/merge/trees/modeconflict.c1
-rw-r--r--tests/merge/trees/renames.c9
-rw-r--r--tests/merge/trees/trivial.c10
-rw-r--r--tests/merge/trees/whitespace.c1
-rw-r--r--tests/merge/workdir/dirty.c31
-rw-r--r--tests/merge/workdir/recursive.c8
-rw-r--r--tests/merge/workdir/renames.c1
-rw-r--r--tests/merge/workdir/setup.c58
-rw-r--r--tests/merge/workdir/simple.c37
-rw-r--r--tests/merge/workdir/submodules.c1
-rw-r--r--tests/merge/workdir/trivial.c10
-rw-r--r--tests/message/trailer.c1
-rw-r--r--tests/network/fetchlocal.c1
-rw-r--r--tests/network/remote/defaultbranch.c1
-rw-r--r--tests/network/remote/local.c17
-rw-r--r--tests/network/remote/remotes.c41
-rw-r--r--tests/notes/notes.c4
-rw-r--r--tests/notes/notesref.c3
-rw-r--r--tests/object/blob/filter.c18
-rw-r--r--tests/object/blob/fromstream.c13
-rw-r--r--tests/object/blob/write.c17
-rw-r--r--tests/object/commit/commitstagedfile.c3
-rw-r--r--tests/object/lookup.c18
-rw-r--r--tests/object/message.c4
-rw-r--r--tests/object/raw/hash.c2
-rw-r--r--tests/object/tree/write.c6
-rw-r--r--tests/odb/alternates.c20
-rw-r--r--tests/odb/foreach.c7
-rw-r--r--tests/odb/freshen.c10
-rw-r--r--tests/odb/largefiles.c10
-rw-r--r--tests/online/clone.c46
-rw-r--r--tests/online/customcert.c10
-rw-r--r--tests/online/fetch.c6
-rw-r--r--tests/online/fetchhead.c8
-rw-r--r--tests/online/push.c43
-rw-r--r--tests/online/push_util.c24
-rw-r--r--tests/pack/filelimit.c18
-rw-r--r--tests/pack/indexer.c26
-rw-r--r--tests/pack/midx.c51
-rw-r--r--tests/pack/packbuilder.c10
-rw-r--r--tests/patch/parse.c12
-rw-r--r--tests/path/core.c14
-rw-r--r--tests/rebase/sign.c14
-rw-r--r--tests/rebase/submodule.c8
-rw-r--r--tests/refs/basic.c10
-rw-r--r--tests/refs/branches/create.c8
-rw-r--r--tests/refs/branches/delete.c20
-rw-r--r--tests/refs/branches/move.c25
-rw-r--r--tests/refs/branches/remote.c9
-rw-r--r--tests/refs/branches/upstreamname.c5
-rw-r--r--tests/refs/delete.c6
-rw-r--r--tests/refs/pack.c14
-rw-r--r--tests/refs/read.c6
-rw-r--r--tests/refs/ref_helpers.c7
-rw-r--r--tests/refs/reflog/messages.c8
-rw-r--r--tests/refs/reflog/reflog.c86
-rw-r--r--tests/refs/reflog/reflog_helpers.c32
-rw-r--r--tests/refs/rename.c22
-rw-r--r--tests/refs/revparse.c21
-rw-r--r--tests/remote/fetch.c16
-rw-r--r--tests/repo/config.c12
-rw-r--r--tests/repo/discover.c26
-rw-r--r--tests/repo/env.c20
-rw-r--r--tests/repo/hashfile.c35
-rw-r--r--tests/repo/init.c70
-rw-r--r--tests/repo/message.c14
-rw-r--r--tests/repo/open.c60
-rw-r--r--tests/repo/repo_helpers.c14
-rw-r--r--tests/repo/reservedname.c14
-rw-r--r--tests/repo/setters.c15
-rw-r--r--tests/repo/state.c11
-rw-r--r--tests/repo/template.c58
-rw-r--r--tests/reset/hard.c62
-rw-r--r--tests/reset/mixed.c12
-rw-r--r--tests/reset/soft.c18
-rw-r--r--tests/revert/bare.c1
-rw-r--r--tests/revert/workdir.c11
-rw-r--r--tests/stash/apply.c8
-rw-r--r--tests/stash/save.c8
-rw-r--r--tests/status/renames.c11
-rw-r--r--tests/status/worktree.c84
-rw-r--r--tests/str/basic.c50
-rw-r--r--tests/str/oom.c (renamed from tests/buf/oom.c)31
-rw-r--r--tests/str/percent.c (renamed from tests/buf/percent.c)21
-rw-r--r--tests/str/quote.c (renamed from tests/buf/quote.c)39
-rw-r--r--tests/str/splice.c92
-rw-r--r--tests/stress/diff.c12
-rw-r--r--tests/submodule/add.c22
-rw-r--r--tests/submodule/escape.c12
-rw-r--r--tests/submodule/init.c18
-rw-r--r--tests/submodule/inject_option.c12
-rw-r--r--tests/submodule/lookup.c12
-rw-r--r--tests/submodule/modify.c6
-rw-r--r--tests/submodule/nosubs.c4
-rw-r--r--tests/submodule/open.c34
-rw-r--r--tests/submodule/repository_init.c4
-rw-r--r--tests/submodule/status.c6
-rw-r--r--tests/submodule/submodule_helpers.c39
-rw-r--r--tests/valgrind-supp-mac.txt6
-rw-r--r--tests/win32/forbidden.c1
-rw-r--r--tests/win32/longpath.c21
-rw-r--r--tests/worktree/merge.c14
-rw-r--r--tests/worktree/open.c10
-rw-r--r--tests/worktree/refs.c6
-rw-r--r--tests/worktree/submodule.c6
-rw-r--r--tests/worktree/worktree.c102
346 files changed, 6759 insertions, 6308 deletions
diff --git a/examples/diff.c b/examples/diff.c
index 2305c8652..a9fb5d442 100644
--- a/examples/diff.c
+++ b/examples/diff.c
@@ -344,7 +344,7 @@ static void parse_opts(struct diff_options *o, int argc, char *argv[])
static void diff_print_stats(git_diff *diff, struct diff_options *o)
{
git_diff_stats *stats;
- git_buf b = GIT_BUF_INIT_CONST(NULL, 0);
+ git_buf b = GIT_BUF_INIT;
git_diff_stats_format_t format = 0;
check_lg2(
diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c
index 39b520882..05783a259 100644
--- a/fuzzers/commit_graph_fuzzer.c
+++ b/fuzzers/commit_graph_fuzzer.c
@@ -11,8 +11,8 @@
#include "git2.h"
-#include "buffer.h"
#include "common.h"
+#include "str.h"
#include "futils.h"
#include "hash.h"
#include "commit_graph.h"
@@ -33,7 +33,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_commit_graph_file file = {{0}};
git_commit_graph_entry e;
- git_buf commit_graph_buf = GIT_BUF_INIT;
+ git_str commit_graph_buf = GIT_STR_INIT;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -51,7 +51,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4;
if (append_hash) {
- if (git_buf_init(&commit_graph_buf, size + GIT_HASH_SHA1_SIZE) < 0)
+ if (git_str_init(&commit_graph_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup;
if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
@@ -62,13 +62,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else {
- git_buf_attach_notowned(&commit_graph_buf, (char *)data, size);
+ git_str_attach_notowned(&commit_graph_buf, (char *)data, size);
}
if (git_commit_graph_file_parse(
&file,
- (const unsigned char *)git_buf_cstr(&commit_graph_buf),
- git_buf_len(&commit_graph_buf))
+ (const unsigned char *)git_str_cstr(&commit_graph_buf),
+ git_str_len(&commit_graph_buf))
< 0)
goto cleanup;
@@ -78,6 +78,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup:
git_commit_graph_file_close(&file);
- git_buf_dispose(&commit_graph_buf);
+ git_str_dispose(&commit_graph_buf);
return 0;
}
diff --git a/fuzzers/midx_fuzzer.c b/fuzzers/midx_fuzzer.c
index 9739f0a40..3cd609063 100644
--- a/fuzzers/midx_fuzzer.c
+++ b/fuzzers/midx_fuzzer.c
@@ -11,7 +11,6 @@
#include "git2.h"
-#include "buffer.h"
#include "common.h"
#include "futils.h"
#include "hash.h"
@@ -33,7 +32,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_midx_file idx = {{0}};
git_midx_entry e;
- git_buf midx_buf = GIT_BUF_INIT;
+ git_str midx_buf = GIT_STR_INIT;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}};
bool append_hash = false;
@@ -51,7 +50,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4;
if (append_hash) {
- if (git_buf_init(&midx_buf, size + GIT_HASH_SHA1_SIZE) < 0)
+ if (git_str_init(&midx_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup;
if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
@@ -62,10 +61,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else {
- git_buf_attach_notowned(&midx_buf, (char *)data, size);
+ git_str_attach_notowned(&midx_buf, (char *)data, size);
}
- if (git_midx_parse(&idx, (const unsigned char *)git_buf_cstr(&midx_buf), git_buf_len(&midx_buf)) < 0)
+ if (git_midx_parse(&idx, (const unsigned char *)git_str_cstr(&midx_buf), git_str_len(&midx_buf)) < 0)
goto cleanup;
/* Search for any oid, just to exercise that codepath. */
@@ -74,6 +73,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup:
git_midx_close(&idx);
- git_buf_dispose(&midx_buf);
+ git_str_dispose(&midx_buf);
return 0;
}
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c
index 50c115755..f739b9563 100644
--- a/fuzzers/packfile_fuzzer.c
+++ b/fuzzers/packfile_fuzzer.c
@@ -12,7 +12,7 @@
#include "git2.h"
#include "git2/sys/mempack.h"
#include "common.h"
-#include "buffer.h"
+#include "str.h"
static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL;
@@ -53,7 +53,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_indexer_progress stats = {0, 0};
git_indexer *indexer = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_oid oid;
bool append_hash = false;
@@ -99,19 +99,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_commit(indexer, &stats) < 0)
goto cleanup;
- if (git_buf_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
+ if (git_str_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
goto cleanup;
- p_unlink(git_buf_cstr(&path));
+ p_unlink(git_str_cstr(&path));
- git_buf_clear(&path);
+ git_str_clear(&path);
- if (git_buf_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
+ if (git_str_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
goto cleanup;
- p_unlink(git_buf_cstr(&path));
+ p_unlink(git_str_cstr(&path));
cleanup:
git_mempack_reset(mempack);
git_indexer_free(indexer);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c
index 90e701333..88c8cfbda 100644
--- a/fuzzers/standalone_driver.c
+++ b/fuzzers/standalone_driver.c
@@ -16,7 +16,7 @@ extern int LLVMFuzzerInitialize(int *argc, char ***argv);
static int run_one_file(const char *filename)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error = 0;
if (git_futils_readbuffer(&buf, filename) < 0) {
@@ -27,7 +27,7 @@ static int run_one_file(const char *filename)
LLVMFuzzerTestOneInput((const unsigned char *)buf.ptr, buf.size);
exit:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
diff --git a/include/git2/buffer.h b/include/git2/buffer.h
index 926f1332d..9fa972034 100644
--- a/include/git2/buffer.h
+++ b/include/git2/buffer.h
@@ -23,110 +23,50 @@ GIT_BEGIN_DECL
*
* Sometimes libgit2 wants to return an allocated data buffer to the
* caller and have the caller take responsibility for freeing that memory.
- * This can be awkward if the caller does not have easy access to the same
- * allocation functions that libgit2 is using. In those cases, libgit2
- * will fill in a `git_buf` and the caller can use `git_buf_dispose()` to
- * release it when they are done.
+ * To make ownership clear in these cases, libgit2 uses `git_buf` to
+ * return this data. Callers should use `git_buf_dispose()` to release
+ * the memory when they are done.
*
- * A `git_buf` may also be used for the caller to pass in a reference to
- * a block of memory they hold. In this case, libgit2 will not resize or
- * free the memory, but will read from it as needed.
- *
- * Some APIs may occasionally do something slightly unusual with a buffer,
- * such as setting `ptr` to a value that was passed in by the user. In
- * those cases, the behavior will be clearly documented by the API.
+ * A `git_buf` contains a pointer to a NUL-terminated C string, and
+ * the length of the string (not including the NUL terminator).
*/
typedef struct {
/**
- * The buffer contents.
- *
- * `ptr` points to the start of the allocated memory. If it is NULL,
- * then the `git_buf` is considered empty and libgit2 will feel free
- * to overwrite it with new data.
+ * The buffer contents. `ptr` points to the start of the buffer
+ * being returned. The buffer's length (in bytes) is specified
+ * by the `size` member of the structure, and contains a NUL
+ * terminator at position `(size + 1)`.
*/
- char *ptr;
+ char *ptr;
/**
- * `asize` holds the known total amount of allocated memory if the `ptr`
- * was allocated by libgit2. It may be larger than `size`. If `ptr`
- * was not allocated by libgit2 and should not be resized and/or freed,
- * then `asize` will be set to zero.
+ * This field is reserved and unused.
*/
- size_t asize;
+ size_t reserved;
/**
- * `size` holds the size (in bytes) of the data that is actually used.
+ * The length (in bytes) of the buffer pointed to by `ptr`,
+ * not including a NUL terminator.
*/
size_t size;
} git_buf;
/**
- * Static initializer for git_buf from static buffer
+ * Use to initialize a `git_buf` before passing it to a function that
+ * will populate it.
*/
-#define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
+#define GIT_BUF_INIT { NULL, 0, 0 }
/**
* Free the memory referred to by the git_buf.
*
* Note that this does not free the `git_buf` itself, just the memory
- * pointed to by `buffer->ptr`. This will not free the memory if it looks
- * like it was not allocated internally, but it will clear the buffer back
- * to the empty state.
+ * pointed to by `buffer->ptr`.
*
* @param buffer The buffer to deallocate
*/
GIT_EXTERN(void) git_buf_dispose(git_buf *buffer);
-/**
- * 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
- */
-GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
-
-/**
- * Set buffer to a copy of some raw data.
- *
- * @param buffer The buffer to set
- * @param data The data to copy into the buffer
- * @param datalen The length of the data to copy into the buffer
- * @return 0 on success, -1 on allocation failure
- */
-GIT_EXTERN(int) git_buf_set(
- git_buf *buffer, const void *data, size_t datalen);
-
-/**
-* Check quickly if buffer looks like it contains binary data
-*
-* @param buf Buffer to check
-* @return 1 if buffer looks like non-text data
-*/
-GIT_EXTERN(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
-*/
-GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
-
GIT_END_DECL
/** @} */
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
diff --git a/tests/apply/fromdiff.c b/tests/apply/fromdiff.c
index 69dfe0987..9da6ac923 100644
--- a/tests/apply/fromdiff.c
+++ b/tests/apply/fromdiff.c
@@ -22,15 +22,15 @@ void test_apply_fromdiff__cleanup(void)
}
static int apply_gitbuf(
- const git_buf *old,
+ const git_str *old,
const char *oldname,
- const git_buf *new,
+ const git_str *new,
const char *newname,
const char *patch_expected,
const git_diff_options *diff_opts)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
git_buf patchbuf = GIT_BUF_INIT;
char *filename;
unsigned int mode;
@@ -62,7 +62,7 @@ static int apply_gitbuf(
}
git__free(filename);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_buf_dispose(&patchbuf);
git_patch_free(patch);
@@ -77,7 +77,7 @@ static int apply_buf(
const char *patch_expected,
const git_diff_options *diff_opts)
{
- git_buf o = GIT_BUF_INIT, n = GIT_BUF_INIT,
+ git_str o = GIT_STR_INIT, n = GIT_STR_INIT,
*optr = NULL, *nptr = NULL;
if (old) {
@@ -275,7 +275,7 @@ void test_apply_fromdiff__no_change(void)
void test_apply_fromdiff__binary_add(void)
{
- git_buf newfile = GIT_BUF_INIT;
+ git_str newfile = GIT_STR_INIT;
newfile.ptr = FILE_BINARY_DELTA_MODIFIED;
newfile.size = FILE_BINARY_DELTA_MODIFIED_LEN;
@@ -288,7 +288,7 @@ void test_apply_fromdiff__binary_add(void)
void test_apply_fromdiff__binary_no_change(void)
{
- git_buf original = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT;
original.ptr = FILE_BINARY_DELTA_ORIGINAL;
original.size = FILE_BINARY_DELTA_ORIGINAL_LEN;
@@ -301,7 +301,7 @@ void test_apply_fromdiff__binary_no_change(void)
void test_apply_fromdiff__binary_change_delta(void)
{
- git_buf original = GIT_BUF_INIT, modified = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT, modified = GIT_STR_INIT;
original.ptr = FILE_BINARY_DELTA_ORIGINAL;
original.size = FILE_BINARY_DELTA_ORIGINAL_LEN;
@@ -317,7 +317,7 @@ void test_apply_fromdiff__binary_change_delta(void)
void test_apply_fromdiff__binary_change_literal(void)
{
- git_buf original = GIT_BUF_INIT, modified = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT, modified = GIT_STR_INIT;
original.ptr = FILE_BINARY_LITERAL_ORIGINAL;
original.size = FILE_BINARY_LITERAL_ORIGINAL_LEN;
@@ -333,7 +333,7 @@ void test_apply_fromdiff__binary_change_literal(void)
void test_apply_fromdiff__binary_delete(void)
{
- git_buf original = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT;
original.ptr = FILE_BINARY_DELTA_MODIFIED;
original.size = FILE_BINARY_DELTA_MODIFIED_LEN;
@@ -346,7 +346,7 @@ void test_apply_fromdiff__binary_delete(void)
void test_apply_fromdiff__patching_correctly_truncates_source(void)
{
- git_buf original = GIT_BUF_INIT, patched = GIT_BUF_INIT;
+ git_str original = GIT_STR_INIT, patched = GIT_STR_INIT;
git_patch *patch;
unsigned int mode;
char *path;
@@ -371,8 +371,8 @@ void test_apply_fromdiff__patching_correctly_truncates_source(void)
cl_git_pass(git_apply__patch(&patched, &path, &mode,
"foo\nbar\n", 7, patch, NULL));
- git_buf_dispose(&original);
- git_buf_dispose(&patched);
+ git_str_dispose(&original);
+ git_str_dispose(&patched);
git_patch_free(patch);
git__free(path);
}
diff --git a/tests/apply/fromfile.c b/tests/apply/fromfile.c
index ae519eab0..8cde62392 100644
--- a/tests/apply/fromfile.c
+++ b/tests/apply/fromfile.c
@@ -30,8 +30,8 @@ static int apply_patchfile(
unsigned int mode_expected)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
- git_buf patchbuf = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
+ git_str patchbuf = GIT_STR_INIT;
char *filename;
unsigned int mode;
int error;
@@ -50,8 +50,8 @@ static int apply_patchfile(
}
git__free(filename);
- git_buf_dispose(&result);
- git_buf_dispose(&patchbuf);
+ git_str_dispose(&result);
+ git_str_dispose(&patchbuf);
git_patch_free(patch);
return error;
diff --git a/tests/apply/partial.c b/tests/apply/partial.c
index 548faaadb..fd4908d4b 100644
--- a/tests/apply/partial.c
+++ b/tests/apply/partial.c
@@ -83,8 +83,8 @@ static int apply_buf(
void *payload)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
- git_buf patchbuf = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
+ git_str patchbuf = GIT_STR_INIT;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
char *filename;
unsigned int mode;
@@ -103,8 +103,8 @@ static int apply_buf(
}
git__free(filename);
- git_buf_dispose(&result);
- git_buf_dispose(&patchbuf);
+ git_str_dispose(&result);
+ git_str_dispose(&patchbuf);
git_patch_free(patch);
return error;
diff --git a/tests/attr/repo.c b/tests/attr/repo.c
index eabc033eb..e7b975290 100644
--- a/tests/attr/repo.c
+++ b/tests/attr/repo.c
@@ -230,12 +230,12 @@ void test_attr_repo__manpage_example(void)
static void add_to_workdir(const char *filename, const char *content)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, "attr", filename));
- cl_git_rewritefile(git_buf_cstr(&buf), content);
+ cl_git_pass(git_str_joinpath(&buf, "attr", filename));
+ cl_git_rewritefile(git_str_cstr(&buf), content);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha)
@@ -311,12 +311,12 @@ void test_attr_repo__bare_repo_with_index(void)
void test_attr_repo__sysdir(void)
{
- git_buf sysdir = GIT_BUF_INIT;
+ git_str sysdir = GIT_STR_INIT;
const char *value;
cl_git_pass(p_mkdir("system", 0777));
cl_git_rewritefile("system/gitattributes", "file merge=foo");
- cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
+ cl_git_pass(git_str_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
@@ -325,18 +325,18 @@ void test_attr_repo__sysdir(void)
cl_git_pass(p_unlink("system/gitattributes"));
cl_git_pass(p_rmdir("system"));
- git_buf_dispose(&sysdir);
+ git_str_dispose(&sysdir);
}
void test_attr_repo__sysdir_with_session(void)
{
const char *values[2], *attrs[2] = { "foo", "bar" };
- git_buf sysdir = GIT_BUF_INIT;
+ git_str sysdir = GIT_STR_INIT;
git_attr_session session;
cl_git_pass(p_mkdir("system", 0777));
cl_git_rewritefile("system/gitattributes", "file foo=1 bar=2");
- cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
+ cl_git_pass(git_str_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
@@ -348,7 +348,7 @@ void test_attr_repo__sysdir_with_session(void)
cl_git_pass(p_unlink("system/gitattributes"));
cl_git_pass(p_rmdir("system"));
- git_buf_dispose(&sysdir);
+ git_str_dispose(&sysdir);
git_attr_session__free(&session);
}
@@ -371,11 +371,11 @@ void test_attr_repo__rewrite(void)
void test_attr_repo__rewrite_sysdir(void)
{
- git_buf sysdir = GIT_BUF_INIT;
+ git_str sysdir = GIT_STR_INIT;
const char *value;
cl_git_pass(p_mkdir("system", 0777));
- cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
+ cl_git_pass(git_str_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
@@ -387,7 +387,7 @@ void test_attr_repo__rewrite_sysdir(void)
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "foo"));
cl_assert_equal_s(value, "second");
- git_buf_dispose(&sysdir);
+ git_str_dispose(&sysdir);
}
void test_attr_repo__unlink(void)
diff --git a/tests/buf/basic.c b/tests/buf/basic.c
deleted file mode 100644
index f90c4c6ed..000000000
--- a/tests/buf/basic.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-static const char *test_string = "Have you seen that? Have you seeeen that??";
-
-void test_buf_basic__resize(void)
-{
- git_buf buf1 = GIT_BUF_INIT;
- git_buf_puts(&buf1, test_string);
- cl_assert(git_buf_oom(&buf1) == 0);
- cl_assert_equal_s(git_buf_cstr(&buf1), test_string);
-
- git_buf_puts(&buf1, test_string);
- cl_assert(strlen(git_buf_cstr(&buf1)) == strlen(test_string) * 2);
- git_buf_dispose(&buf1);
-}
-
-void test_buf_basic__resize_incremental(void)
-{
- git_buf buf1 = GIT_BUF_INIT;
-
- /* Presently, asking for 6 bytes will round up to 8. */
- cl_git_pass(git_buf_puts(&buf1, "Hello"));
- cl_assert_equal_i(5, buf1.size);
- cl_assert_equal_i(8, buf1.asize);
-
- /* Ensure an additional byte does not realloc. */
- cl_git_pass(git_buf_grow_by(&buf1, 1));
- cl_assert_equal_i(5, buf1.size);
- cl_assert_equal_i(8, buf1.asize);
-
- /* But requesting many does. */
- cl_git_pass(git_buf_grow_by(&buf1, 16));
- cl_assert_equal_i(5, buf1.size);
- cl_assert(buf1.asize > 8);
-
- git_buf_dispose(&buf1);
-}
-
-void test_buf_basic__printf(void)
-{
- git_buf buf2 = GIT_BUF_INIT;
- git_buf_printf(&buf2, "%s %s %d ", "shoop", "da", 23);
- cl_assert(git_buf_oom(&buf2) == 0);
- cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 ");
-
- git_buf_printf(&buf2, "%s %d", "woop", 42);
- cl_assert(git_buf_oom(&buf2) == 0);
- cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 woop 42");
- git_buf_dispose(&buf2);
-}
diff --git a/tests/buf/splice.c b/tests/buf/splice.c
deleted file mode 100644
index 18c7c3f2b..000000000
--- a/tests/buf/splice.c
+++ /dev/null
@@ -1,93 +0,0 @@
-#include "clar_libgit2.h"
-#include "buffer.h"
-
-static git_buf _buf;
-
-void test_buf_splice__initialize(void) {
- git_buf_init(&_buf, 16);
-}
-
-void test_buf_splice__cleanup(void) {
- git_buf_dispose(&_buf);
-}
-
-void test_buf_splice__preprend(void)
-{
- git_buf_sets(&_buf, "world!");
-
- cl_git_pass(git_buf_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__append(void)
-{
- git_buf_sets(&_buf, "Hello");
-
- cl_git_pass(git_buf_splice(&_buf, git_buf_len(&_buf), 0, " world!", strlen(" world!")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__insert_at(void)
-{
- git_buf_sets(&_buf, "Hell world!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__remove_at(void)
-{
- git_buf_sets(&_buf, "Hello world of warcraft!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__replace(void)
-{
- git_buf_sets(&_buf, "Hell0 w0rld!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__replace_with_longer(void)
-{
- git_buf_sets(&_buf, "Hello you!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__replace_with_shorter(void)
-{
- git_buf_sets(&_buf, "Brave new world!");
-
- cl_git_pass(git_buf_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__truncate(void)
-{
- git_buf_sets(&_buf, "Hello world!!");
-
- cl_git_pass(git_buf_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
-
-void test_buf_splice__dont_do_anything(void)
-{
- git_buf_sets(&_buf, "Hello world!");
-
- cl_git_pass(git_buf_splice(&_buf, 3, 0, "Hello", 0));
-
- cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
-}
diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c
index 95af5d396..1e9c21bdc 100644
--- a/tests/checkout/checkout_helpers.c
+++ b/tests/checkout/checkout_helpers.c
@@ -7,16 +7,16 @@
void assert_on_branch(git_repository *repo, const char *branch)
{
git_reference *head;
- git_buf bname = GIT_BUF_INIT;
+ git_str bname = GIT_STR_INIT;
cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
cl_assert_(git_reference_type(head) == GIT_REFERENCE_SYMBOLIC, branch);
- cl_git_pass(git_buf_joinpath(&bname, "refs/heads", branch));
+ cl_git_pass(git_str_joinpath(&bname, "refs/heads", branch));
cl_assert_equal_s(bname.ptr, git_reference_symbolic_target(head));
git_reference_free(head);
- git_buf_dispose(&bname);
+ git_str_dispose(&bname);
}
void reset_index_to_treeish(git_object *treeish)
diff --git a/tests/checkout/checkout_helpers.h b/tests/checkout/checkout_helpers.h
index 6058a196c..879b48b06 100644
--- a/tests/checkout/checkout_helpers.h
+++ b/tests/checkout/checkout_helpers.h
@@ -1,4 +1,3 @@
-#include "buffer.h"
#include "git2/object.h"
#include "git2/repository.h"
diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c
index dae3f295e..3f5e7162d 100644
--- a/tests/checkout/conflict.c
+++ b/tests/checkout/conflict.c
@@ -85,14 +85,14 @@ void test_checkout_conflict__cleanup(void)
static void create_index(struct checkout_index_entry *entries, size_t entries_len)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t i;
for (i = 0; i < entries_len; i++) {
- git_buf_joinpath(&path, TEST_REPO_PATH, entries[i].path);
+ git_str_joinpath(&path, TEST_REPO_PATH, entries[i].path);
if (entries[i].stage == 3 && (i == 0 || strcmp(entries[i-1].path, entries[i].path) != 0 || entries[i-1].stage != 2))
- p_unlink(git_buf_cstr(&path));
+ p_unlink(git_str_cstr(&path));
cl_git_pass(git_index_remove_bypath(g_index, entries[i].path));
}
@@ -110,7 +110,7 @@ static void create_index(struct checkout_index_entry *entries, size_t entries_le
cl_git_pass(git_index_add(g_index, &entry));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void create_index_names(struct checkout_name_entry *entries, size_t entries_len)
@@ -139,16 +139,16 @@ static void create_conflicting_index(void)
static void ensure_workdir_contents(const char *path, const char *contents)
{
- git_buf fullpath = GIT_BUF_INIT, data_buf = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT, data_buf = GIT_STR_INIT;
cl_git_pass(
- git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+ git_str_joinpath(&fullpath, git_repository_workdir(g_repo), path));
- cl_git_pass(git_futils_readbuffer(&data_buf, git_buf_cstr(&fullpath)));
- cl_assert(strcmp(git_buf_cstr(&data_buf), contents) == 0);
+ cl_git_pass(git_futils_readbuffer(&data_buf, git_str_cstr(&fullpath)));
+ cl_assert(strcmp(git_str_cstr(&data_buf), contents) == 0);
- git_buf_dispose(&fullpath);
- git_buf_dispose(&data_buf);
+ git_str_dispose(&fullpath);
+ git_str_dispose(&data_buf);
}
static void ensure_workdir_oid(const char *path, const char *oid_str)
@@ -166,16 +166,16 @@ static void ensure_workdir_mode(const char *path, int mode)
GIT_UNUSED(path);
GIT_UNUSED(mode);
#else
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
struct stat st;
cl_git_pass(
- git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+ git_str_joinpath(&fullpath, git_repository_workdir(g_repo), path));
- cl_git_pass(p_stat(git_buf_cstr(&fullpath), &st));
+ cl_git_pass(p_stat(git_str_cstr(&fullpath), &st));
cl_assert_equal_i((mode & S_IRWXU), (st.st_mode & S_IRWXU));
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
#endif
}
@@ -197,22 +197,22 @@ static void ensure_workdir_link(
if (!symlinks) {
ensure_workdir_contents(path, target);
} else {
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
char actual[1024];
struct stat st;
int len;
cl_git_pass(
- git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+ git_str_joinpath(&fullpath, git_repository_workdir(g_repo), path));
- cl_git_pass(p_lstat(git_buf_cstr(&fullpath), &st));
+ cl_git_pass(p_lstat(git_str_cstr(&fullpath), &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert((len = p_readlink(git_buf_cstr(&fullpath), actual, 1024)) > 0);
+ cl_assert((len = p_readlink(git_str_cstr(&fullpath), actual, 1024)) > 0);
actual[len] = '\0';
cl_assert(strcmp(actual, target) == 0);
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
}
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index 495020161..eb4c61f39 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -11,9 +11,9 @@
static git_repository *g_repo;
static const char *systype;
-static git_buf expected_fixture = GIT_BUF_INIT;
+static git_str expected_fixture = GIT_STR_INIT;
-static int unlink_file(void *payload, git_buf *path)
+static int unlink_file(void *payload, git_str *path)
{
char *fn;
@@ -30,7 +30,7 @@ static int unlink_file(void *payload, git_buf *path)
void test_checkout_crlf__initialize(void)
{
- git_buf reponame = GIT_BUF_INIT;
+ git_str reponame = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("crlf");
@@ -38,7 +38,7 @@ void test_checkout_crlf__initialize(void)
* remove the contents of the working directory so that we can
* check out over it.
*/
- cl_git_pass(git_buf_puts(&reponame, "crlf"));
+ cl_git_pass(git_str_puts(&reponame, "crlf"));
cl_git_pass(git_path_direach(&reponame, 0, unlink_file, NULL));
if (GIT_EOL_NATIVE == GIT_EOL_CRLF)
@@ -46,7 +46,7 @@ void test_checkout_crlf__initialize(void)
else
systype = "posix";
- git_buf_dispose(&reponame);
+ git_str_dispose(&reponame);
}
void test_checkout_crlf__cleanup(void)
@@ -55,7 +55,7 @@ void test_checkout_crlf__cleanup(void)
if (expected_fixture.size) {
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
+ git_str_dispose(&expected_fixture);
}
}
@@ -66,11 +66,11 @@ struct compare_data
const char *attrs;
};
-static int compare_file(void *payload, git_buf *actual_path)
+static int compare_file(void *payload, git_str *actual_path)
{
- git_buf expected_path = GIT_BUF_INIT;
- git_buf actual_contents = GIT_BUF_INIT;
- git_buf expected_contents = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
+ git_str actual_contents = GIT_STR_INIT;
+ git_str expected_contents = GIT_STR_INIT;
struct compare_data *cd = payload;
bool failed = true;
int cmp_git, cmp_gitattributes;
@@ -85,7 +85,7 @@ static int compare_file(void *payload, git_buf *actual_path)
goto done;
}
- cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
+ cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename));
if (!git_path_isfile(expected_path.ptr) ||
!git_path_isfile(actual_path->ptr))
@@ -105,61 +105,61 @@ static int compare_file(void *payload, git_buf *actual_path)
done:
if (failed) {
- git_buf details = GIT_BUF_INIT;
- git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
+ git_str details = GIT_STR_INIT;
+ git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
clar__fail(__FILE__, __func__, __LINE__,
"checked out contents did not match expected", details.ptr, 0);
- git_buf_dispose(&details);
+ git_str_dispose(&details);
}
git__free(basename);
- git_buf_dispose(&expected_contents);
- git_buf_dispose(&actual_contents);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&expected_contents);
+ git_str_dispose(&actual_contents);
+ git_str_dispose(&expected_path);
return 0;
}
static void test_checkout(const char *autocrlf, const char *attrs)
{
- git_buf attrbuf = GIT_BUF_INIT;
- git_buf expected_dirname = GIT_BUF_INIT;
- git_buf systype_and_direction = GIT_BUF_INIT;
- git_buf sandboxname = GIT_BUF_INIT;
- git_buf reponame = GIT_BUF_INIT;
+ git_str attrbuf = GIT_STR_INIT;
+ git_str expected_dirname = GIT_STR_INIT;
+ git_str systype_and_direction = GIT_STR_INIT;
+ git_str sandboxname = GIT_STR_INIT;
+ git_str reponame = GIT_STR_INIT;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
struct compare_data compare_data = { NULL, autocrlf, attrs };
const char *c;
- cl_git_pass(git_buf_puts(&reponame, "crlf"));
+ cl_git_pass(git_str_puts(&reponame, "crlf"));
- cl_git_pass(git_buf_puts(&systype_and_direction, systype));
- cl_git_pass(git_buf_puts(&systype_and_direction, "_to_workdir"));
+ cl_git_pass(git_str_puts(&systype_and_direction, systype));
+ cl_git_pass(git_str_puts(&systype_and_direction, "_to_workdir"));
- cl_git_pass(git_buf_puts(&sandboxname, "autocrlf_"));
- cl_git_pass(git_buf_puts(&sandboxname, autocrlf));
+ cl_git_pass(git_str_puts(&sandboxname, "autocrlf_"));
+ cl_git_pass(git_str_puts(&sandboxname, autocrlf));
if (*attrs) {
- cl_git_pass(git_buf_puts(&sandboxname, ","));
+ cl_git_pass(git_str_puts(&sandboxname, ","));
for (c = attrs; *c; c++) {
if (*c == ' ')
- cl_git_pass(git_buf_putc(&sandboxname, ','));
+ cl_git_pass(git_str_putc(&sandboxname, ','));
else if (*c == '=')
- cl_git_pass(git_buf_putc(&sandboxname, '_'));
+ cl_git_pass(git_str_putc(&sandboxname, '_'));
else
- cl_git_pass(git_buf_putc(&sandboxname, *c));
+ cl_git_pass(git_str_putc(&sandboxname, *c));
}
- cl_git_pass(git_buf_printf(&attrbuf, "* %s\n", attrs));
+ cl_git_pass(git_str_printf(&attrbuf, "* %s\n", attrs));
cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr);
}
cl_repo_set_string(g_repo, "core.autocrlf", autocrlf);
- cl_git_pass(git_buf_joinpath(&expected_dirname, systype_and_direction.ptr, sandboxname.ptr));
- cl_git_pass(git_buf_joinpath(&expected_fixture, "crlf_data", expected_dirname.ptr));
+ cl_git_pass(git_str_joinpath(&expected_dirname, systype_and_direction.ptr, sandboxname.ptr));
+ cl_git_pass(git_str_joinpath(&expected_fixture, "crlf_data", expected_dirname.ptr));
cl_fixture_sandbox(expected_fixture.ptr);
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -169,14 +169,14 @@ static void test_checkout(const char *autocrlf, const char *attrs)
cl_git_pass(git_path_direach(&reponame, 0, compare_file, &compare_data));
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
-
- git_buf_dispose(&attrbuf);
- git_buf_dispose(&expected_fixture);
- git_buf_dispose(&expected_dirname);
- git_buf_dispose(&sandboxname);
- git_buf_dispose(&systype_and_direction);
- git_buf_dispose(&reponame);
+ git_str_dispose(&expected_fixture);
+
+ git_str_dispose(&attrbuf);
+ git_str_dispose(&expected_fixture);
+ git_str_dispose(&expected_dirname);
+ git_str_dispose(&sandboxname);
+ git_str_dispose(&systype_and_direction);
+ git_str_dispose(&reponame);
}
static void empty_workdir(const char *name)
diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c
index 077d24cd3..6c30765a3 100644
--- a/tests/checkout/icase.c
+++ b/tests/checkout/icase.c
@@ -46,7 +46,7 @@ void test_checkout_icase__cleanup(void)
static char *get_filename(const char *in)
{
char *search_dirname, *search_filename, *filename = NULL;
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
DIR *dir;
struct dirent *de;
@@ -57,8 +57,8 @@ static char *get_filename(const char *in)
while ((de = readdir(dir))) {
if (strcasecmp(de->d_name, search_filename) == 0) {
- git_buf_join(&out, '/', search_dirname, de->d_name);
- filename = git_buf_detach(&out);
+ git_str_join(&out, '/', search_dirname, de->d_name);
+ filename = git_str_detach(&out);
break;
}
}
@@ -67,7 +67,7 @@ static char *get_filename(const char *in)
git__free(search_dirname);
git__free(search_filename);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
return filename;
}
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 508975365..13eecc984 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -8,7 +8,7 @@
#include "repo/repo_helpers.h"
static git_repository *g_repo;
-static git_buf g_global_path = GIT_BUF_INIT;
+static git_str g_global_path = GIT_STR_INIT;
void test_checkout_index__initialize(void)
{
@@ -33,7 +33,7 @@ void test_checkout_index__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
g_global_path.ptr);
- git_buf_dispose(&g_global_path);
+ git_str_dispose(&g_global_path);
cl_git_sandbox_cleanup();
@@ -203,14 +203,14 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
static void populate_symlink_workdir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_remote *origin;
git_object *target;
const char *url = git_repository_path(g_repo);
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "symlink.git"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "symlink.git"));
cl_git_pass(git_repository_init(&repo, path.ptr, true));
cl_git_pass(git_repository_set_workdir(repo, "symlink", 1));
@@ -226,7 +226,7 @@ static void populate_symlink_workdir(void)
git_object_free(target);
git_repository_free(repo);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_checkout_index__honor_coresymlinks_default_true(void)
@@ -808,7 +808,7 @@ void test_checkout_index__writes_conflict_file(void)
{
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, g_repo));
@@ -824,7 +824,7 @@ void test_checkout_index__writes_conflict_file(void)
"=======\n"
"this file is changed in branch and master\n"
">>>>>>> theirs\n") == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
git_index_free(index);
}
@@ -855,7 +855,7 @@ void test_checkout_index__conflicts_honor_coreautocrlf(void)
#ifdef GIT_WIN32
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
cl_repo_set_bool(g_repo, "core.autocrlf", true);
@@ -874,7 +874,7 @@ void test_checkout_index__conflicts_honor_coreautocrlf(void)
"=======\r\n"
"this file is changed in branch and master\r\n"
">>>>>>> theirs\r\n") == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
git_index_free(index);
#endif
diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c
index 611e850d3..a1b3164be 100644
--- a/tests/checkout/nasty.c
+++ b/tests/checkout/nasty.c
@@ -3,7 +3,6 @@
#include "git2/checkout.h"
#include "repository.h"
-#include "buffer.h"
#include "futils.h"
static const char *repo_name = "nasty";
@@ -28,9 +27,9 @@ static void test_checkout_passes(const char *refname, const char *filename)
git_oid commit_id;
git_commit *commit;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, repo_name, filename));
+ cl_git_pass(git_str_joinpath(&path, repo_name, filename));
cl_git_pass(git_reference_name_to_id(&commit_id, repo, refname));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
@@ -42,7 +41,7 @@ static void test_checkout_passes(const char *refname, const char *filename)
cl_assert(!git_path_exists(path.ptr));
git_commit_free(commit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void test_checkout_fails(const char *refname, const char *filename)
@@ -50,9 +49,9 @@ static void test_checkout_fails(const char *refname, const char *filename)
git_oid commit_id;
git_commit *commit;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, repo_name, filename));
+ cl_git_pass(git_str_joinpath(&path, repo_name, filename));
cl_git_pass(git_reference_name_to_id(&commit_id, repo, refname));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
@@ -63,7 +62,7 @@ static void test_checkout_fails(const char *refname, const char *filename)
cl_assert(!git_path_exists(path.ptr));
git_commit_free(commit);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/* A tree that contains ".git" as a tree, with a blob inside
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 3241a3eb7..cdfb456b7 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -3,7 +3,6 @@
#include "git2/checkout.h"
#include "repository.h"
-#include "buffer.h"
#include "futils.h"
static git_repository *g_repo;
@@ -519,7 +518,7 @@ void assert_conflict(
git_index *index;
git_object *hack_tree;
git_reference *branch, *head;
- git_buf file_path = GIT_BUF_INIT;
+ git_str file_path = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, g_repo));
@@ -549,9 +548,9 @@ void assert_conflict(
g_object = NULL;
/* Create a conflicting file */
- cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path));
- cl_git_mkfile(git_buf_cstr(&file_path), new_content);
- git_buf_dispose(&file_path);
+ cl_git_pass(git_str_joinpath(&file_path, "./testrepo", entry_path));
+ cl_git_mkfile(git_str_cstr(&file_path), new_content);
+ git_str_dispose(&file_path);
/* Trying to checkout the original commit */
cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha));
@@ -1037,17 +1036,17 @@ void test_checkout_tree__filemode_preserved_in_index(void)
mode_t read_filemode(const char *path)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
struct stat st;
mode_t result;
- git_buf_joinpath(&fullpath, "testrepo", path);
+ git_str_joinpath(&fullpath, "testrepo", path);
cl_must_pass(p_stat(fullpath.ptr, &st));
result = GIT_PERMS_IS_EXEC(st.st_mode) ?
GIT_FILEMODE_BLOB_EXECUTABLE : GIT_FILEMODE_BLOB;
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
return result;
}
@@ -1317,7 +1316,7 @@ void test_checkout_tree__caches_attributes_during_checkout(void)
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_oid oid;
git_object *obj = NULL;
- git_buf ident1 = GIT_BUF_INIT, ident2 = GIT_BUF_INIT;
+ git_str ident1 = GIT_STR_INIT, ident2 = GIT_STR_INIT;
char *ident_paths[] = { "ident1.txt", "ident2.txt" };
opts.progress_cb = update_attr_callback;
@@ -1346,8 +1345,8 @@ void test_checkout_tree__caches_attributes_during_checkout(void)
cl_assert_equal_strn(ident1.ptr, "# $Id: ", 7);
cl_assert_equal_strn(ident2.ptr, "# $Id: ", 7);
- git_buf_dispose(&ident1);
- git_buf_dispose(&ident2);
+ git_str_dispose(&ident1);
+ git_str_dispose(&ident2);
git_object_free(obj);
}
@@ -1679,6 +1678,6 @@ void test_checkout_tree__dry_run(void)
/* check that notify callback was invoked */
cl_assert_equal_i(ct.n_updates, 2);
-
+
git_object_free(obj);
}
diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c
index db3f02a5c..205ce657f 100644
--- a/tests/checkout/typechange.c
+++ b/tests/checkout/typechange.c
@@ -90,7 +90,7 @@ static void assert_workdir_matches_tree(
git_object *obj;
git_tree *tree;
size_t i, max_i;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (!root)
root = git_repository_workdir(repo);
@@ -106,7 +106,7 @@ static void assert_workdir_matches_tree(
const git_tree_entry *te = git_tree_entry_byindex(tree, i);
cl_assert(te);
- cl_git_pass(git_buf_joinpath(&path, root, git_tree_entry_name(te)));
+ cl_git_pass(git_str_joinpath(&path, root, git_tree_entry_name(te)));
switch (git_tree_entry_type(te)) {
case GIT_OBJECT_COMMIT:
@@ -139,7 +139,7 @@ static void assert_workdir_matches_tree(
}
git_tree_free(tree);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_checkout_typechange__checkout_typechanges_safe(void)
@@ -226,31 +226,31 @@ static void force_create_file(const char *file)
static int make_submodule_dirty(git_submodule *sm, const char *name, void *payload)
{
- git_buf submodulepath = GIT_BUF_INIT;
- git_buf dirtypath = GIT_BUF_INIT;
+ git_str submodulepath = GIT_STR_INIT;
+ git_str dirtypath = GIT_STR_INIT;
git_repository *submodule_repo;
GIT_UNUSED(name);
GIT_UNUSED(payload);
/* remove submodule directory in preparation for init and repo_init */
- cl_git_pass(git_buf_joinpath(
+ cl_git_pass(git_str_joinpath(
&submodulepath,
git_repository_workdir(g_repo),
git_submodule_path(sm)
));
- git_futils_rmdir_r(git_buf_cstr(&submodulepath), NULL, GIT_RMDIR_REMOVE_FILES);
+ git_futils_rmdir_r(git_str_cstr(&submodulepath), NULL, GIT_RMDIR_REMOVE_FILES);
/* initialize submodule's repository */
cl_git_pass(git_submodule_repo_init(&submodule_repo, sm, 0));
/* create a file in the submodule workdir to make it dirty */
cl_git_pass(
- git_buf_joinpath(&dirtypath, git_repository_workdir(submodule_repo), "dirty"));
- force_create_file(git_buf_cstr(&dirtypath));
+ git_str_joinpath(&dirtypath, git_repository_workdir(submodule_repo), "dirty"));
+ force_create_file(git_str_cstr(&dirtypath));
- git_buf_dispose(&dirtypath);
- git_buf_dispose(&submodulepath);
+ git_str_dispose(&dirtypath);
+ git_str_dispose(&submodulepath);
git_repository_free(submodule_repo);
return 0;
diff --git a/tests/cherrypick/bare.c b/tests/cherrypick/bare.c
index 50e8d8600..f90ce0226 100644
--- a/tests/cherrypick/bare.c
+++ b/tests/cherrypick/bare.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/cherrypick.h"
diff --git a/tests/cherrypick/workdir.c b/tests/cherrypick/workdir.c
index 10e8c2d8b..f7765f2c2 100644
--- a/tests/cherrypick/workdir.c
+++ b/tests/cherrypick/workdir.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/cherrypick.h"
@@ -140,7 +139,7 @@ void test_cherrypick_workdir__conflicts(void)
{
git_commit *head = NULL, *commit = NULL;
git_oid head_oid, cherry_oid;
- git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
@@ -168,7 +167,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
- cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+ cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
"Change all files\n" \
"\n" \
"Conflicts:\n" \
@@ -178,7 +177,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/file2.txt"));
- cl_assert(strcmp(git_buf_cstr(&conflicting_buf),
+ cl_assert(strcmp(git_str_cstr(&conflicting_buf),
"!File 2\n" \
"File 2\n" \
"File 2\n" \
@@ -204,7 +203,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/file3.txt"));
- cl_assert(strcmp(git_buf_cstr(&conflicting_buf),
+ cl_assert(strcmp(git_str_cstr(&conflicting_buf),
"!File 3\n" \
"File 3\n" \
"File 3\n" \
@@ -228,8 +227,8 @@ void test_cherrypick_workdir__conflicts(void)
git_commit_free(commit);
git_commit_free(head);
- git_buf_dispose(&mergemsg_buf);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&mergemsg_buf);
+ git_str_dispose(&conflicting_buf);
}
/* git reset --hard bafbf6912c09505ac60575cd43d3f2aba3bd84d8
@@ -324,7 +323,7 @@ void test_cherrypick_workdir__both_renamed(void)
{
git_commit *head, *commit;
git_oid head_oid, cherry_oid;
- git_buf mergemsg_buf = GIT_BUF_INIT;
+ git_str mergemsg_buf = GIT_STR_INIT;
git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -350,7 +349,7 @@ void test_cherrypick_workdir__both_renamed(void)
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
- cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+ cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
"Renamed file3.txt -> file3.txt.renamed\n" \
"\n" \
"Conflicts:\n" \
@@ -358,7 +357,7 @@ void test_cherrypick_workdir__both_renamed(void)
"\tfile3.txt.renamed\n" \
"\tfile3.txt.renamed_on_branch\n") == 0);
- git_buf_dispose(&mergemsg_buf);
+ git_str_dispose(&mergemsg_buf);
git_commit_free(commit);
git_commit_free(head);
}
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index c4550c32a..adea597e3 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -68,7 +68,7 @@ void cl_git_rmfile(const char *filename)
char *cl_getenv(const char *name)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
int error = git__getenv(&out, name);
cl_assert(error >= 0 || error == GIT_ENOTFOUND);
@@ -83,7 +83,7 @@ char *cl_getenv(const char *name)
return dup;
}
- return git_buf_detach(&out);
+ return git_str_detach(&out);
}
bool cl_is_env_set(const char *name)
@@ -278,11 +278,11 @@ const char* cl_git_path_url(const char *path)
static char url[4096 + 1];
const char *in_buf;
- git_buf path_buf = GIT_BUF_INIT;
- git_buf url_buf = GIT_BUF_INIT;
+ git_str path_buf = GIT_STR_INIT;
+ git_str url_buf = GIT_STR_INIT;
cl_git_pass(git_path_prettify_dir(&path_buf, path, NULL));
- cl_git_pass(git_buf_puts(&url_buf, "file://"));
+ cl_git_pass(git_str_puts(&url_buf, "file://"));
#ifdef GIT_WIN32
/*
@@ -294,29 +294,29 @@ const char* cl_git_path_url(const char *path)
* *nix: file:///usr/home/...
* Windows: file:///C:/Users/...
*/
- cl_git_pass(git_buf_putc(&url_buf, '/'));
+ cl_git_pass(git_str_putc(&url_buf, '/'));
#endif
- in_buf = git_buf_cstr(&path_buf);
+ in_buf = git_str_cstr(&path_buf);
/*
* A very hacky Url encoding that only takes care of escaping the spaces
*/
while (*in_buf) {
if (*in_buf == ' ')
- cl_git_pass(git_buf_puts(&url_buf, "%20"));
+ cl_git_pass(git_str_puts(&url_buf, "%20"));
else
- cl_git_pass(git_buf_putc(&url_buf, *in_buf));
+ cl_git_pass(git_str_putc(&url_buf, *in_buf));
in_buf++;
}
cl_assert(url_buf.size < sizeof(url) - 1);
- strncpy(url, git_buf_cstr(&url_buf), sizeof(url) - 1);
+ strncpy(url, git_str_cstr(&url_buf), sizeof(url) - 1);
url[sizeof(url) - 1] = '\0';
- git_buf_dispose(&url_buf);
- git_buf_dispose(&path_buf);
+ git_str_dispose(&url_buf);
+ git_str_dispose(&path_buf);
return url;
}
@@ -324,15 +324,15 @@ const char *cl_git_sandbox_path(int is_dir, ...)
{
const char *path = NULL;
static char _temp[GIT_PATH_MAX];
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
va_list arg;
- cl_git_pass(git_buf_sets(&buf, clar_sandbox_path()));
+ cl_git_pass(git_str_sets(&buf, clar_sandbox_path()));
va_start(arg, is_dir);
while ((path = va_arg(arg, const char *)) != NULL) {
- cl_git_pass(git_buf_joinpath(&buf, buf.ptr, path));
+ cl_git_pass(git_str_joinpath(&buf, buf.ptr, path));
}
va_end(arg);
@@ -341,10 +341,10 @@ const char *cl_git_sandbox_path(int is_dir, ...)
git_path_to_dir(&buf);
/* make sure we won't truncate */
- cl_assert(git_buf_len(&buf) < sizeof(_temp));
- git_buf_copy_cstr(_temp, sizeof(_temp), &buf);
+ cl_assert(git_str_len(&buf) < sizeof(_temp));
+ git_str_copy_cstr(_temp, sizeof(_temp), &buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return _temp;
}
@@ -354,7 +354,7 @@ typedef struct {
size_t filename_len;
} remove_data;
-static int remove_placeholders_recurs(void *_data, git_buf *path)
+static int remove_placeholders_recurs(void *_data, git_str *path)
{
remove_data *data = (remove_data *)_data;
size_t pathlen;
@@ -380,12 +380,12 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
{
int error;
remove_data data;
- git_buf buffer = GIT_BUF_INIT;
+ git_str buffer = GIT_STR_INIT;
if (git_path_isdir(directory_path) == false)
return -1;
- if (git_buf_sets(&buffer, directory_path) < 0)
+ if (git_str_sets(&buffer, directory_path) < 0)
return -1;
data.filename = filename;
@@ -393,7 +393,7 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
error = remove_placeholders_recurs(&data, &buffer);
- git_buf_dispose(&buffer);
+ git_str_dispose(&buffer);
return error;
}
@@ -548,30 +548,26 @@ void clar__assert_equal_file(
(size_t)expected_bytes, (size_t)total_bytes);
}
-static char *_cl_restore_home = NULL;
+static git_buf _cl_restore_home = GIT_BUF_INIT;
void cl_fake_home_cleanup(void *payload)
{
- char *restore = _cl_restore_home;
- _cl_restore_home = NULL;
-
GIT_UNUSED(payload);
- if (restore) {
+ if (_cl_restore_home.ptr) {
cl_git_pass(git_libgit2_opts(
- GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore));
- git__free(restore);
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, _cl_restore_home.ptr));
+ git_buf_dispose(&_cl_restore_home);
}
}
void cl_fake_home(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_libgit2_opts(
- GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &path));
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_home));
- _cl_restore_home = git_buf_detach(&path);
cl_set_cleanup(cl_fake_home_cleanup, NULL);
if (!git_path_exists("home"))
@@ -579,14 +575,14 @@ void cl_fake_home(void)
cl_git_pass(git_path_prettify(&path, "home", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void cl_sandbox_set_search_path_defaults(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- git_buf_joinpath(&path, clar_sandbox_path(), "__config");
+ git_str_joinpath(&path, clar_sandbox_path(), "__config");
if (!git_path_exists(path.ptr))
cl_must_pass(p_mkdir(path.ptr, 0777));
@@ -600,18 +596,18 @@ void cl_sandbox_set_search_path_defaults(void)
git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_PROGRAMDATA, path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
#ifdef GIT_WIN32
bool cl_sandbox_supports_8dot3(void)
{
- git_buf longpath = GIT_BUF_INIT;
+ git_str longpath = GIT_STR_INIT;
char *shortname;
bool supported;
cl_git_pass(
- git_buf_joinpath(&longpath, clar_sandbox_path(), "longer_than_8dot3"));
+ git_str_joinpath(&longpath, clar_sandbox_path(), "longer_than_8dot3"));
cl_git_write2file(longpath.ptr, "", 0, O_RDWR|O_CREAT, 0666);
shortname = git_win32_path_8dot3_name(longpath.ptr);
@@ -619,7 +615,7 @@ bool cl_sandbox_supports_8dot3(void)
supported = (shortname != NULL);
git__free(shortname);
- git_buf_dispose(&longpath);
+ git_str_dispose(&longpath);
return supported;
}
diff --git a/tests/clar_libgit2_timer.c b/tests/clar_libgit2_timer.c
index 737506da2..2330f9351 100644
--- a/tests/clar_libgit2_timer.c
+++ b/tests/clar_libgit2_timer.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "clar_libgit2_timer.h"
-#include "buffer.h"
void cl_perf_timer__init(cl_perf_timer *t)
{
diff --git a/tests/clone/local.c b/tests/clone/local.c
index b90ff3107..e0bd74df7 100644
--- a/tests/clone/local.c
+++ b/tests/clone/local.c
@@ -2,42 +2,41 @@
#include "git2/clone.h"
#include "clone.h"
-#include "buffer.h"
#include "path.h"
#include "posix.h"
#include "futils.h"
-static int file_url(git_buf *buf, const char *host, const char *path)
+static int file_url(git_str *buf, const char *host, const char *path)
{
if (path[0] == '/')
path++;
- git_buf_clear(buf);
- return git_buf_printf(buf, "file://%s/%s", host, path);
+ git_str_clear(buf);
+ return git_str_printf(buf, "file://%s/%s", host, path);
}
#ifdef GIT_WIN32
-static int git_style_unc_path(git_buf *buf, const char *host, const char *path)
+static int git_style_unc_path(git_str *buf, const char *host, const char *path)
{
- git_buf_clear(buf);
+ git_str_clear(buf);
if (host)
- git_buf_printf(buf, "//%s/", host);
+ git_str_printf(buf, "//%s/", host);
if (path[0] == '/')
path++;
if (git__isalpha(path[0]) && path[1] == ':' && path[2] == '/') {
- git_buf_printf(buf, "%c$/", path[0]);
+ git_str_printf(buf, "%c$/", path[0]);
path += 3;
}
- git_buf_puts(buf, path);
+ git_str_puts(buf, path);
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
-static int unc_path(git_buf *buf, const char *host, const char *path)
+static int unc_path(git_str *buf, const char *host, const char *path)
{
char *c;
@@ -54,7 +53,7 @@ static int unc_path(git_buf *buf, const char *host, const char *path)
void test_clone_local__should_clone_local(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* we use a fixture path because it needs to exist for us to want to clone */
const char *path = cl_fixture("testrepo.git");
@@ -79,8 +78,8 @@ void test_clone_local__should_clone_local(void)
/* Ensure that file:/// urls are percent decoded: .git == %2e%67%69%74 */
cl_git_pass(file_url(&buf, "", path));
- git_buf_shorten(&buf, 4);
- cl_git_pass(git_buf_puts(&buf, "%2e%67%69%74"));
+ git_str_shorten(&buf, 4);
+ cl_git_pass(git_str_puts(&buf, "%2e%67%69%74"));
cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
@@ -91,14 +90,14 @@ void test_clone_local__should_clone_local(void)
cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS));
cl_assert_equal_i(0, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_clone_local__hardlinks(void)
{
git_repository *repo;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
struct stat st;
/*
@@ -117,21 +116,21 @@ void test_clone_local__hardlinks(void)
cl_git_pass(git_clone(&repo, cl_git_path_url("clone.git"), "./clone2.git", &opts));
#ifndef GIT_WIN32
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(p_stat(buf.ptr, &st));
cl_assert_equal_i(2, st.st_nlink);
#endif
git_repository_free(repo);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
opts.local = GIT_CLONE_LOCAL_NO_LINKS;
cl_git_pass(git_clone(&repo, cl_git_path_url("clone.git"), "./clone3.git", &opts));
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(p_stat(buf.ptr, &st));
cl_assert_equal_i(1, st.st_nlink);
@@ -142,14 +141,14 @@ void test_clone_local__hardlinks(void)
cl_git_pass(git_clone(&repo, "./clone.git", "./clone4.git", NULL));
#ifndef GIT_WIN32
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(p_stat(buf.ptr, &st));
cl_assert_equal_i(3, st.st_nlink);
#endif
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_repository_free(repo);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
@@ -164,7 +163,7 @@ void test_clone_local__standard_unc_paths_are_written_git_style(void)
git_repository *repo;
git_remote *remote;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf unc = GIT_BUF_INIT, git_unc = GIT_BUF_INIT;
+ git_str unc = GIT_STR_INIT, git_unc = GIT_STR_INIT;
/* we use a fixture path because it needs to exist for us to want to clone */
const char *path = cl_fixture("testrepo.git");
@@ -179,8 +178,8 @@ void test_clone_local__standard_unc_paths_are_written_git_style(void)
git_remote_free(remote);
git_repository_free(repo);
- git_buf_dispose(&unc);
- git_buf_dispose(&git_unc);
+ git_str_dispose(&unc);
+ git_str_dispose(&git_unc);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
#endif
@@ -192,7 +191,7 @@ void test_clone_local__git_style_unc_paths(void)
git_repository *repo;
git_remote *remote;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf git_unc = GIT_BUF_INIT;
+ git_str git_unc = GIT_STR_INIT;
/* we use a fixture path because it needs to exist for us to want to clone */
const char *path = cl_fixture("testrepo.git");
@@ -206,7 +205,7 @@ void test_clone_local__git_style_unc_paths(void)
git_remote_free(remote);
git_repository_free(repo);
- git_buf_dispose(&git_unc);
+ git_str_dispose(&git_unc);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
#endif
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index ec12fee18..7625a2183 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -145,15 +145,15 @@ void test_clone_nonetwork__cope_with_already_existing_directory(void)
void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
g_options.checkout_opts.checkout_strategy = 0;
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&path)));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_clone_nonetwork__can_checkout_given_branch(void)
@@ -304,9 +304,9 @@ static void assert_correct_reflog(const char *name)
{
git_reflog *log;
const git_reflog_entry *entry;
- git_buf expected_message = GIT_BUF_INIT;
+ git_str expected_message = GIT_STR_INIT;
- git_buf_printf(&expected_message,
+ git_str_printf(&expected_message,
"clone: from %s", cl_git_fixture_url("testrepo.git"));
cl_git_pass(git_reflog_read(&log, g_repo, name));
@@ -316,7 +316,7 @@ static void assert_correct_reflog(const char *name)
git_reflog_free(log);
- git_buf_dispose(&expected_message);
+ git_str_dispose(&expected_message);
}
void test_clone_nonetwork__clone_updates_reflog_properly(void)
diff --git a/tests/commit/parse.c b/tests/commit/parse.c
index f0a31de9a..04366d7d2 100644
--- a/tests/commit/parse.c
+++ b/tests/commit/parse.c
@@ -445,15 +445,15 @@ cpxtDQQMGYFpXK/71stq\n\
cl_git_pass(git_commit_header_field(&buf, commit, "tree"));
cl_assert_equal_s("6b79e22d69bf46e289df0345a14ca059dfc9bdf6", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_commit_header_field(&buf, commit, "parent"));
cl_assert_equal_s("34734e478d6cf50c27c9d69026d93974d052c454", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_commit_header_field(&buf, commit, "gpgsig"));
cl_assert_equal_s(gpgsig, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "awesomeness"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "par"));
@@ -513,7 +513,6 @@ committer Some User <someuser@gmail.com> 1454537944 -0700\n\
\n\
corrupt signature\n";
-
cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
cl_git_pass(git_odb_write(&commit_id, odb, passing_commit_cases[4], strlen(passing_commit_cases[4]), GIT_OBJECT_COMMIT));
@@ -521,13 +520,16 @@ corrupt signature\n";
cl_assert_equal_s(gpgsig, signature.ptr);
cl_assert_equal_s(data, signed_data.ptr);
- git_buf_clear(&signature);
- git_buf_clear(&signed_data);
+ git_buf_dispose(&signature);
+ git_buf_dispose(&signed_data);
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, "gpgsig"));
cl_assert_equal_s(gpgsig, signature.ptr);
cl_assert_equal_s(data, signed_data.ptr);
+ git_buf_dispose(&signature);
+ git_buf_dispose(&signed_data);
+
/* Try to parse a tree */
cl_git_pass(git_oid_fromstr(&commit_id, "45dd856fdd4d89b884c340ba0e047752d9b085d6"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
@@ -539,15 +541,11 @@ corrupt signature\n";
cl_assert_equal_i(GIT_ERROR_OBJECT, git_error_last()->klass);
/* Parse the commit with a single-line signature */
- git_buf_clear(&signature);
- git_buf_clear(&signed_data);
cl_git_pass(git_odb_write(&commit_id, odb, oneline_signature, strlen(oneline_signature), GIT_OBJECT_COMMIT));
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
cl_assert_equal_s("bad", signature.ptr);
cl_assert_equal_s(oneline_data, signed_data.ptr);
-
git_buf_dispose(&signature);
git_buf_dispose(&signed_data);
-
}
diff --git a/tests/config/conditionals.c b/tests/config/conditionals.c
index 5858782c1..6249dbd79 100644
--- a/tests/config/conditionals.c
+++ b/tests/config/conditionals.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "repository.h"
@@ -23,43 +22,46 @@ void test_config_conditionals__cleanup(void)
static void assert_condition_includes(const char *keyword, const char *path, bool expected)
{
- git_buf buf = GIT_BUF_INIT;
+ git_buf value = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_config *cfg;
- cl_git_pass(git_buf_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
- cl_git_pass(git_buf_puts(&buf, "path = other\n"));
+ cl_git_pass(git_str_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
+ cl_git_pass(git_str_puts(&buf, "path = other\n"));
cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
_repo = cl_git_sandbox_reopen();
+ git_str_dispose(&buf);
+
cl_git_pass(git_repository_config(&cfg, _repo));
if (expected) {
- git_buf_clear(&buf);
- cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_git_pass(git_config_get_string_buf(&value, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", value.ptr);
} else {
cl_git_fail_with(GIT_ENOTFOUND,
- git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ git_config_get_string_buf(&value, cfg, "foo.bar"));
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
+ git_buf_dispose(&value);
git_config_free(cfg);
}
-static char *sandbox_path(git_buf *buf, const char *suffix)
+static char *sandbox_path(git_str *buf, const char *suffix)
{
char *path = p_realpath(clar_sandbox_path(), NULL);
cl_assert(path);
- cl_git_pass(git_buf_attach(buf, path, 0));
- cl_git_pass(git_buf_joinpath(buf, buf->ptr, suffix));
+ cl_git_pass(git_str_attach(buf, path, 0));
+ cl_git_pass(git_str_joinpath(buf, buf->ptr, suffix));
return buf->ptr;
}
void test_config_conditionals__gitdir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
assert_condition_includes("gitdir", ROOT_PREFIX "/", true);
assert_condition_includes("gitdir", "empty_stand", false);
@@ -90,17 +92,17 @@ void test_config_conditionals__gitdir(void)
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo/"), false);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_config_conditionals__gitdir_i(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
assert_condition_includes("gitdir/i", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir/i", sandbox_path(&path, "EMPTY_STANDARD_REPO/"), true);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_config_conditionals__invalid_conditional_fails(void)
diff --git a/tests/config/config_helpers.c b/tests/config/config_helpers.c
index d92ff1a4e..ecdab5bf6 100644
--- a/tests/config/config_helpers.c
+++ b/tests/config/config_helpers.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
-#include "buffer.h"
void assert_config_entry_existence(
git_repository *repo,
@@ -13,7 +12,7 @@ void assert_config_entry_existence(
int result;
cl_git_pass(git_repository_config__weakptr(&config, repo));
-
+
result = git_config_get_entry(&entry, config, name);
git_config_entry_free(entry);
@@ -35,7 +34,7 @@ void assert_config_entry_value(
cl_git_pass(git_config_get_string_buf(&buf, config, name));
- cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_value, buf.ptr);
git_buf_dispose(&buf);
}
diff --git a/tests/config/configlevel.c b/tests/config/configlevel.c
index 15c469fcb..8422d32c9 100644
--- a/tests/config/configlevel.c
+++ b/tests/config/configlevel.c
@@ -22,7 +22,7 @@ void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
{
git_config *cfg;
- git_buf buf = {0};
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
diff --git a/tests/config/global.c b/tests/config/global.c
index ed47d0251..d59c39fa2 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -1,10 +1,9 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
void test_config_global__initialize(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_futils_mkdir_r("home", 0777));
cl_git_pass(git_path_prettify(&path, "home", NULL));
@@ -21,7 +20,7 @@ void test_config_global__initialize(void)
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_config_global__cleanup(void)
@@ -132,24 +131,25 @@ void test_config_global__open_programdata(void)
{
git_config *cfg;
git_repository *repo;
- git_buf config_path = GIT_BUF_INIT;
+ git_buf dir_path = GIT_BUF_INIT;
+ git_str config_path = GIT_STR_INIT;
git_buf var_contents = GIT_BUF_INIT;
if (cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
cl_skip();
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
- GIT_CONFIG_LEVEL_PROGRAMDATA, &config_path));
+ GIT_CONFIG_LEVEL_PROGRAMDATA, &dir_path));
- if (!git_path_isdir(config_path.ptr))
- cl_git_pass(p_mkdir(config_path.ptr, 0777));
+ if (!git_path_isdir(dir_path.ptr))
+ cl_git_pass(p_mkdir(dir_path.ptr, 0777));
- cl_git_pass(git_buf_puts(&config_path, "/config"));
+ cl_git_pass(git_str_joinpath(&config_path, dir_path.ptr, "config"));
cl_git_pass(git_config_open_ondisk(&cfg, config_path.ptr));
cl_git_pass(git_config_set_string(cfg, "programdata.var", "even higher level"));
- git_buf_dispose(&config_path);
+ git_str_dispose(&config_path);
git_config_free(cfg);
git_config_open_default(&cfg);
@@ -165,6 +165,7 @@ void test_config_global__open_programdata(void)
cl_assert_equal_s("even higher level", var_contents.ptr);
git_config_free(cfg);
+ git_buf_dispose(&dir_path);
git_buf_dispose(&var_contents);
git_repository_free(repo);
cl_fixture_cleanup("./foo.git");
diff --git a/tests/config/include.c b/tests/config/include.c
index b702d6211..9328f3cf6 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
static git_config *cfg;
@@ -7,14 +6,14 @@ static git_buf buf;
void test_config_include__initialize(void)
{
- cfg = NULL;
- git_buf_init(&buf, 0);
+ cfg = NULL;
+ memset(&buf, 0, sizeof(git_buf));
}
void test_config_include__cleanup(void)
{
- git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_config_free(cfg);
+ git_buf_dispose(&buf);
}
void test_config_include__relative(void)
@@ -22,19 +21,21 @@ void test_config_include__relative(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
}
void test_config_include__absolute(void)
{
- cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
+ git_str cfgdata = GIT_STR_INIT;
+ cl_git_pass(git_str_printf(&cfgdata, "[include]\npath = %s/config-included", cl_fixture("config")));
+
+ cl_git_mkfile("config-include-absolute", cfgdata.ptr);
+ git_str_dispose(&cfgdata);
- cl_git_mkfile("config-include-absolute", git_buf_cstr(&buf));
- git_buf_dispose(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_git_pass(p_unlink("config-include-absolute"));
}
@@ -47,7 +48,7 @@ void test_config_include__homedir(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_sandbox_set_search_path_defaults();
@@ -66,10 +67,10 @@ void test_config_include__ordering(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
- cl_assert_equal_s("hiya", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("hiya", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
- cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ cl_assert_equal_s("huzzah", buf.ptr);
cl_git_pass(p_unlink("included"));
cl_git_pass(p_unlink("including"));
@@ -92,7 +93,7 @@ void test_config_include__empty_path_sanely_handled(void)
cl_git_mkfile("a", "[include]\npath");
cl_git_pass(git_config_open_ondisk(&cfg, "a"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "include.path"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
cl_git_pass(p_unlink("a"));
}
@@ -105,7 +106,7 @@ void test_config_include__missing(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
cl_git_pass(p_unlink("including"));
}
@@ -119,7 +120,7 @@ void test_config_include__missing_homedir(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
cl_sandbox_set_search_path_defaults();
cl_git_pass(p_unlink("including"));
@@ -137,11 +138,11 @@ void test_config_include__depth2(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
- cl_assert_equal_s("baz2", git_buf_cstr(&buf));
+ cl_assert_equal_s("baz2", buf.ptr);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("middle"));
@@ -186,13 +187,13 @@ void test_config_include__rewriting_include_twice_refreshes_values(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_mkfile("included", "[foo]\nother = value2");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_assert_equal_s(buf.ptr, "value2");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_mkfile("included", "[foo]\nanother = bar");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.another"));
diff --git a/tests/config/new.c b/tests/config/new.c
index 22c330f6f..baca05332 100644
--- a/tests/config/new.c
+++ b/tests/config/new.c
@@ -22,10 +22,10 @@ void test_config_new__write_new_config(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
- cl_assert_equal_s("auto", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("auto", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
- cl_assert_equal_s("ed", git_buf_cstr(&buf));
+ cl_assert_equal_s("ed", buf.ptr);
git_buf_dispose(&buf);
git_config_free(config);
diff --git a/tests/config/read.c b/tests/config/read.c
index 8d1bb8b0a..77f8a1262 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
static git_buf buf = GIT_BUF_INIT;
@@ -36,11 +35,11 @@ void test_config_read__case_sensitive(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
- cl_assert_equal_s("true", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("true", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
- cl_assert_equal_s("yes", git_buf_cstr(&buf));
+ cl_assert_equal_s("yes", buf.ptr);
cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
@@ -64,7 +63,7 @@ void test_config_read__multiline_value(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
- cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
+ cl_assert_equal_s("one one one two two three three", buf.ptr);
git_config_free(cfg);
}
@@ -84,7 +83,7 @@ void test_config_read__multiline_value_and_eof(void)
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
- cl_assert_equal_s("foo", git_buf_cstr(&buf));
+ cl_assert_equal_s("foo", buf.ptr);
git_config_free(cfg);
}
@@ -98,7 +97,7 @@ void test_config_read__multiline_eof(void)
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
git_config_free(cfg);
}
@@ -113,7 +112,7 @@ void test_config_read__subsection_header(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
- cl_assert_equal_s("hello", git_buf_cstr(&buf));
+ cl_assert_equal_s("hello", buf.ptr);
/* The subsection is transformed to lower-case */
cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
@@ -131,14 +130,14 @@ void test_config_read__lone_variable(void)
cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
cl_assert(i == 0);
@@ -234,11 +233,11 @@ void test_config_read__prefixes(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
- cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("http://example.com/git/ab", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
- cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
+ cl_assert_equal_s("http://example.com/git/abba", buf.ptr);
git_config_free(cfg);
}
@@ -249,7 +248,7 @@ void test_config_read__escaping_quotes(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
- cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
+ cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", buf.ptr);
git_config_free(cfg);
}
@@ -446,11 +445,11 @@ void test_config_read__whitespace_not_required_around_assignment(void)
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
- cl_assert_equal_s("c", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("c", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
- cl_assert_equal_s("f", git_buf_cstr(&buf));
+ cl_assert_equal_s("f", buf.ptr);
git_config_free(cfg);
}
@@ -596,7 +595,7 @@ void test_config_read__simple_read_from_specific_level(void)
cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ cl_assert_equal_s("I'm a global config value!", buf.ptr);
git_config_free(cfg_specific);
git_config_free(cfg);
@@ -692,7 +691,7 @@ void test_config_read__override_variable(void)
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
- cl_assert_equal_s("two", git_buf_cstr(&buf));
+ cl_assert_equal_s("two", buf.ptr);
git_config_free(cfg);
}
@@ -702,8 +701,8 @@ void test_config_read__path(void)
git_config *cfg;
git_buf path = GIT_BUF_INIT;
git_buf old_path = GIT_BUF_INIT;
- git_buf home_path = GIT_BUF_INIT;
- git_buf expected_path = GIT_BUF_INIT;
+ git_str home_path = GIT_STR_INIT;
+ git_str expected_path = GIT_STR_INIT;
cl_git_pass(p_mkdir("fakehome", 0777));
cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL));
@@ -725,7 +724,7 @@ void test_config_read__path(void)
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~");
- cl_git_pass(git_buf_sets(&expected_path, home_path.ptr));
+ cl_git_pass(git_str_sets(&expected_path, home_path.ptr));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
@@ -736,8 +735,8 @@ void test_config_read__path(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr));
git_buf_dispose(&old_path);
- git_buf_dispose(&home_path);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&home_path);
+ git_str_dispose(&expected_path);
git_config_free(cfg);
}
@@ -884,18 +883,18 @@ void test_config_read__single_line(void)
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"]var = value");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
diff --git a/tests/config/stress.c b/tests/config/stress.c
index 577452e8d..7ec274b18 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -41,9 +41,9 @@ void test_config_stress__dont_break_on_invalid_input(void)
void assert_config_value(git_config *config, const char *key, const char *value)
{
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, config, key));
- cl_assert_equal_s(value, git_buf_cstr(&buf));
+ cl_assert_equal_s(value, buf.ptr);
}
void test_config_stress__comments(void)
diff --git a/tests/config/write.c b/tests/config/write.c
index 78ed7f15b..4ee83833f 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/sys/config.h"
#include "config.h"
@@ -290,7 +289,7 @@ void test_config_write__write_subsection(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "my.own.var"));
- cl_assert_equal_s("works", git_buf_cstr(&buf));
+ cl_assert_equal_s("works", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
@@ -313,27 +312,27 @@ void test_config_write__value_containing_quotes(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this \"has\" quotes", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this \"has\" quotes", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
/* The code path for values that already exist is different, check that one as well */
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this also \"has\" quotes", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
+ cl_assert_equal_s("this also \"has\" quotes", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
}
@@ -346,13 +345,13 @@ void test_config_write__escape_value(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("this \"has\" quotes and \t", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
- cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
+ cl_assert_equal_s("this \"has\" quotes and \t", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
}
@@ -390,7 +389,7 @@ void test_config_write__add_value_at_specific_level(void)
cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ cl_assert_equal_s("I'm a global config value!", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
@@ -553,7 +552,7 @@ void test_config_write__preserves_whitespace_and_comments(void)
const char *file_name = "config-duplicate-header";
const char *n;
git_config *cfg;
- git_buf newfile = GIT_BUF_INIT;
+ git_str newfile = GIT_STR_INIT;
/* This config can occur after removing and re-adding the origin remote */
const char *file_content = SECTION_FOO_WITH_COMMENT SECTION_BAR;
@@ -580,7 +579,7 @@ void test_config_write__preserves_whitespace_and_comments(void)
cl_assert_equal_s("[newsection]\n\tnewname = new_value\n", n);
- git_buf_dispose(&newfile);
+ git_str_dispose(&newfile);
git_config_free(cfg);
}
@@ -588,7 +587,7 @@ void test_config_write__preserves_entry_with_name_only(void)
{
const char *file_name = "config-empty-value";
git_config *cfg;
- git_buf newfile = GIT_BUF_INIT;
+ git_str newfile = GIT_STR_INIT;
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, "[section \"foo\"]\n\tname\n");
@@ -599,7 +598,7 @@ void test_config_write__preserves_entry_with_name_only(void)
cl_git_pass(git_futils_readbuffer(&newfile, file_name));
cl_assert_equal_s("[section \"foo\"]\n\tname\n\tother = otherval\n[newsection]\n\tnewname = new_value\n", newfile.ptr);
- git_buf_dispose(&newfile);
+ git_str_dispose(&newfile);
git_config_free(cfg);
}
@@ -607,7 +606,7 @@ void test_config_write__to_empty_file(void)
{
git_config *cfg;
const char *filename = "config-file";
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
cl_git_mkfile(filename, "");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
@@ -617,14 +616,14 @@ void test_config_write__to_empty_file(void)
cl_git_pass(git_futils_readbuffer(&result, "config-file"));
cl_assert_equal_s("[section]\n\tname = value\n", result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
}
void test_config_write__to_file_with_only_comment(void)
{
git_config *cfg;
const char *filename = "config-file";
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
cl_git_mkfile(filename, "\n\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
@@ -634,7 +633,7 @@ void test_config_write__to_file_with_only_comment(void)
cl_git_pass(git_futils_readbuffer(&result, "config-file"));
cl_assert_equal_s("\n\n[section]\n\tname = value\n", result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
}
void test_config_write__locking(void)
@@ -699,7 +698,7 @@ void test_config_write__repeated(void)
{
const char *filename = "config-repeated";
git_config *cfg;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
const char *expected = "[sample \"prefix\"]\n\
\tsetting1 = someValue1\n\
\tsetting2 = someValue2\n\
@@ -717,7 +716,7 @@ void test_config_write__repeated(void)
cl_git_pass(git_futils_readbuffer(&result, filename));
cl_assert_equal_s(expected, result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_config_free(cfg);
}
@@ -726,7 +725,7 @@ void test_config_write__preserve_case(void)
{
const char *filename = "config-preserve-case";
git_config *cfg;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
const char *expected = "[sOMe]\n" \
"\tThInG = foo\n" \
"\tOtheR = thing\n";
@@ -740,7 +739,7 @@ void test_config_write__preserve_case(void)
cl_git_pass(git_futils_readbuffer(&result, filename));
cl_assert_equal_s(expected, result.ptr);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_config_free(cfg);
}
diff --git a/tests/core/buf.c b/tests/core/buf.c
new file mode 100644
index 000000000..3959fa883
--- /dev/null
+++ b/tests/core/buf.c
@@ -0,0 +1,54 @@
+#include "clar_libgit2.h"
+#include "buf.h"
+
+void test_core_buf__sanitize(void)
+{
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_sanitize(&buf));
+ cl_assert_equal_s(buf.ptr, "");
+ cl_assert_equal_i(buf.reserved, 0);
+ cl_assert_equal_i(buf.size, 0);
+
+ git_buf_dispose(&buf);
+}
+
+void test_core_buf__tostr(void)
+{
+ git_str str = GIT_STR_INIT;
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_tostr(&str, &buf));
+
+ cl_assert_equal_s(buf.ptr, "");
+ cl_assert_equal_i(buf.reserved, 0);
+ cl_assert_equal_i(buf.size, 0);
+
+ cl_assert_equal_s(str.ptr, "");
+ cl_assert_equal_i(str.asize, 0);
+ cl_assert_equal_i(str.size, 0);
+
+ git_buf_dispose(&buf);
+ git_str_dispose(&str);
+}
+
+void test_core_buf__fromstr(void)
+{
+ git_str str = GIT_STR_INIT;
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_tostr(&str, &buf));
+ cl_git_pass(git_str_puts(&str, "Hello, world."));
+ cl_git_pass(git_buf_fromstr(&buf, &str));
+
+ cl_assert(buf.reserved > 14);
+ cl_assert_equal_i(buf.size, 13);
+ cl_assert_equal_s(buf.ptr, "Hello, world.");
+
+ cl_assert_equal_s(str.ptr, "");
+ cl_assert_equal_i(str.asize, 0);
+ cl_assert_equal_i(str.size, 0);
+
+ git_buf_dispose(&buf);
+ git_str_dispose(&str);
+}
diff --git a/tests/core/dirent.c b/tests/core/dirent.c
index 08e0b11cf..ce93e0358 100644
--- a/tests/core/dirent.c
+++ b/tests/core/dirent.c
@@ -9,7 +9,7 @@ typedef struct name_data {
typedef struct walk_data {
char *sub; /* sub-directory name */
name_data *names; /* name state data */
- git_buf path;
+ git_str path;
} walk_data;
@@ -27,7 +27,7 @@ static void setup(walk_data *d)
if (strcmp(d->sub, ".") != 0)
cl_must_pass(p_mkdir(d->sub, 0777));
- cl_git_pass(git_buf_sets(&d->path, d->sub));
+ cl_git_pass(git_str_sets(&d->path, d->sub));
state_loc = d;
@@ -55,7 +55,7 @@ static void dirent_cleanup__cb(void *_d)
cl_must_pass(p_rmdir(top_dir));
- git_buf_dispose(&d->path);
+ git_str_dispose(&d->path);
}
static void check_counts(walk_data *d)
@@ -81,7 +81,7 @@ static int update_count(name_data *data, const char *name)
return GIT_ERROR;
}
-static int one_entry(void *state, git_buf *path)
+static int one_entry(void *state, git_str *path)
{
walk_data *d = (walk_data *) state;
@@ -104,7 +104,7 @@ static name_data dot_names[] = {
static walk_data dot = {
".",
dot_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that the '.' folder is not traversed */
@@ -128,7 +128,7 @@ static name_data sub_names[] = {
static walk_data sub = {
"sub",
sub_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* traverse a subfolder */
@@ -146,7 +146,7 @@ void test_core_dirent__traverse_subfolder(void)
static walk_data sub_slash = {
"sub/",
sub_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* traverse a slash-terminated subfolder */
@@ -167,7 +167,7 @@ static name_data empty_names[] = {
static walk_data empty = {
"empty",
empty_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that empty folders are not traversed */
@@ -195,7 +195,7 @@ static name_data odd_names[] = {
static walk_data odd = {
"odd",
odd_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that strange looking filenames ('..c') are traversed */
diff --git a/tests/core/env.c b/tests/core/env.c
index 3c34b2c4d..9a3f0ae76 100644
--- a/tests/core/env.c
+++ b/tests/core/env.c
@@ -83,7 +83,7 @@ static void setenv_and_check(const char *name, const char *value)
void test_core_env__0(void)
{
- git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, found = GIT_STR_INIT;
char testfile[16], tidx = '0';
char **val;
const char *testname = "testfile";
@@ -110,9 +110,9 @@ void test_core_env__0(void)
* accidentally make this test pass...
*/
testfile[testlen] = tidx++;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
cl_git_mkfile(path.ptr, "find me");
- git_buf_rtruncate_at_char(&path, '/');
+ git_str_rtruncate_at_char(&path, '/');
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(&found, testfile));
@@ -162,14 +162,14 @@ void test_core_env__0(void)
(void)p_rmdir(*val);
}
- git_buf_dispose(&path);
- git_buf_dispose(&found);
+ git_str_dispose(&path);
+ git_str_dispose(&found);
}
void test_core_env__1(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(&path, "nonexistentfile"));
@@ -206,21 +206,21 @@ void test_core_env__1(void)
GIT_ENOTFOUND, git_sysdir_find_system_file(&path, "nonexistentfile"));
#endif
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void check_global_searchpath(
- const char *path, int position, const char *file, git_buf *temp)
+ const char *path, int position, const char *file, git_str *temp)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
/* build and set new path */
if (position < 0)
- cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
+ cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
else if (position > 0)
- cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
+ cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
else
- cl_git_pass(git_buf_sets(temp, path));
+ cl_git_pass(git_str_sets(temp, path));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, temp->ptr));
@@ -245,12 +245,12 @@ static void check_global_searchpath(
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(temp, file));
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
void test_core_env__2(void)
{
- git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, found = GIT_STR_INIT;
char testfile[16], tidx = '0';
char **val;
const char *testname = "alternate";
@@ -276,9 +276,9 @@ void test_core_env__2(void)
* deleting files won't accidentally make a test pass.
*/
testfile[testlen] = tidx++;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
cl_git_mkfile(path.ptr, "find me");
- git_buf_rtruncate_at_char(&path, '/');
+ git_str_rtruncate_at_char(&path, '/');
/* default should be NOTFOUND */
cl_assert_equal_i(
@@ -290,32 +290,32 @@ void test_core_env__2(void)
check_global_searchpath(path.ptr, 1, testfile, &found);
/* cleanup */
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
(void)p_unlink(path.ptr);
(void)p_rmdir(*val);
}
- git_buf_dispose(&path);
- git_buf_dispose(&found);
+ git_str_dispose(&path);
+ git_str_dispose(&found);
}
void test_core_env__substitution(void)
{
- git_buf buf = GIT_BUF_INIT, expected = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, expected = GIT_STR_INIT;
/* Set it to something non-default so we have controllable values */
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "/tmp/a"));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
cl_assert_equal_s("/tmp/a", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, buf.ptr));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
- cl_git_pass(git_buf_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
+ cl_git_pass(git_str_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
cl_assert_equal_s(expected.ptr, buf.ptr);
- git_buf_dispose(&expected);
- git_buf_dispose(&buf);
+ git_str_dispose(&expected);
+ git_str_dispose(&buf);
}
diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c
index e527ce97c..6f654f523 100644
--- a/tests/core/filebuf.c
+++ b/tests/core/filebuf.c
@@ -189,13 +189,13 @@ void test_core_filebuf__symlink_follow(void)
void test_core_filebuf__symlink_follow_absolute_paths(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT;
+ git_str source = GIT_STR_INIT, target = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip();
- cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
- cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
+ cl_git_pass(git_str_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
+ cl_git_pass(git_str_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
cl_git_pass(p_mkdir("linkdir", 0777));
cl_git_pass(p_symlink(target.ptr, source.ptr));
@@ -208,8 +208,8 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
cl_assert_equal_i(true, git_path_exists("linkdir/target"));
git_filebuf_cleanup(&file);
- git_buf_dispose(&source);
- git_buf_dispose(&target);
+ git_str_dispose(&source);
+ git_str_dispose(&target);
cl_git_pass(git_futils_rmdir_r("linkdir", NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/core/futils.c b/tests/core/futils.c
index 2c8294c87..d08043b6e 100644
--- a/tests/core/futils.c
+++ b/tests/core/futils.c
@@ -14,27 +14,27 @@ void test_core_futils__cleanup(void)
void test_core_futils__writebuffer(void)
{
- git_buf out = GIT_BUF_INIT,
- append = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT,
+ append = GIT_STR_INIT;
/* create a new file */
- git_buf_puts(&out, "hello!\n");
- git_buf_printf(&out, "this is a %s\n", "test");
+ git_str_puts(&out, "hello!\n");
+ git_str_printf(&out, "this is a %s\n", "test");
cl_git_pass(git_futils_writebuffer(&out, "futils/test-file", O_RDWR|O_CREAT, 0666));
cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
/* append some more data */
- git_buf_puts(&append, "And some more!\n");
- git_buf_put(&out, append.ptr, append.size);
+ git_str_puts(&append, "And some more!\n");
+ git_str_put(&out, append.ptr, append.size);
cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR|O_APPEND, 0666));
cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
- git_buf_dispose(&out);
- git_buf_dispose(&append);
+ git_str_dispose(&out);
+ git_str_dispose(&append);
}
void test_core_futils__write_hidden_file(void)
@@ -42,17 +42,17 @@ void test_core_futils__write_hidden_file(void)
#ifndef GIT_WIN32
cl_skip();
#else
- git_buf out = GIT_BUF_INIT, append = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT, append = GIT_STR_INIT;
bool hidden;
- git_buf_puts(&out, "hidden file.\n");
+ git_str_puts(&out, "hidden file.\n");
git_futils_writebuffer(&out, "futils/test-file", O_RDWR | O_CREAT, 0666);
cl_git_pass(git_win32__set_hidden("futils/test-file", true));
/* append some more data */
- git_buf_puts(&append, "And some more!\n");
- git_buf_put(&out, append.ptr, append.size);
+ git_str_puts(&append, "And some more!\n");
+ git_str_put(&out, append.ptr, append.size);
cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR | O_APPEND, 0666));
@@ -61,8 +61,8 @@ void test_core_futils__write_hidden_file(void)
cl_git_pass(git_win32__hidden(&hidden, "futils/test-file"));
cl_assert(hidden);
- git_buf_dispose(&out);
- git_buf_dispose(&append);
+ git_str_dispose(&out);
+ git_str_dispose(&append);
#endif
}
diff --git a/tests/core/buffer.c b/tests/core/gitstr.c
index 2af4a8712..0a624e28c 100644
--- a/tests/core/buffer.c
+++ b/tests/core/gitstr.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "git2/sys/hashsig.h"
#include "futils.h"
@@ -13,205 +12,205 @@ const char *test_4096 = TESTSTR_4096;
const char *test_8192 = TESTSTR_8192;
/* test basic data concatenation */
-void test_core_buffer__0(void)
+void test_core_gitstr__0(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_assert(buf.size == 0);
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string_x2, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-/* test git_buf_printf */
-void test_core_buffer__1(void)
+/* test git_str_printf */
+void test_core_gitstr__1(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("shoop da 23 ", git_buf_cstr(&buf));
+ git_str_printf(&buf, "%s %s %d ", "shoop", "da", 23);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("shoop da 23 ", git_str_cstr(&buf));
- git_buf_printf(&buf, "%s %d", "woop", 42);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("shoop da 23 woop 42", git_buf_cstr(&buf));
+ git_str_printf(&buf, "%s %d", "woop", 42);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("shoop da 23 woop 42", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
/* more thorough test of concatenation options */
-void test_core_buffer__2(void)
+void test_core_gitstr__2(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int i;
char data[128];
cl_assert(buf.size == 0);
/* this must be safe to do */
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_assert(buf.size == 0);
cl_assert(buf.asize == 0);
/* empty buffer should be empty string */
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", git_str_cstr(&buf));
cl_assert(buf.size == 0);
- /* cl_assert(buf.asize == 0); -- should not assume what git_buf does */
+ /* cl_assert(buf.asize == 0); -- should not assume what git_str does */
/* free should set us back to the beginning */
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_assert(buf.size == 0);
cl_assert(buf.asize == 0);
/* add letter */
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("+", git_buf_cstr(&buf));
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("+", git_str_cstr(&buf));
/* add letter again */
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("++", git_buf_cstr(&buf));
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("++", git_str_cstr(&buf));
/* let's try that a few times */
for (i = 0; i < 16; ++i) {
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
}
- cl_assert_equal_s("++++++++++++++++++", git_buf_cstr(&buf));
+ cl_assert_equal_s("++++++++++++++++++", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* add data */
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("xo", git_buf_cstr(&buf));
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("xo", git_str_cstr(&buf));
/* add letter again */
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("xoxo", git_buf_cstr(&buf));
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("xoxo", git_str_cstr(&buf));
/* let's try that a few times */
for (i = 0; i < 16; ++i) {
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
}
cl_assert_equal_s("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo",
- git_buf_cstr(&buf));
+ git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* set to string */
- git_buf_sets(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
+ git_str_sets(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
/* append string */
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string_x2, git_str_cstr(&buf));
/* set to string again (should overwrite - not append) */
- git_buf_sets(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
+ git_str_sets(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
/* test clear */
- git_buf_clear(&buf);
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ git_str_clear(&buf);
+ cl_assert_equal_s("", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* test extracting data into buffer */
- git_buf_puts(&buf, REP4("0123456789"));
- cl_assert(git_buf_oom(&buf) == 0);
+ git_str_puts(&buf, REP4("0123456789"));
+ cl_assert(git_str_oom(&buf) == 0);
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_copy_cstr(data, sizeof(data), &buf);
cl_assert_equal_s(REP4("0123456789"), data);
- git_buf_copy_cstr(data, 11, &buf);
+ git_str_copy_cstr(data, 11, &buf);
cl_assert_equal_s("0123456789", data);
- git_buf_copy_cstr(data, 3, &buf);
+ git_str_copy_cstr(data, 3, &buf);
cl_assert_equal_s("01", data);
- git_buf_copy_cstr(data, 1, &buf);
+ git_str_copy_cstr(data, 1, &buf);
cl_assert_equal_s("", data);
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_copy_cstr(data, sizeof(data), &buf);
cl_assert_equal_s(REP4("0123456789"), data);
- git_buf_sets(&buf, REP256("x"));
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_sets(&buf, REP256("x"));
+ git_str_copy_cstr(data, sizeof(data), &buf);
/* since sizeof(data) == 128, only 127 bytes should be copied */
cl_assert_equal_s(REP4(REP16("x")) REP16("x") REP16("x")
REP16("x") "xxxxxxxxxxxxxxx", data);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_copy_cstr(data, sizeof(data), &buf);
cl_assert_equal_s("", data);
}
/* let's do some tests with larger buffers to push our limits */
-void test_core_buffer__3(void)
+void test_core_gitstr__3(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* set to string */
- git_buf_set(&buf, test_4096, 4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
+ git_str_set(&buf, test_4096, 4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_4096, git_str_cstr(&buf));
/* append string */
- git_buf_puts(&buf, test_4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_8192, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_8192, git_str_cstr(&buf));
/* set to string again (should overwrite - not append) */
- git_buf_set(&buf, test_4096, 4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
+ git_str_set(&buf, test_4096, 4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_4096, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
/* let's try some producer/consumer tests */
-void test_core_buffer__4(void)
+void test_core_gitstr__4(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int i;
for (i = 0; i < 10; ++i) {
- git_buf_puts(&buf, "1234"); /* add 4 */
- cl_assert(git_buf_oom(&buf) == 0);
- git_buf_consume(&buf, buf.ptr + 2); /* eat the first two */
- cl_assert(strlen(git_buf_cstr(&buf)) == (size_t)((i + 1) * 2));
+ git_str_puts(&buf, "1234"); /* add 4 */
+ cl_assert(git_str_oom(&buf) == 0);
+ git_str_consume(&buf, buf.ptr + 2); /* eat the first two */
+ cl_assert(strlen(git_str_cstr(&buf)) == (size_t)((i + 1) * 2));
}
/* we have appended 1234 10x and removed the first 20 letters */
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, NULL);
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, NULL);
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, "invalid pointer");
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, "invalid pointer");
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, buf.ptr);
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, buf.ptr);
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, buf.ptr + 1);
- cl_assert_equal_s("2341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, buf.ptr + 1);
+ cl_assert_equal_s("2341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, buf.ptr + buf.size);
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ git_str_consume(&buf, buf.ptr + buf.size);
+ cl_assert_equal_s("", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
@@ -223,18 +222,18 @@ check_buf_append(
size_t expected_size,
size_t expected_asize)
{
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- git_buf_sets(&tgt, data_a);
- cl_assert(git_buf_oom(&tgt) == 0);
- git_buf_puts(&tgt, data_b);
- cl_assert(git_buf_oom(&tgt) == 0);
- cl_assert_equal_s(expected_data, git_buf_cstr(&tgt));
+ git_str_sets(&tgt, data_a);
+ cl_assert(git_str_oom(&tgt) == 0);
+ git_str_puts(&tgt, data_b);
+ cl_assert(git_str_oom(&tgt) == 0);
+ cl_assert_equal_s(expected_data, git_str_cstr(&tgt));
cl_assert_equal_i(tgt.size, expected_size);
if (expected_asize > 0)
cl_assert_equal_i(tgt.asize, expected_asize);
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
}
static void
@@ -248,37 +247,37 @@ check_buf_append_abc(
const char* expected_abcab,
const char* expected_abcabc)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_sets(&buf, buf_a);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(buf_a, git_buf_cstr(&buf));
+ git_str_sets(&buf, buf_a);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(buf_a, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_ab, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_ab, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_c);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abc, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_c);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abc, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_a);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abca, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_a);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abca, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abcab, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abcab, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_c);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abcabc, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_c);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abcabc, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
/* more variations on append tests */
-void test_core_buffer__5(void)
+void test_core_gitstr__5(void)
{
check_buf_append("", "", "", 0, 0);
check_buf_append("a", "", "a", 1, 0);
@@ -321,70 +320,70 @@ void test_core_buffer__5(void)
}
/* test swap */
-void test_core_buffer__6(void)
+void test_core_gitstr__6(void)
{
- git_buf a = GIT_BUF_INIT;
- git_buf b = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
+ git_str b = GIT_STR_INIT;
- git_buf_sets(&a, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- git_buf_sets(&b, "bar");
- cl_assert(git_buf_oom(&b) == 0);
+ git_str_sets(&a, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ git_str_sets(&b, "bar");
+ cl_assert(git_str_oom(&b) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
- cl_assert_equal_s("bar", git_buf_cstr(&b));
+ cl_assert_equal_s("foo", git_str_cstr(&a));
+ cl_assert_equal_s("bar", git_str_cstr(&b));
- git_buf_swap(&a, &b);
+ git_str_swap(&a, &b);
- cl_assert_equal_s("bar", git_buf_cstr(&a));
- cl_assert_equal_s("foo", git_buf_cstr(&b));
+ cl_assert_equal_s("bar", git_str_cstr(&a));
+ cl_assert_equal_s("foo", git_str_cstr(&b));
- git_buf_dispose(&a);
- git_buf_dispose(&b);
+ git_str_dispose(&a);
+ git_str_dispose(&b);
}
/* test detach/attach data */
-void test_core_buffer__7(void)
+void test_core_gitstr__7(void)
{
const char *fun = "This is fun";
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
char *b = NULL;
- git_buf_sets(&a, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
+ git_str_sets(&a, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo", git_str_cstr(&a));
- b = git_buf_detach(&a);
+ b = git_str_detach(&a);
cl_assert_equal_s("foo", b);
cl_assert_equal_s("", a.ptr);
git__free(b);
- b = git_buf_detach(&a);
+ b = git_str_detach(&a);
cl_assert_equal_s(NULL, b);
cl_assert_equal_s("", a.ptr);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
b = git__strdup(fun);
- git_buf_attach(&a, b, 0);
+ git_str_attach(&a, b, 0);
cl_assert_equal_s(fun, a.ptr);
cl_assert(a.size == strlen(fun));
cl_assert(a.asize == strlen(fun) + 1);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
b = git__strdup(fun);
- git_buf_attach(&a, b, strlen(fun) + 1);
+ git_str_attach(&a, b, strlen(fun) + 1);
cl_assert_equal_s(fun, a.ptr);
cl_assert(a.size == strlen(fun));
cl_assert(a.asize == strlen(fun) + 1);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
@@ -395,12 +394,12 @@ check_joinbuf_2(
const char *expected)
{
char sep = '/';
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_join(&buf, sep, a, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_join(&buf, sep, a, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
}
static void
@@ -411,13 +410,13 @@ check_joinbuf_overlapped(
const char *expected)
{
char sep = '/';
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_sets(&buf, oldval);
- git_buf_join(&buf, sep, buf.ptr + ofs_a, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_sets(&buf, oldval);
+ git_str_join(&buf, sep, buf.ptr + ofs_a, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
}
static void
@@ -427,16 +426,16 @@ check_joinbuf_n_2(
const char *expected)
{
char sep = '/';
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_sets(&buf, a);
- cl_assert(git_buf_oom(&buf) == 0);
+ git_str_sets(&buf, a);
+ cl_assert(git_str_oom(&buf) == 0);
- git_buf_join_n(&buf, sep, 1, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ git_str_join_n(&buf, sep, 1, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void
@@ -448,31 +447,31 @@ check_joinbuf_n_4(
const char *expected)
{
char sep = ';';
- git_buf buf = GIT_BUF_INIT;
- git_buf_join_n(&buf, sep, 4, a, b, c, d);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str buf = GIT_STR_INIT;
+ git_str_join_n(&buf, sep, 4, a, b, c, d);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
}
/* test join */
-void test_core_buffer__8(void)
+void test_core_gitstr__8(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- git_buf_join_n(&a, '/', 1, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
+ git_str_join_n(&a, '/', 1, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo", git_str_cstr(&a));
- git_buf_join_n(&a, '/', 1, "bar");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo/bar", git_buf_cstr(&a));
+ git_str_join_n(&a, '/', 1, "bar");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo/bar", git_str_cstr(&a));
- git_buf_join_n(&a, '/', 1, "baz");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo/bar/baz", git_buf_cstr(&a));
+ git_str_join_n(&a, '/', 1, "baz");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo/bar/baz", git_str_cstr(&a));
- git_buf_dispose(&a);
+ git_str_dispose(&a);
check_joinbuf_2(NULL, "", "");
check_joinbuf_2(NULL, "a", "a");
@@ -537,9 +536,9 @@ void test_core_buffer__8(void)
check_joinbuf_n_4(";abcd;", ";efgh;", ";ijkl;", ";mnop;", ";abcd;efgh;ijkl;mnop;");
}
-void test_core_buffer__9(void)
+void test_core_gitstr__9(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* just some exhaustive tests of various separator placement */
char *a[] = { "", "-", "a-", "-a", "-a-" };
@@ -570,68 +569,68 @@ void test_core_buffer__9(void)
for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {
for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {
- git_buf_join(&buf, separator, a[i], b[j]);
+ git_str_join(&buf, separator, a[i], b[j]);
cl_assert_equal_s(*expect, buf.ptr);
expect++;
}
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__10(void)
+void test_core_gitstr__10(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&a, '/', 1, "test"));
+ cl_git_pass(git_str_join_n(&a, '/', 1, "test"));
cl_assert_equal_s(a.ptr, "test");
- cl_git_pass(git_buf_join_n(&a, '/', 1, "string"));
+ cl_git_pass(git_str_join_n(&a, '/', 1, "string"));
cl_assert_equal_s(a.ptr, "test/string");
- git_buf_clear(&a);
- cl_git_pass(git_buf_join_n(&a, '/', 3, "test", "string", "join"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_join_n(&a, '/', 3, "test", "string", "join"));
cl_assert_equal_s(a.ptr, "test/string/join");
- cl_git_pass(git_buf_join_n(&a, '/', 2, a.ptr, "more"));
+ cl_git_pass(git_str_join_n(&a, '/', 2, a.ptr, "more"));
cl_assert_equal_s(a.ptr, "test/string/join/test/string/join/more");
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__join3(void)
+void test_core_gitstr__join3(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- cl_git_pass(git_buf_join3(&a, '/', "test", "string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test", "string", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "string", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string/", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string/", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string/", "/join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string/", "/join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "", "string", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string/", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "", "string/", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string/", "/join"));
+ cl_git_pass(git_str_join3(&a, '/', "", "string/", "/join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string", "", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "string", "", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string/", "", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "string/", "", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string/", "", "/join"));
+ cl_git_pass(git_str_join3(&a, '/', "string/", "", "/join"));
cl_assert_equal_s("string/join", a.ptr);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__11(void)
+void test_core_gitstr__11(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
char *t1[] = { "nothing", "in", "common" };
char *t2[] = { "something", "something else", "some other" };
char *t3[] = { "something", "some fun", "no fun" };
@@ -640,89 +639,89 @@ void test_core_buffer__11(void)
char *t6[] = { "no", "nope", "" };
char *t7[] = { "", "doesn't matter" };
- cl_git_pass(git_buf_common_prefix(&a, t1, 3));
+ cl_git_pass(git_str_common_prefix(&a, t1, 3));
cl_assert_equal_s(a.ptr, "");
- cl_git_pass(git_buf_common_prefix(&a, t2, 3));
+ cl_git_pass(git_str_common_prefix(&a, t2, 3));
cl_assert_equal_s(a.ptr, "some");
- cl_git_pass(git_buf_common_prefix(&a, t3, 3));
+ cl_git_pass(git_str_common_prefix(&a, t3, 3));
cl_assert_equal_s(a.ptr, "");
- cl_git_pass(git_buf_common_prefix(&a, t4, 3));
+ cl_git_pass(git_str_common_prefix(&a, t4, 3));
cl_assert_equal_s(a.ptr, "happ");
- cl_git_pass(git_buf_common_prefix(&a, t5, 3));
+ cl_git_pass(git_str_common_prefix(&a, t5, 3));
cl_assert_equal_s(a.ptr, "happ");
- cl_git_pass(git_buf_common_prefix(&a, t6, 3));
+ cl_git_pass(git_str_common_prefix(&a, t6, 3));
cl_assert_equal_s(a.ptr, "");
- cl_git_pass(git_buf_common_prefix(&a, t7, 3));
+ cl_git_pass(git_str_common_prefix(&a, t7, 3));
cl_assert_equal_s(a.ptr, "");
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__rfind_variants(void)
+void test_core_gitstr__rfind_variants(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
ssize_t len;
- cl_git_pass(git_buf_sets(&a, "/this/is/it/"));
+ cl_git_pass(git_str_sets(&a, "/this/is/it/"));
- len = (ssize_t)git_buf_len(&a);
+ len = (ssize_t)git_str_len(&a);
- cl_assert(git_buf_rfind(&a, '/') == len - 1);
- cl_assert(git_buf_rfind_next(&a, '/') == len - 4);
+ cl_assert(git_str_rfind(&a, '/') == len - 1);
+ cl_assert(git_str_rfind_next(&a, '/') == len - 4);
- cl_assert(git_buf_rfind(&a, 'i') == len - 3);
- cl_assert(git_buf_rfind_next(&a, 'i') == len - 3);
+ cl_assert(git_str_rfind(&a, 'i') == len - 3);
+ cl_assert(git_str_rfind_next(&a, 'i') == len - 3);
- cl_assert(git_buf_rfind(&a, 'h') == 2);
- cl_assert(git_buf_rfind_next(&a, 'h') == 2);
+ cl_assert(git_str_rfind(&a, 'h') == 2);
+ cl_assert(git_str_rfind_next(&a, 'h') == 2);
- cl_assert(git_buf_rfind(&a, 'q') == -1);
- cl_assert(git_buf_rfind_next(&a, 'q') == -1);
+ cl_assert(git_str_rfind(&a, 'q') == -1);
+ cl_assert(git_str_rfind_next(&a, 'q') == -1);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__puts_escaped(void)
+void test_core_gitstr__puts_escaped(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "", ""));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "", ""));
cl_assert_equal_s("this is a test", a.ptr);
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "t", "\\"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "t", "\\"));
cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "i ", "__"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "i ", "__"));
cl_assert_equal_s("th__is__ __is__ a__ test", a.ptr);
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
cl_assert_equal_s("\\^match\\\\s\\*\\[A-Z\\]\\+\\.\\*", a.ptr);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
static void assert_unescape(char *expected, char *to_unescape) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, to_unescape));
- git_buf_unescape(&buf);
+ cl_git_pass(git_str_sets(&buf, to_unescape));
+ git_str_unescape(&buf);
cl_assert_equal_s(expected, buf.ptr);
cl_assert_equal_sz(strlen(expected), buf.size);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__unescape(void)
+void test_core_gitstr__unescape(void)
{
assert_unescape("Escaped\\", "Es\\ca\\ped\\");
assert_unescape("Es\\caped\\", "Es\\\\ca\\ped\\\\");
@@ -731,9 +730,9 @@ void test_core_buffer__unescape(void)
assert_unescape("", "");
}
-void test_core_buffer__encode_base64(void)
+void test_core_gitstr__encode_base64(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* t h i s
* 0x 74 68 69 73
@@ -742,100 +741,100 @@ void test_core_buffer__encode_base64(void)
* 0x 1d 06 21 29 1c 30
* d G h p c w
*/
- cl_git_pass(git_buf_encode_base64(&buf, "this", 4));
+ cl_git_pass(git_str_encode_base64(&buf, "this", 4));
cl_assert_equal_s("dGhpcw==", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_encode_base64(&buf, "this!", 5));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_encode_base64(&buf, "this!", 5));
cl_assert_equal_s("dGhpcyE=", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_encode_base64(&buf, "this!\n", 6));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_encode_base64(&buf, "this!\n", 6));
cl_assert_equal_s("dGhpcyEK", buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__decode_base64(void)
+void test_core_gitstr__decode_base64(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcw==", 8));
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcw==", 8));
cl_assert_equal_s("this", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyE=", 8));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcyE=", 8));
cl_assert_equal_s("this!", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyEK", 8));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcyEK", 8));
cl_assert_equal_s("this!\n", buf.ptr);
- cl_git_fail(git_buf_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
+ cl_git_fail(git_str_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
cl_assert_equal_s("this!\n", buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__encode_base85(void)
+void test_core_gitstr__encode_base85(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_encode_base85(&buf, "this", 4));
+ cl_git_pass(git_str_encode_base85(&buf, "this", 4));
cl_assert_equal_s("bZBXF", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_encode_base85(&buf, "two rnds", 8));
+ cl_git_pass(git_str_encode_base85(&buf, "two rnds", 8));
cl_assert_equal_s("ba!tca&BaE", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_encode_base85(&buf, "this is base 85 encoded",
+ cl_git_pass(git_str_encode_base85(&buf, "this is base 85 encoded",
strlen("this is base 85 encoded")));
cl_assert_equal_s("bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__decode_base85(void)
+void test_core_gitstr__decode_base85(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_decode_base85(&buf, "bZBXF", 5, 4));
+ cl_git_pass(git_str_decode_base85(&buf, "bZBXF", 5, 4));
cl_assert_equal_sz(4, buf.size);
cl_assert_equal_s("this", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_decode_base85(&buf, "ba!tca&BaE", 10, 8));
+ cl_git_pass(git_str_decode_base85(&buf, "ba!tca&BaE", 10, 8));
cl_assert_equal_sz(8, buf.size);
cl_assert_equal_s("two rnds", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_decode_base85(&buf, "bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", 30, 23));
+ cl_git_pass(git_str_decode_base85(&buf, "bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", 30, 23));
cl_assert_equal_sz(23, buf.size);
cl_assert_equal_s("this is base 85 encoded", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__decode_base85_fails_gracefully(void)
+void test_core_gitstr__decode_base85_fails_gracefully(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_puts(&buf, "foobar");
+ git_str_puts(&buf, "foobar");
- cl_git_fail(git_buf_decode_base85(&buf, "invalid charsZZ", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "invalidchars__ ", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "overflowZZ~~~~~", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "truncated", 9, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "invalid charsZZ", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "invalidchars__ ", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "overflowZZ~~~~~", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "truncated", 9, 42));
cl_assert_equal_sz(6, buf.size);
cl_assert_equal_s("foobar", buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__classify_with_utf8(void)
+void test_core_gitstr__classify_with_utf8(void)
{
char *data0 = "Simple text\n";
size_t data0len = 12;
@@ -845,23 +844,23 @@ void test_core_buffer__classify_with_utf8(void)
size_t data2len = 29;
char *data3 = "\xef\xbb\xbfThis is UTF-8 with a BOM.\n";
size_t data3len = 20;
- git_buf b;
+ git_str b;
b.ptr = data0; b.size = b.asize = data0len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
b.ptr = data1; b.size = b.asize = data1len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
b.ptr = data2; b.size = b.asize = data2len;
- cl_assert(git_buf_is_binary(&b));
- cl_assert(git_buf_contains_nul(&b));
+ cl_assert(git_str_is_binary(&b));
+ cl_assert(git_str_contains_nul(&b));
b.ptr = data3; b.size = b.asize = data3len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
}
#define SIMILARITY_TEST_DATA_1 \
@@ -871,15 +870,15 @@ void test_core_buffer__classify_with_utf8(void)
"030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \
"040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n"
-void test_core_buffer__similarity_metric(void)
+void test_core_gitstr__similarity_metric(void)
{
git_hashsig *a, *b;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int sim;
/* in the first case, we compare data to itself and expect 100% match */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
@@ -890,9 +889,9 @@ void test_core_buffer__similarity_metric(void)
/* if we change just a single byte, how much does that change magnify? */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf,
+ cl_git_pass(git_str_sets(&buf,
"000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
"010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
"x020x\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \
@@ -910,9 +909,9 @@ void test_core_buffer__similarity_metric(void)
/* let's try comparing data to a superset of itself */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1
"050\n051\n052\n053\n054\n055\n056\n057\n058\n059\n"));
cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
@@ -926,9 +925,9 @@ void test_core_buffer__similarity_metric(void)
/* what if we keep about half the original data and add half new */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf,
+ cl_git_pass(git_str_sets(&buf,
"000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
"010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
"020x\n021\n022\n023\n024\n" \
@@ -948,7 +947,7 @@ void test_core_buffer__similarity_metric(void)
/* lastly, let's check that we can hash file content as well */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH));
@@ -961,15 +960,15 @@ void test_core_buffer__similarity_metric(void)
git_hashsig_free(a);
git_hashsig_free(b);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES);
}
-void test_core_buffer__similarity_metric_whitespace(void)
+void test_core_gitstr__similarity_metric_whitespace(void)
{
git_hashsig *a, *b;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int sim, i, j;
git_hashsig_option_t opt;
const char *tabbed =
@@ -979,7 +978,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
"\n"
" for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
" for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\n"
" cl_assert_equal_s(*expect, buf.ptr);\n"
" expect++;\n"
" }\n"
@@ -992,7 +991,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
"\n"
" for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
" for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\n"
" cl_assert_equal_s(*expect, buf.ptr);\n"
" expect++;\n"
" }\n"
@@ -1005,7 +1004,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
"\r\n"
" for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n"
" for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\r\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\r\n"
" cl_assert_equal_s(*expect, buf.ptr);\r\n"
" expect++;\r\n"
" }\r\n"
@@ -1018,10 +1017,10 @@ void test_core_buffer__similarity_metric_whitespace(void)
for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) {
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
- cl_git_pass(git_buf_sets(&buf, text[i]));
+ cl_git_pass(git_str_sets(&buf, text[i]));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt));
- cl_git_pass(git_buf_sets(&buf, text[j]));
+ cl_git_pass(git_str_sets(&buf, text[j]));
cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt));
sim = git_hashsig_compare(a, b);
@@ -1041,7 +1040,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#include "../filter/crlf.h"
@@ -1050,177 +1049,177 @@ void test_core_buffer__similarity_metric_whitespace(void)
cl_assert_equal_s(expected, buf.ptr); \
cl_assert_equal_sz(strlen(expected), buf.size); } while (0)
-void test_core_buffer__lf_and_crlf_conversions(void)
+void test_core_gitstr__lf_and_crlf_conversions(void)
{
- git_buf src = GIT_BUF_INIT, tgt = GIT_BUF_INIT;
+ git_str src = GIT_STR_INIT, tgt = GIT_STR_INIT;
/* LF source */
- git_buf_sets(&src, "lf\nlf\nlf\nlf\n");
+ git_str_sets(&src, "lf\nlf\nlf\nlf\n");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("lf\r\nlf\r\nlf\r\nlf\r\n", tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(src.ptr, tgt);
- git_buf_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
+ git_str_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\nlf\r\nlf\r\nlf\r\nlf\r\nlf", tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(src.ptr, tgt);
/* CRLF source */
- git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+ git_str_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt);
- git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+ git_str_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt);
- git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+ git_str_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt);
- git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+ git_str_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt);
/* CRLF in LF text */
- git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+ git_str_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt);
- git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+ git_str_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt);
/* LF in CRLF text */
- git_buf_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
+ git_str_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt);
/* bare CR test */
- git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+ git_str_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt);
- git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+ git_str_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
- git_buf_sets(&src, "\rcr\r");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, "\rcr\r");
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(src.ptr, tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\rcr\r", tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
/* blob correspondence tests */
- git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(ALL_CRLF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
- git_buf_sets(&src, ALL_LF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(ALL_LF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, ALL_LF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(ALL_LF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
- git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(MORE_CRLF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
- git_buf_sets(&src, MORE_LF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(MORE_LF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, MORE_LF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(MORE_LF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
}
-void test_core_buffer__dont_grow_borrowed(void)
+void test_core_gitstr__dont_grow_borrowed(void)
{
const char *somestring = "blah blah";
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_attach_notowned(&buf, somestring, strlen(somestring) + 1);
+ git_str_attach_notowned(&buf, somestring, strlen(somestring) + 1);
cl_assert_equal_p(somestring, buf.ptr);
cl_assert_equal_i(0, buf.asize);
cl_assert_equal_i(strlen(somestring) + 1, buf.size);
- cl_git_fail_with(GIT_EINVALID, git_buf_grow(&buf, 1024));
+ cl_git_fail_with(GIT_EINVALID, git_str_grow(&buf, 1024));
}
-void test_core_buffer__dont_hit_infinite_loop_when_resizing(void)
+void test_core_gitstr__dont_hit_infinite_loop_when_resizing(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&buf, "foobar"));
+ cl_git_pass(git_str_puts(&buf, "foobar"));
/*
* We do not care whether this succeeds or fails, which
* would depend on platform-specific allocation
* semantics. We only want to know that the function
* actually returns.
*/
- (void)git_buf_try_grow(&buf, SIZE_MAX, true);
+ (void)git_str_try_grow(&buf, SIZE_MAX, true);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__avoid_printing_into_oom_buffer(void)
+void test_core_gitstr__avoid_printing_into_oom_buffer(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* Emulate OOM situation with a previous allocation */
buf.asize = 8;
- buf.ptr = git_buf__oom;
+ buf.ptr = git_str__oom;
/*
* Print the same string again. As the buffer still has
* an `asize` of 8 due to the previous print,
* `ENSURE_SIZE` would not try to reallocate the array at
- * all. As it didn't explicitly check for `git_buf__oom`
+ * all. As it didn't explicitly check for `git_str__oom`
* in earlier versions, this would've resulted in it
- * returning successfully and thus `git_buf_puts` would
- * just print into the `git_buf__oom` array.
+ * returning successfully and thus `git_str_puts` would
+ * just print into the `git_str__oom` array.
*/
- cl_git_fail(git_buf_puts(&buf, "foobar"));
+ cl_git_fail(git_str_puts(&buf, "foobar"));
}
diff --git a/tests/core/link.c b/tests/core/link.c
index 0493edf1d..6ab79b2a8 100644
--- a/tests/core/link.c
+++ b/tests/core/link.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "posix.h"
-#include "buffer.h"
#include "path.h"
#ifdef GIT_WIN32
@@ -82,7 +81,7 @@ static void do_junction(const char *old, const char *new)
{
GIT_REPARSE_DATA_BUFFER *reparse_buf;
HANDLE handle;
- git_buf unparsed_buf = GIT_BUF_INIT;
+ git_str unparsed_buf = GIT_STR_INIT;
wchar_t *subst_utf16, *print_utf16;
DWORD ioctl_ret;
int subst_utf16_len, subst_byte_len, print_utf16_len, print_byte_len, ret;
@@ -93,14 +92,14 @@ static void do_junction(const char *old, const char *new)
* backslashes instead of forward, and end in a trailing backslash.
* eg: \??\C:\Foo\
*/
- git_buf_puts(&unparsed_buf, "\\??\\");
+ git_str_puts(&unparsed_buf, "\\??\\");
for (i = 0; i < strlen(old); i++)
- git_buf_putc(&unparsed_buf, old[i] == '/' ? '\\' : old[i]);
+ git_str_putc(&unparsed_buf, old[i] == '/' ? '\\' : old[i]);
- git_buf_putc(&unparsed_buf, '\\');
+ git_str_putc(&unparsed_buf, '\\');
- subst_utf16_len = git__utf8_to_16(NULL, 0, git_buf_cstr(&unparsed_buf));
+ subst_utf16_len = git__utf8_to_16(NULL, 0, git_str_cstr(&unparsed_buf));
subst_byte_len = subst_utf16_len * sizeof(WCHAR);
print_utf16_len = subst_utf16_len - 4;
@@ -127,11 +126,11 @@ static void do_junction(const char *old, const char *new)
print_utf16 = subst_utf16 + subst_utf16_len + 1;
ret = git__utf8_to_16(subst_utf16, subst_utf16_len + 1,
- git_buf_cstr(&unparsed_buf));
+ git_str_cstr(&unparsed_buf));
cl_assert_equal_i(subst_utf16_len, ret);
ret = git__utf8_to_16(print_utf16,
- print_utf16_len + 1, git_buf_cstr(&unparsed_buf) + 4);
+ print_utf16_len + 1, git_str_cstr(&unparsed_buf) + 4);
cl_assert_equal_i(print_utf16_len, ret);
reparse_buf->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
@@ -147,7 +146,7 @@ static void do_junction(const char *old, const char *new)
CloseHandle(handle);
LocalFree(reparse_buf);
- git_buf_dispose(&unparsed_buf);
+ git_str_dispose(&unparsed_buf);
}
static void do_custom_reparse(const char *path)
@@ -300,7 +299,7 @@ void test_core_link__stat_dangling_symlink_directory(void)
void test_core_link__lstat_symlink(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
if (!should_run())
@@ -309,10 +308,10 @@ void test_core_link__lstat_symlink(void)
/* Windows always writes the canonical path as the link target, so
* write the full path on all platforms.
*/
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_target");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_target");
cl_git_rewritefile("lstat_target", "This is the target of a symbolic link.\n");
- do_symlink(git_buf_cstr(&target_path), "lstat_symlink", 0);
+ do_symlink(git_str_cstr(&target_path), "lstat_symlink", 0);
cl_must_pass(p_lstat("lstat_target", &st));
cl_assert(S_ISREG(st.st_mode));
@@ -320,32 +319,32 @@ void test_core_link__lstat_symlink(void)
cl_must_pass(p_lstat("lstat_symlink", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__lstat_symlink_directory(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_dirtarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_dirtarget");
p_mkdir("lstat_dirtarget", 0777);
- do_symlink(git_buf_cstr(&target_path), "lstat_dirlink", 1);
+ do_symlink(git_str_cstr(&target_path), "lstat_dirlink", 1);
cl_must_pass(p_lstat("lstat_dirtarget", &st));
cl_assert(S_ISDIR(st.st_mode));
cl_must_pass(p_lstat("lstat_dirlink", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__lstat_dangling_symlink(void)
@@ -383,13 +382,13 @@ void test_core_link__lstat_dangling_symlink_directory(void)
void test_core_link__stat_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "stat_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "stat_junctarget");
p_mkdir("stat_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "stat_junction");
+ do_junction(git_str_cstr(&target_path), "stat_junction");
cl_must_pass(p_stat("stat_junctarget", &st));
cl_assert(S_ISDIR(st.st_mode));
@@ -397,40 +396,40 @@ void test_core_link__stat_junction(void)
cl_must_pass(p_stat("stat_junction", &st));
cl_assert(S_ISDIR(st.st_mode));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__stat_dangling_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "stat_nonexistent_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "stat_nonexistent_junctarget");
p_mkdir("stat_nonexistent_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "stat_dangling_junction");
+ do_junction(git_str_cstr(&target_path), "stat_dangling_junction");
RemoveDirectory("stat_nonexistent_junctarget");
cl_must_fail(p_stat("stat_nonexistent_junctarget", &st));
cl_must_fail(p_stat("stat_dangling_junction", &st));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__lstat_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_junctarget");
p_mkdir("lstat_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "lstat_junction");
+ do_junction(git_str_cstr(&target_path), "lstat_junction");
cl_must_pass(p_lstat("lstat_junctarget", &st));
cl_assert(S_ISDIR(st.st_mode));
@@ -438,20 +437,20 @@ void test_core_link__lstat_junction(void)
cl_must_pass(p_lstat("lstat_junction", &st));
cl_assert(S_ISLNK(st.st_mode));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__lstat_dangling_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_nonexistent_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_nonexistent_junctarget");
p_mkdir("lstat_nonexistent_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "lstat_dangling_junction");
+ do_junction(git_str_cstr(&target_path), "lstat_dangling_junction");
RemoveDirectory("lstat_nonexistent_junctarget");
@@ -459,9 +458,9 @@ void test_core_link__lstat_dangling_junction(void)
cl_must_pass(p_lstat("lstat_dangling_junction", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
@@ -554,79 +553,79 @@ void test_core_link__readlink_normal_file(void)
void test_core_link__readlink_symlink(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_target");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_target");
cl_git_rewritefile("readlink_target", "This is the target of a symlink\n");
- do_symlink(git_buf_cstr(&target_path), "readlink_link", 0);
+ do_symlink(git_str_cstr(&target_path), "readlink_link", 0);
len = p_readlink("readlink_link", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&target_path), buf);
+ cl_assert_equal_s(git_str_cstr(&target_path), buf);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__readlink_dangling(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_nonexistent");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_nonexistent");
- do_symlink(git_buf_cstr(&target_path), "readlink_dangling", 0);
+ do_symlink(git_str_cstr(&target_path), "readlink_dangling", 0);
len = p_readlink("readlink_dangling", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&target_path), buf);
+ cl_assert_equal_s(git_str_cstr(&target_path), buf);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__readlink_multiple(void)
{
- git_buf target_path = GIT_BUF_INIT,
- path3 = GIT_BUF_INIT, path2 = GIT_BUF_INIT, path1 = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT,
+ path3 = GIT_STR_INIT, path2 = GIT_STR_INIT, path1 = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_final");
- git_buf_join(&path3, '/', clar_sandbox_path(), "readlink_3");
- git_buf_join(&path2, '/', clar_sandbox_path(), "readlink_2");
- git_buf_join(&path1, '/', clar_sandbox_path(), "readlink_1");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_final");
+ git_str_join(&path3, '/', clar_sandbox_path(), "readlink_3");
+ git_str_join(&path2, '/', clar_sandbox_path(), "readlink_2");
+ git_str_join(&path1, '/', clar_sandbox_path(), "readlink_1");
- do_symlink(git_buf_cstr(&target_path), git_buf_cstr(&path3), 0);
- do_symlink(git_buf_cstr(&path3), git_buf_cstr(&path2), 0);
- do_symlink(git_buf_cstr(&path2), git_buf_cstr(&path1), 0);
+ do_symlink(git_str_cstr(&target_path), git_str_cstr(&path3), 0);
+ do_symlink(git_str_cstr(&path3), git_str_cstr(&path2), 0);
+ do_symlink(git_str_cstr(&path2), git_str_cstr(&path1), 0);
len = p_readlink("readlink_1", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&path2), buf);
+ cl_assert_equal_s(git_str_cstr(&path2), buf);
- git_buf_dispose(&path1);
- git_buf_dispose(&path2);
- git_buf_dispose(&path3);
- git_buf_dispose(&target_path);
+ git_str_dispose(&path1);
+ git_str_dispose(&path2);
+ git_str_dispose(&path3);
+ git_str_dispose(&target_path);
}
diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c
index 3f04c2ad3..f0461ac1f 100644
--- a/tests/core/mkdir.c
+++ b/tests/core/mkdir.c
@@ -15,41 +15,41 @@ static void cleanup_basic_dirs(void *ref)
void test_core_mkdir__absolute(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
- git_buf_joinpath(&path, clar_sandbox_path(), "d0");
+ git_str_joinpath(&path, clar_sandbox_path(), "d0");
/* make a directory */
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
- git_buf_joinpath(&path, path.ptr, "subdir");
+ git_str_joinpath(&path, path.ptr, "subdir");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works for a single subdir */
- git_buf_joinpath(&path, path.ptr, "another");
+ git_str_joinpath(&path, path.ptr, "another");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works */
- git_buf_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
+ git_str_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure we don't imply recursive */
- git_buf_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
+ git_str_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_fail(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(!git_path_isdir(path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_mkdir__basic(void)
@@ -230,7 +230,7 @@ void test_core_mkdir__chmods(void)
void test_core_mkdir__keeps_parent_symlinks(void)
{
#ifndef GIT_WIN32
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
@@ -250,14 +250,14 @@ void test_core_mkdir__keeps_parent_symlinks(void)
cl_must_pass(symlink("d0", "d2"));
cl_assert(git_path_islink("d2"));
- git_buf_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
+ git_str_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
cl_assert(git_path_islink("d2"));
cl_assert(git_path_isdir("d2/other/dir"));
cl_assert(git_path_isdir("d0/other/dir"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
diff --git a/tests/core/path.c b/tests/core/path.c
index eac3573fe..6decf23ea 100644
--- a/tests/core/path.c
+++ b/tests/core/path.c
@@ -4,12 +4,12 @@
static void
check_dirname(const char *A, const char *B)
{
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
char *dir2;
cl_assert(git_path_dirname_r(&dir, A) >= 0);
cl_assert_equal_s(B, dir.ptr);
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
cl_assert((dir2 = git_path_dirname(A)) != NULL);
cl_assert_equal_s(B, dir2);
@@ -19,12 +19,12 @@ check_dirname(const char *A, const char *B)
static void
check_basename(const char *A, const char *B)
{
- git_buf base = GIT_BUF_INIT;
+ git_str base = GIT_STR_INIT;
char *base2;
cl_assert(git_path_basename_r(&base, A) >= 0);
cl_assert_equal_s(B, base.ptr);
- git_buf_dispose(&base);
+ git_str_dispose(&base);
cl_assert((base2 = git_path_basename(A)) != NULL);
cl_assert_equal_s(B, base2);
@@ -34,12 +34,12 @@ check_basename(const char *A, const char *B)
static void
check_joinpath(const char *path_a, const char *path_b, const char *expected_path)
{
- git_buf joined_path = GIT_BUF_INIT;
+ git_str joined_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b));
+ cl_git_pass(git_str_joinpath(&joined_path, path_a, path_b));
cl_assert_equal_s(expected_path, joined_path.ptr);
- git_buf_dispose(&joined_path);
+ git_str_dispose(&joined_path);
}
static void
@@ -50,13 +50,13 @@ check_joinpath_n(
const char *path_d,
const char *expected_path)
{
- git_buf joined_path = GIT_BUF_INIT;
+ git_str joined_path = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&joined_path, '/', 4,
+ cl_git_pass(git_str_join_n(&joined_path, '/', 4,
path_a, path_b, path_c, path_d));
cl_assert_equal_s(expected_path, joined_path.ptr);
- git_buf_dispose(&joined_path);
+ git_str_dispose(&joined_path);
}
@@ -172,13 +172,13 @@ check_path_to_dir(
const char* path,
const char* expected)
{
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- git_buf_sets(&tgt, path);
+ git_str_sets(&tgt, path);
cl_git_pass(git_path_to_dir(&tgt));
cl_assert_equal_s(expected, tgt.ptr);
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
}
static void
@@ -231,46 +231,46 @@ void test_core_path__07_path_to_dir(void)
/* join path to itself */
void test_core_path__08_self_join(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t asize = 0;
asize = path.asize;
- cl_git_pass(git_buf_sets(&path, "/foo"));
+ cl_git_pass(git_str_sets(&path, "/foo"));
cl_assert_equal_s(path.ptr, "/foo");
cl_assert(asize < path.asize);
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "this is a new string"));
cl_assert_equal_s(path.ptr, "/foo/this is a new string");
cl_assert(asize < path.asize);
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
cl_assert_equal_s(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
cl_assert(asize < path.asize);
- git_buf_dispose(&path);
- cl_git_pass(git_buf_sets(&path, "/foo/bar"));
+ git_str_dispose(&path);
+ cl_git_pass(git_str_sets(&path, "/foo/bar"));
- cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr + 4, "baz"));
cl_assert_equal_s(path.ptr, "/bar/baz");
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
cl_assert_equal_s(path.ptr, "/baz/somethinglongenoughtorealloc");
cl_assert(asize < path.asize);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void check_percent_decoding(const char *expected_result, const char *input)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_git_pass(git__percent_decode(&buf, input));
- cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_result, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_core_path__09_percent_decode(void)
@@ -289,17 +289,17 @@ void test_core_path__09_percent_decode(void)
static void check_fromurl(const char *expected_result, const char *input, int should_fail)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
assert(should_fail || expected_result);
if (!should_fail) {
cl_git_pass(git_path_fromurl(&buf, input));
- cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_result, git_str_cstr(&buf));
} else
cl_git_fail(git_path_fromurl(&buf, input));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#ifdef GIT_WIN32
@@ -353,7 +353,7 @@ static int check_one_walkup_step(void *ref, const char *path)
void test_core_path__11_walkup(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
char *expect[] = {
/* 1 */ "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
@@ -398,7 +398,7 @@ void test_core_path__11_walkup(void)
for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
- git_buf_sets(&p, expect[i]);
+ git_str_sets(&p, expect[i]);
info.expect_idx = i;
cl_git_pass(
@@ -410,12 +410,12 @@ void test_core_path__11_walkup(void)
i = info.expect_idx;
}
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__11a_walkup_cancel(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
int cancel[] = { 3, 2, 1, 0 };
char *expect[] = {
"/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "[CANCEL]", NULL,
@@ -432,7 +432,7 @@ void test_core_path__11a_walkup_cancel(void)
for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
- git_buf_sets(&p, expect[i]);
+ git_str_sets(&p, expect[i]);
info.cancel_after = cancel[j];
info.expect_idx = i;
@@ -446,7 +446,7 @@ void test_core_path__11a_walkup_cancel(void)
while (expect[i] != NULL) i++;
}
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__12_offset_to_path_root(void)
@@ -468,20 +468,20 @@ void test_core_path__12_offset_to_path_root(void)
void test_core_path__13_cannot_prettify_a_non_existing_file(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false);
cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__14_apply_relative(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&p, "/this/is/a/base"));
+ cl_git_pass(git_str_sets(&p, "/this/is/a/base"));
cl_git_pass(git_path_apply_relative(&p, "../test"));
cl_assert_equal_s("/this/is/a/test", p.ptr);
@@ -501,7 +501,7 @@ void test_core_path__14_apply_relative(void)
cl_git_fail(git_path_apply_relative(&p, "../../.."));
- cl_git_pass(git_buf_sets(&p, "d:/another/test"));
+ cl_git_pass(git_str_sets(&p, "d:/another/test"));
cl_git_pass(git_path_apply_relative(&p, "../.."));
cl_assert_equal_s("d:/", p.ptr);
@@ -510,7 +510,7 @@ void test_core_path__14_apply_relative(void)
cl_assert_equal_s("d:/from/here/and/back/", p.ptr);
- cl_git_pass(git_buf_sets(&p, "https://my.url.com/test.git"));
+ cl_git_pass(git_str_sets(&p, "https://my.url.com/test.git"));
cl_git_pass(git_path_apply_relative(&p, "../another.git"));
cl_assert_equal_s("https://my.url.com/another.git", p.ptr);
@@ -525,7 +525,7 @@ void test_core_path__14_apply_relative(void)
cl_assert_equal_s("https://", p.ptr);
- cl_git_pass(git_buf_sets(&p, "../../this/is/relative"));
+ cl_git_pass(git_str_sets(&p, "../../this/is/relative"));
cl_git_pass(git_path_apply_relative(&p, "../../preserves/the/prefix"));
cl_assert_equal_s("../../this/preserves/the/prefix", p.ptr);
@@ -535,20 +535,20 @@ void test_core_path__14_apply_relative(void)
cl_git_pass(git_path_apply_relative(&p, "../there"));
cl_assert_equal_s("../../there", p.ptr);
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
static void assert_resolve_relative(
- git_buf *buf, const char *expected, const char *path)
+ git_str *buf, const char *expected, const char *path)
{
- cl_git_pass(git_buf_sets(buf, path));
+ cl_git_pass(git_str_sets(buf, path));
cl_git_pass(git_path_resolve_relative(buf, 0));
cl_assert_equal_s(expected, buf->ptr);
}
void test_core_path__15_resolve_relative(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
assert_resolve_relative(&buf, "", "");
assert_resolve_relative(&buf, "", ".");
@@ -595,22 +595,22 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "../../path", "../../test//../././path");
assert_resolve_relative(&buf, "../d", "a/b/../../../c/../d");
- cl_git_pass(git_buf_sets(&buf, "/.."));
+ cl_git_pass(git_str_sets(&buf, "/.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/./.."));
+ cl_git_pass(git_str_sets(&buf, "/./.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/.//.."));
+ cl_git_pass(git_str_sets(&buf, "/.//.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/../."));
+ cl_git_pass(git_str_sets(&buf, "/../."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/../.././../a"));
+ cl_git_pass(git_str_sets(&buf, "/../.././../a"));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "////.."));
+ cl_git_pass(git_str_sets(&buf, "////.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
/* things that start with Windows network paths */
@@ -619,7 +619,7 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "//a/", "//a/b/..");
assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c");
- cl_git_pass(git_buf_sets(&buf, "//a/b/../.."));
+ cl_git_pass(git_str_sets(&buf, "//a/b/../.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
#else
assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
@@ -628,7 +628,7 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "/", "//a/b/../..");
#endif
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#define assert_common_dirlen(i, p, q) \
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 1bb1e9c6b..247bd43f5 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -168,7 +168,7 @@ void test_core_posix__unlink_removes_symlink(void)
void test_core_posix__symlink_resolves_to_correct_type(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -187,12 +187,12 @@ void test_core_posix__symlink_resolves_to_correct_type(void)
cl_must_pass(p_rmdir("dir"));
cl_must_pass(p_rmdir("file"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_core_posix__relative_symlink(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -207,12 +207,12 @@ void test_core_posix__relative_symlink(void)
cl_must_pass(p_unlink("dir/link"));
cl_must_pass(p_rmdir("dir"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_core_posix__symlink_to_file_across_dirs(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -234,5 +234,5 @@ void test_core_posix__symlink_to_file_across_dirs(void)
cl_must_pass(p_unlink("link"));
cl_must_pass(p_rmdir("dir"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index b436b97e0..56ea320be 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -5,26 +5,26 @@ static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
void test_core_rmdir__initialize(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_rmdir__cleanup(void)
@@ -36,25 +36,25 @@ void test_core_rmdir__cleanup(void)
/* make sure empty dir can be deleted recusively */
void test_core_rmdir__delete_recursive(void)
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
- cl_assert(git_path_exists(git_buf_cstr(&path)));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_assert(git_path_exists(git_str_cstr(&path)));
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
- cl_assert(!git_path_exists(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists(git_str_cstr(&path)));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/* make sure non-empty dir cannot be deleted recusively */
void test_core_rmdir__fail_to_delete_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
@@ -63,7 +63,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
cl_assert(!git_path_exists(empty_tmp_dir));
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__keep_base(void)
@@ -74,47 +74,47 @@ void test_core_rmdir__keep_base(void)
void test_core_rmdir__can_skip_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY));
- cl_assert(git_path_exists(git_buf_cstr(&file)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&file)) == true);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(git_path_exists(empty_tmp_dir) == false);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__can_remove_empty_parents(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
cl_git_pass(
- git_buf_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
- cl_assert(git_path_isfile(git_buf_cstr(&file)));
+ git_str_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
+ cl_assert(git_path_isfile(git_str_cstr(&file)));
cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir,
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS));
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
- cl_assert(git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
+ cl_assert(git_path_exists(git_str_cstr(&file)));
cl_assert(git_path_exists(empty_tmp_dir) == true);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
}
diff --git a/tests/core/sortedcache.c b/tests/core/sortedcache.c
index d5bbcea19..cb4e34efa 100644
--- a/tests/core/sortedcache.c
+++ b/tests/core/sortedcache.c
@@ -241,7 +241,7 @@ void test_core_sortedcache__in_memory(void)
static void sortedcache_test_reload(git_sortedcache *sc)
{
int count = 0;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *scan, *after;
sortedcache_test_struct *item;
@@ -266,7 +266,7 @@ static void sortedcache_test_reload(git_sortedcache *sc)
git_sortedcache_wunlock(sc);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_core_sortedcache__on_disk(void)
diff --git a/tests/core/stat.c b/tests/core/stat.c
index 7f5d66753..56d141e98 100644
--- a/tests/core/stat.c
+++ b/tests/core/stat.c
@@ -98,17 +98,17 @@ void test_core_stat__0(void)
void test_core_stat__root(void)
{
const char *sandbox = clar_sandbox_path();
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
int root_len;
struct stat st;
root_len = git_path_root(sandbox);
cl_assert(root_len >= 0);
- git_buf_set(&root, sandbox, root_len+1);
+ git_str_set(&root, sandbox, root_len+1);
cl_must_pass(p_stat(root.ptr, &st));
cl_assert(S_ISDIR(st.st_mode));
- git_buf_dispose(&root);
+ git_str_dispose(&root);
}
diff --git a/tests/core/useragent.c b/tests/core/useragent.c
index 2ce935bf5..a4ece902f 100644
--- a/tests/core/useragent.c
+++ b/tests/core/useragent.c
@@ -4,7 +4,7 @@
void test_core_useragent__get(void)
{
const char *custom_name = "super duper git";
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_assert_equal_p(NULL, git_libgit2__user_agent());
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_USER_AGENT, custom_name));
@@ -13,5 +13,5 @@ void test_core_useragent__get(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_USER_AGENT, &buf));
cl_assert_equal_s(custom_name, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
diff --git a/tests/core/zstream.c b/tests/core/zstream.c
index 3cbcea168..c22e81008 100644
--- a/tests/core/zstream.c
+++ b/tests/core/zstream.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "zstream.h"
static const char *data = "This is a test test test of This is a test";
@@ -60,7 +59,7 @@ void test_core_zstream__basic(void)
void test_core_zstream__fails_on_trailing_garbage(void)
{
- git_buf deflated = GIT_BUF_INIT, inflated = GIT_BUF_INIT;
+ git_str deflated = GIT_STR_INIT, inflated = GIT_STR_INIT;
char i = 0;
/* compress a simple string */
@@ -68,29 +67,29 @@ void test_core_zstream__fails_on_trailing_garbage(void)
/* append some garbage */
for (i = 0; i < 10; i++) {
- git_buf_putc(&deflated, i);
+ git_str_putc(&deflated, i);
}
cl_git_fail(git_zstream_inflatebuf(&inflated, deflated.ptr, deflated.size));
- git_buf_dispose(&deflated);
- git_buf_dispose(&inflated);
+ git_str_dispose(&deflated);
+ git_str_dispose(&inflated);
}
void test_core_zstream__buffer(void)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
cl_git_pass(git_zstream_deflatebuf(&out, data, strlen(data) + 1));
assert_zlib_equal(data, strlen(data) + 1, out.ptr, out.size);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
#define BIG_STRING_PART "Big Data IS Big - Long Data IS Long - We need a buffer larger than 1024 x 1024 to make sure we trigger chunked compression - Big Big Data IS Bigger than Big - Long Long Data IS Longer than Long"
-static void compress_and_decompress_input_various_ways(git_buf *input)
+static void compress_and_decompress_input_various_ways(git_str *input)
{
- git_buf out1 = GIT_BUF_INIT, out2 = GIT_BUF_INIT;
- git_buf inflated = GIT_BUF_INIT;
+ git_str out1 = GIT_STR_INIT, out2 = GIT_STR_INIT;
+ git_str inflated = GIT_STR_INIT;
size_t i, fixed_size = max(input->size / 2, 256);
char *fixed = git__malloc(fixed_size);
cl_assert(fixed);
@@ -119,7 +118,7 @@ static void compress_and_decompress_input_various_ways(git_buf *input)
while (!git_zstream_done(&zs)) {
size_t written = use_fixed_size;
cl_git_pass(git_zstream_get_output(fixed, &written, &zs));
- cl_git_pass(git_buf_put(&out2, fixed, written));
+ cl_git_pass(git_str_put(&out2, fixed, written));
}
git_zstream_free(&zs);
@@ -129,30 +128,30 @@ static void compress_and_decompress_input_various_ways(git_buf *input)
cl_assert_equal_sz(out1.size, out2.size);
cl_assert(!memcmp(out1.ptr, out2.ptr, out1.size));
- git_buf_dispose(&out2);
+ git_str_dispose(&out2);
}
cl_git_pass(git_zstream_inflatebuf(&inflated, out1.ptr, out1.size));
cl_assert_equal_i(input->size, inflated.size);
cl_assert(memcmp(input->ptr, inflated.ptr, inflated.size) == 0);
- git_buf_dispose(&out1);
- git_buf_dispose(&inflated);
+ git_str_dispose(&out1);
+ git_str_dispose(&inflated);
git__free(fixed);
}
void test_core_zstream__big_data(void)
{
- git_buf in = GIT_BUF_INIT;
+ git_str in = GIT_STR_INIT;
size_t scan, target;
for (target = 1024; target <= 1024 * 1024 * 4; target *= 8) {
/* make a big string that's easy to compress */
- git_buf_clear(&in);
+ git_str_clear(&in);
while (in.size < target)
cl_git_pass(
- git_buf_put(&in, BIG_STRING_PART, strlen(BIG_STRING_PART)));
+ git_str_put(&in, BIG_STRING_PART, strlen(BIG_STRING_PART)));
compress_and_decompress_input_various_ways(&in);
@@ -164,5 +163,5 @@ void test_core_zstream__big_data(void)
compress_and_decompress_input_various_ways(&in);
}
- git_buf_dispose(&in);
+ git_str_dispose(&in);
}
diff --git a/tests/describe/describe.c b/tests/describe/describe.c
index 26ca4efd8..ba67ca46b 100644
--- a/tests/describe/describe.c
+++ b/tests/describe/describe.c
@@ -32,7 +32,7 @@ void test_describe_describe__describe_a_repo_with_no_refs(void)
{
git_repository *repo;
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_object *object;
git_describe_result *result = NULL;
@@ -50,6 +50,6 @@ void test_describe_describe__describe_a_repo_with_no_refs(void)
git_describe_result_free(result);
git_object_free(object);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_git_sandbox_cleanup();
}
diff --git a/tests/describe/describe_helpers.c b/tests/describe/describe_helpers.c
index 80217dcf0..3df3b7c59 100644
--- a/tests/describe/describe_helpers.c
+++ b/tests/describe/describe_helpers.c
@@ -18,7 +18,7 @@ void assert_describe(
cl_git_pass(git_describe_commit(&result, object, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts));
- cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0));
+ cl_must_pass(wildmatch(expected_output, label.ptr, 0));
git_describe_result_free(result);
git_object_free(object);
@@ -37,7 +37,7 @@ void assert_describe_workdir(
cl_git_pass(git_describe_workdir(&result, repo, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts));
- cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0));
+ cl_must_pass(wildmatch(expected_output, label.ptr, 0));
git_describe_result_free(result);
git_buf_dispose(&label);
diff --git a/tests/describe/describe_helpers.h b/tests/describe/describe_helpers.h
index 16a0638e3..43e8c5e19 100644
--- a/tests/describe/describe_helpers.h
+++ b/tests/describe/describe_helpers.h
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
extern void assert_describe(
const char *expected_output,
diff --git a/tests/diff/binary.c b/tests/diff/binary.c
index 7edf37b51..24d2b22ef 100644
--- a/tests/diff/binary.c
+++ b/tests/diff/binary.c
@@ -2,7 +2,6 @@
#include "git2/sys/diff.h"
-#include "buffer.h"
#include "delta.h"
#include "filebuf.h"
#include "repository.h"
@@ -53,7 +52,7 @@ void test_patch(
cl_assert_equal_s(expected, actual.ptr);
- git_buf_clear(&actual);
+ git_buf_dispose(&actual);
cl_git_pass(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, git_diff_print_callback__to_buf, &actual));
cl_assert_equal_s(expected, actual.ptr);
@@ -197,7 +196,7 @@ void test_diff_binary__delete(void)
void test_diff_binary__delta(void)
{
git_index *index;
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
size_t i;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const char *expected =
@@ -239,7 +238,7 @@ void test_diff_binary__delta(void)
expected);
git_index_free(index);
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_diff_binary__delta_append(void)
@@ -283,7 +282,7 @@ void test_diff_binary__empty_for_no_diff(void)
git_commit *commit;
git_tree *tree;
git_diff *diff;
- git_buf actual = GIT_BUF_INIT;
+ git_str actual = GIT_STR_INIT;
opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY;
opts.id_abbrev = GIT_OID_HEXSZ;
@@ -299,7 +298,7 @@ void test_diff_binary__empty_for_no_diff(void)
cl_assert_equal_s("", actual.ptr);
- git_buf_dispose(&actual);
+ git_str_dispose(&actual);
git_diff_free(diff);
git_commit_free(commit);
git_tree_free(tree);
@@ -359,24 +358,24 @@ static int print_cb(
const git_diff_line *line,
void *payload)
{
- git_buf *buf = (git_buf *)payload;
+ git_str *buf = (git_str *)payload;
GIT_UNUSED(delta);
if (hunk)
- git_buf_put(buf, hunk->header, hunk->header_len);
+ git_str_put(buf, hunk->header, hunk->header_len);
if (line)
- git_buf_put(buf, line->content, line->content_len);
+ git_str_put(buf, line->content, line->content_len);
- return git_buf_oom(buf) ? -1 : 0;
+ return git_str_oom(buf) ? -1 : 0;
}
void test_diff_binary__print_patch_from_diff(void)
{
git_index *index;
git_diff *diff;
- git_buf actual = GIT_BUF_INIT;
+ git_str actual = GIT_STR_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const char *expected =
"diff --git a/untimely.txt b/untimely.txt\n" \
@@ -403,7 +402,7 @@ void test_diff_binary__print_patch_from_diff(void)
cl_assert_equal_s(expected, actual.ptr);
- git_buf_dispose(&actual);
+ git_str_dispose(&actual);
git_diff_free(diff);
git_index_free(index);
}
@@ -411,13 +410,13 @@ void test_diff_binary__print_patch_from_diff(void)
struct diff_data {
char *old_path;
git_oid old_id;
- git_buf old_binary_base85;
+ git_str old_binary_base85;
size_t old_binary_inflatedlen;
git_diff_binary_t old_binary_type;
char *new_path;
git_oid new_id;
- git_buf new_binary_base85;
+ git_str new_binary_base85;
size_t new_binary_inflatedlen;
git_diff_binary_t new_binary_type;
};
@@ -452,12 +451,12 @@ static int binary_cb(
GIT_UNUSED(delta);
- git_buf_encode_base85(&diff_data->old_binary_base85,
+ git_str_encode_base85(&diff_data->old_binary_base85,
binary->old_file.data, binary->old_file.datalen);
diff_data->old_binary_inflatedlen = binary->old_file.inflatedlen;
diff_data->old_binary_type = binary->old_file.type;
- git_buf_encode_base85(&diff_data->new_binary_base85,
+ git_str_encode_base85(&diff_data->new_binary_base85,
binary->new_file.data, binary->new_file.datalen);
diff_data->new_binary_inflatedlen = binary->new_file.inflatedlen;
diff_data->new_binary_type = binary->new_file.type;
@@ -541,6 +540,6 @@ void test_diff_binary__blob_to_blob(void)
git__free(diff_data.old_path);
git__free(diff_data.new_path);
- git_buf_dispose(&diff_data.old_binary_base85);
- git_buf_dispose(&diff_data.new_binary_base85);
+ git_str_dispose(&diff_data.old_binary_base85);
+ git_str_dispose(&diff_data.new_binary_base85);
}
diff --git a/tests/diff/blob.c b/tests/diff/blob.c
index 50edf6bc0..9f71e4ea6 100644
--- a/tests/diff/blob.c
+++ b/tests/diff/blob.c
@@ -915,7 +915,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+More lines\n"
"+And more\n"
"+Go here\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -925,7 +925,7 @@ void test_diff_blob__using_path_and_attributes(void)
"diff --git a/zzz.binary b/zzz.binary\n"
"index 45141a7..75b0dbb 100644\n"
"Binary files a/zzz.binary and b/zzz.binary differ\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -940,7 +940,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+More lines\n"
"+And more\n"
"+Go here\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -955,7 +955,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+More lines\n"
"+And more\n"
"+Go here\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
@@ -971,7 +971,7 @@ void test_diff_blob__using_path_and_attributes(void)
"diff --git a/zzz.normal b/zzz.normal\n"
"index b435cd5..1604519 100644\n"
"Binary files a/zzz.normal and b/zzz.normal differ\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -985,7 +985,7 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -3 +3 @@\n"
"-0123456789\n"
"+replace a line\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -999,7 +999,7 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -3 +3 @@\n"
"-0123456789\n"
"+replace a line\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
@@ -1013,7 +1013,7 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -3 +3 @@ 0123456789\n"
"-0123456789\n"
"+replace a line\n", buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(p);
git_buf_dispose(&buf);
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c
index cace40967..ce24e9bc0 100644
--- a/tests/diff/drivers.c
+++ b/tests/diff/drivers.c
@@ -178,7 +178,8 @@ void test_diff_drivers__builtins(void)
{
git_diff *diff;
git_patch *patch;
- git_buf file = GIT_BUF_INIT, actual = GIT_BUF_INIT, expected = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT, expected = GIT_STR_INIT;
+ git_buf actual = GIT_BUF_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_vector files = GIT_VECTOR_INIT;
size_t i;
@@ -205,15 +206,15 @@ void test_diff_drivers__builtins(void)
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
- git_buf_sets(&expected, "userdiff/expected/nodriver/diff.");
- git_buf_puts(&expected, extension);
+ git_str_sets(&expected, "userdiff/expected/nodriver/diff.");
+ git_str_puts(&expected, extension);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_clear(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -230,24 +231,24 @@ void test_diff_drivers__builtins(void)
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
- git_buf_sets(&expected, "userdiff/expected/driver/diff.");
- git_buf_puts(&expected, extension);
+ git_str_sets(&expected, "userdiff/expected/driver/diff.");
+ git_str_puts(&expected, extension);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_clear(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
git__free(path);
}
- git_buf_dispose(&file);
git_buf_dispose(&actual);
- git_buf_dispose(&expected);
+ git_str_dispose(&file);
+ git_str_dispose(&expected);
git_vector_free(&files);
}
diff --git a/tests/diff/format_email.c b/tests/diff/format_email.c
index ea7aa070f..612804c42 100644
--- a/tests/diff/format_email.c
+++ b/tests/diff/format_email.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "commit.h"
#include "diff.h"
#include "diff_generate.h"
@@ -41,12 +40,12 @@ static void assert_email_match(
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_diff_format_email(&buf, diff, opts));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s(expected, buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_diff_commit_as_email(
&buf, repo, commit, 1, 1, opts->flags, NULL));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, buf.ptr);
git_diff_free(diff);
git_commit_free(commit);
@@ -258,7 +257,7 @@ void test_diff_format_email__multiple(void)
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_diff_format_email(&buf, diff, &opts));
- cl_assert_equal_s(email, git_buf_cstr(&buf));
+ cl_assert_equal_s(email, buf.ptr);
git_diff_free(diff);
git_commit_free(commit);
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index 6b6e6645e..d3a0c8de6 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -39,21 +39,21 @@ void test_diff_parse__nonpatches_fail_with_notfound(void)
static void test_parse_invalid_diff(const char *invalid_diff)
{
git_diff *diff;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* throw some random (legitimate) diffs in with the given invalid
* one.
*/
- git_buf_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE);
- git_buf_puts(&buf, PATCH_BINARY_DELTA);
- git_buf_puts(&buf, invalid_diff);
- git_buf_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_MIDDLE);
- git_buf_puts(&buf, PATCH_BINARY_LITERAL);
+ git_str_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE);
+ git_str_puts(&buf, PATCH_BINARY_DELTA);
+ git_str_puts(&buf, invalid_diff);
+ git_str_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_MIDDLE);
+ git_str_puts(&buf, PATCH_BINARY_LITERAL);
cl_git_fail_with(GIT_ERROR,
git_diff_from_buffer(&diff, buf.ptr, buf.size));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_diff_parse__exact_rename(void)
diff --git a/tests/diff/patch.c b/tests/diff/patch.c
index d288bba58..8945afc26 100644
--- a/tests/diff/patch.c
+++ b/tests/diff/patch.c
@@ -208,7 +208,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected1, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -219,7 +219,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected2, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -233,7 +233,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected3, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -247,7 +247,7 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected4, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -267,7 +267,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
const git_diff_hunk *hunk;
const git_diff_line *line;
size_t hunklen;
- git_buf old_content = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str old_content = GIT_STR_INIT, actual = GIT_STR_INIT;
const char *new_content = "The Song of Seven Cities\n------------------------\n\nI WAS Lord of Cities very sumptuously builded.\nSeven roaring Cities paid me tribute from afar.\nIvory their outposts were--the guardrooms of them gilded,\nAnd garrisoned with Amazons invincible in war.\n\nThis is some new text;\nNot as good as the old text;\nBut here it is.\n\nSo they warred and trafficked only yesterday, my Cities.\nTo-day there is no mark or mound of where my Cities stood.\nFor the River rose at midnight and it washed away my Cities.\nThey are evened with Atlantis and the towns before the Flood.\n\nRain on rain-gorged channels raised the water-levels round them,\nFreshet backed on freshet swelled and swept their world from sight,\nTill the emboldened floods linked arms and, flashing forward, drowned them--\nDrowned my Seven Cities and their peoples in one night!\n\nLow among the alders lie their derelict foundations,\nThe beams wherein they trusted and the plinths whereon they built--\nMy rulers and their treasure and their unborn populations,\nDead, destroyed, aborted, and defiled with mud and silt!\n\nAnother replacement;\nBreaking up the poem;\nGenerating some hunks.\n\nTo the sound of trumpets shall their seed restore my Cities\nWealthy and well-weaponed, that once more may I behold\nAll the world go softly when it walks before my Cities,\nAnd the horses and the chariots fleeing from them as of old!\n\n -- Rudyard Kipling\n";
g_repo = cl_git_sandbox_init("renames");
@@ -311,7 +311,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 0));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("Ivory their outposts were--the guardrooms of them gilded,\n", actual.ptr);
cl_assert_equal_i(6, line->old_lineno);
cl_assert_equal_i(6, line->new_lineno);
@@ -319,7 +319,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("All the world went softly when it walked before my Cities--\n", actual.ptr);
cl_assert_equal_i(9, line->old_lineno);
cl_assert_equal_i(-1, line->new_lineno);
@@ -327,7 +327,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 12));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("This is some new text;\n", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(9, line->new_lineno);
@@ -348,7 +348,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 0));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("My rulers and their treasure and their unborn populations,\n", actual.ptr);
cl_assert_equal_i(31, line->old_lineno);
cl_assert_equal_i(25, line->new_lineno);
@@ -356,7 +356,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("The Daughters of the Palace whom they cherished in my Cities,\n", actual.ptr);
cl_assert_equal_i(34, line->old_lineno);
cl_assert_equal_i(-1, line->new_lineno);
@@ -364,7 +364,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 12));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("Another replacement;\n", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(28, line->new_lineno);
@@ -375,7 +375,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
/* Let's check line numbers when there is no newline */
- git_buf_rtrim(&old_content);
+ git_str_rtrim(&old_content);
cl_git_rewritefile("renames/songof7cities.txt", old_content.ptr);
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, head, &opt));
@@ -403,35 +403,35 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 1));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("And the horses and the chariots fleeing from them as of old!\n", actual.ptr);
cl_assert_equal_i(47, line->old_lineno);
cl_assert_equal_i(47, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 2));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("\n", actual.ptr);
cl_assert_equal_i(48, line->old_lineno);
cl_assert_equal_i(48, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s(" -- Rudyard Kipling\n", actual.ptr);
cl_assert_equal_i(49, line->old_lineno);
cl_assert_equal_i(-1, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 4));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s(" -- Rudyard Kipling", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(49, line->new_lineno);
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 5));
cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)line->origin);
- cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
+ cl_git_pass(git_str_set(&actual, line->content, line->content_len));
cl_assert_equal_s("\n\\ No newline at end of file\n", actual.ptr);
cl_assert_equal_i(-1, line->old_lineno);
cl_assert_equal_i(49, line->new_lineno);
@@ -439,8 +439,8 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
git_patch_free(patch);
git_diff_free(diff);
- git_buf_dispose(&actual);
- git_buf_dispose(&old_content);
+ git_str_dispose(&actual);
+ git_str_dispose(&old_content);
git_tree_free(head);
}
@@ -532,7 +532,7 @@ static void check_single_patch_stats(
void test_diff_patch__line_counts_with_eofnl(void)
{
git_config *cfg;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
const char *end;
git_index *index;
const char *expected =
@@ -565,15 +565,15 @@ void test_diff_patch__line_counts_with_eofnl(void)
/* remove first line */
- end = git_buf_cstr(&content) + git_buf_find(&content, '\n') + 1;
- git_buf_consume(&content, end);
+ end = git_str_cstr(&content) + git_str_find(&content, '\n') + 1;
+ git_str_consume(&content, end);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(g_repo, 1, 0, 1, 3, NULL, NULL);
/* remove trailing whitespace */
- git_buf_rtrim(&content);
+ git_str_rtrim(&content);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(g_repo, 2, 1, 2, 6, NULL, NULL);
@@ -585,7 +585,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_buf_putc(&content, '\n'));
+ cl_git_pass(git_str_putc(&content, '\n'));
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(g_repo, 1, 1, 1, 3, NULL, NULL);
@@ -613,7 +613,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
check_single_patch_stats(
g_repo, 1, 1, 1, 6, expected_sizes, expected);
- git_buf_dispose(&content);
+ git_str_dispose(&content);
}
void test_diff_patch__can_strip_bad_utf8(void)
diff --git a/tests/diff/rename.c b/tests/diff/rename.c
index bd25d29aa..d28a4d989 100644
--- a/tests/diff/rename.c
+++ b/tests/diff/rename.c
@@ -460,7 +460,7 @@ void test_diff_rename__working_directory_changes(void)
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
- git_buf old_content = GIT_BUF_INIT, content = GIT_BUF_INIT;;
+ git_str old_content = GIT_STR_INIT, content = GIT_STR_INIT;;
tree = resolve_commit_oid_to_tree(g_repo, sha0);
diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED | GIT_DIFF_INCLUDE_UNTRACKED;
@@ -514,7 +514,7 @@ void test_diff_rename__working_directory_changes(void)
cl_git_pass(
git_futils_readbuffer(&old_content, "renames/songof7cities.txt"));
cl_git_pass(
- git_buf_lf_to_crlf(&content, &old_content));
+ git_str_lf_to_crlf(&content, &old_content));
cl_git_pass(
git_futils_writebuffer(&content, "renames/songof7cities.txt", 0, 0));
@@ -576,7 +576,7 @@ void test_diff_rename__working_directory_changes(void)
cl_git_pass(git_oid_fromstr(&id, blobsha));
cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
- cl_git_pass(git_buf_set(
+ cl_git_pass(git_str_set(
&content, git_blob_rawcontent(blob), (size_t)git_blob_rawsize(blob)));
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
git_blob_free(blob);
@@ -604,8 +604,8 @@ void test_diff_rename__working_directory_changes(void)
git_diff_free(diff);
git_tree_free(tree);
- git_buf_dispose(&content);
- git_buf_dispose(&old_content);
+ git_str_dispose(&content);
+ git_str_dispose(&old_content);
}
void test_diff_rename__patch(void)
@@ -666,7 +666,7 @@ void test_diff_rename__patch(void)
void test_diff_rename__file_exchange(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -708,13 +708,13 @@ void test_diff_rename__file_exchange(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
}
void test_diff_rename__file_exchange_three(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT, c3 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT, c3 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -760,14 +760,14 @@ void test_diff_rename__file_exchange_three(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
- git_buf_dispose(&c3);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
+ git_str_dispose(&c3);
}
void test_diff_rename__file_partial_exchange(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -779,7 +779,7 @@ void test_diff_rename__file_partial_exchange(void)
cl_git_pass(git_futils_readbuffer(&c1, "renames/untimely.txt"));
cl_git_pass(git_futils_writebuffer(&c1, "renames/songof7cities.txt", 0, 0));
for (i = 0; i < 100; ++i)
- cl_git_pass(git_buf_puts(&c2, "this is not the content you are looking for\n"));
+ cl_git_pass(git_str_puts(&c2, "this is not the content you are looking for\n"));
cl_git_pass(git_futils_writebuffer(&c2, "renames/untimely.txt", 0, 0));
cl_git_pass(
@@ -813,13 +813,13 @@ void test_diff_rename__file_partial_exchange(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
}
void test_diff_rename__rename_and_copy_from_same_source(void)
{
- git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT, c2 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -831,9 +831,9 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
* and the second 2/3 of file into another new place
*/
cl_git_pass(git_futils_readbuffer(&c1, "renames/songof7cities.txt"));
- cl_git_pass(git_buf_set(&c2, c1.ptr, c1.size));
- git_buf_truncate(&c1, c1.size * 2 / 3);
- git_buf_consume(&c2, ((char *)c2.ptr) + (c2.size / 3));
+ cl_git_pass(git_str_set(&c2, c1.ptr, c1.size));
+ git_str_truncate(&c1, c1.size * 2 / 3);
+ git_str_consume(&c2, ((char *)c2.ptr) + (c2.size / 3));
cl_git_pass(git_futils_writebuffer(&c1, "renames/song_a.txt", 0, 0));
cl_git_pass(git_futils_writebuffer(&c2, "renames/song_b.txt", 0, 0));
@@ -870,13 +870,13 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
- git_buf_dispose(&c2);
+ git_str_dispose(&c1);
+ git_str_dispose(&c2);
}
void test_diff_rename__from_deleted_to_split(void)
{
- git_buf c1 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -924,7 +924,7 @@ void test_diff_rename__from_deleted_to_split(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
+ git_str_dispose(&c1);
}
struct rename_expected
@@ -967,7 +967,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
- git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
+ git_str one = GIT_STR_INIT, two = GIT_STR_INIT;
unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
const char *sources[] = { "Class1.cs", "Class2.cs" };
const char *targets[] = { "ClassA.cs", "ClassB.cs" };
@@ -1024,25 +1024,25 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_index_free(index);
git_reference_free(head);
git_reference_free(selfsimilar);
- git_buf_dispose(&one);
- git_buf_dispose(&two);
+ git_str_dispose(&one);
+ git_str_dispose(&two);
}
static void write_similarity_file_two(const char *filename, size_t b_lines)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
size_t i;
for (i = 0; i < b_lines; i++)
- git_buf_printf(&contents, "%02d - bbbbb\r\n", (int)(i+1));
+ git_str_printf(&contents, "%02d - bbbbb\r\n", (int)(i+1));
for (i = b_lines; i < 50; i++)
- git_buf_printf(&contents, "%02d - aaaaa%s", (int)(i+1), (i == 49 ? "" : "\r\n"));
+ git_str_printf(&contents, "%02d - aaaaa%s", (int)(i+1), (i == 49 ? "" : "\r\n"));
cl_git_pass(
git_futils_writebuffer(&contents, filename, O_RDWR|O_CREAT, 0777));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_diff_rename__rejected_match_can_match_others_two(void)
@@ -1346,7 +1346,7 @@ void test_diff_rename__rewrite_on_single_file(void)
void test_diff_rename__can_find_copy_to_split(void)
{
- git_buf c1 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -1390,12 +1390,12 @@ void test_diff_rename__can_find_copy_to_split(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
+ git_str_dispose(&c1);
}
void test_diff_rename__can_delete_unmodified_deltas(void)
{
- git_buf c1 = GIT_BUF_INIT;
+ git_str c1 = GIT_STR_INIT;
git_index *index;
git_tree *tree;
git_diff *diff;
@@ -1438,7 +1438,7 @@ void test_diff_rename__can_delete_unmodified_deltas(void)
git_tree_free(tree);
git_index_free(index);
- git_buf_dispose(&c1);
+ git_str_dispose(&c1);
}
void test_diff_rename__matches_config_behavior(void)
diff --git a/tests/diff/stats.c b/tests/diff/stats.c
index 54572672c..f69dba9b3 100644
--- a/tests/diff/stats.c
+++ b/tests/diff/stats.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "commit.h"
#include "diff.h"
#include "diff_generate.h"
@@ -53,11 +52,11 @@ void test_diff_stats__stat(void)
cl_assert_equal_sz(3, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+ cl_assert(strcmp(buf.ptr, stat) == 0);
git_buf_dispose(&buf);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 80));
- cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0);
+ cl_assert(strcmp(buf.ptr, stat) == 0);
git_buf_dispose(&buf);
}
@@ -77,7 +76,7 @@ void test_diff_stats__multiple_hunks(void)
cl_assert_equal_sz(4, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -92,7 +91,7 @@ void test_diff_stats__numstat(void)
&_stats, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2", false);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -110,7 +109,7 @@ void test_diff_stats__shortstat(void)
cl_assert_equal_sz(3, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -128,7 +127,7 @@ void test_diff_stats__shortstat_noinsertions(void)
cl_assert_equal_sz(2, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -146,7 +145,7 @@ void test_diff_stats__shortstat_nodeletions(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -166,7 +165,7 @@ void test_diff_stats__rename(void)
cl_assert_equal_sz(1, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -186,7 +185,7 @@ void test_diff_stats__rename_nochanges(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -206,7 +205,7 @@ void test_diff_stats__rename_and_modifiy(void)
cl_assert_equal_sz(1, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -225,7 +224,7 @@ void test_diff_stats__rename_in_subdirectory(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -247,7 +246,7 @@ void test_diff_stats__rename_no_find(void)
cl_assert_equal_sz(10, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -269,7 +268,7 @@ void test_diff_stats__rename_nochanges_no_find(void)
cl_assert_equal_sz(13, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -290,7 +289,7 @@ void test_diff_stats__rename_and_modify_no_find(void)
cl_assert_equal_sz(8, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -309,7 +308,7 @@ void test_diff_stats__binary(void)
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -323,7 +322,7 @@ void test_diff_stats__binary_numstat(void)
&_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -339,7 +338,7 @@ void test_diff_stats__mode_change(void)
&_stats, "7ade76dd34bba4733cf9878079f9fd4a456a9189", false);
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
}
@@ -372,7 +371,7 @@ void test_diff_stats__new_file(void)
cl_git_pass(git_diff_from_buffer(&diff, input, strlen(input)));
cl_git_pass(git_diff_get_stats(&_stats, diff));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0));
- cl_assert_equal_s(stat, git_buf_cstr(&buf));
+ cl_assert_equal_s(stat, buf.ptr);
git_buf_dispose(&buf);
git_diff_free(diff);
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c
index 93223ef7d..0436ca5c8 100644
--- a/tests/diff/submodules.c
+++ b/tests/diff/submodules.c
@@ -15,7 +15,7 @@ void test_diff_submodules__cleanup(void)
cl_git_sandbox_cleanup();
}
-#define get_buf_ptr(buf) ((buf)->asize ? (buf)->ptr : NULL)
+#define get_buf_ptr(buf) ((buf)->size ? (buf)->ptr : NULL)
static void check_diff_patches_at_line(
git_diff *diff, const char **expected,
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 00c52ff1b..f7c74a294 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1663,7 +1663,7 @@ void test_diff_workdir__patience_diff(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected_normal, buf.ptr);
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
@@ -1675,9 +1675,8 @@ void test_diff_workdir__patience_diff(void)
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(expected_patience, buf.ptr);
- git_buf_clear(&buf);
-
git_buf_dispose(&buf);
+
git_patch_free(patch);
git_diff_free(diff);
}
@@ -1754,7 +1753,7 @@ void test_diff_workdir__with_stale_index(void)
git_index_free(idx);
}
-static int touch_file(void *payload, git_buf *path)
+static int touch_file(void *payload, git_str *path)
{
struct stat st;
struct p_timeval times[2];
@@ -1804,10 +1803,10 @@ void test_diff_workdir__can_update_index(void)
/* touch all the files so stat times are different */
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_sets(&path, "status"));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_sets(&path, "status"));
cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
@@ -1873,9 +1872,9 @@ void test_diff_workdir__binary_detection(void)
{
git_index *idx;
git_diff *diff = NULL;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
int i;
- git_buf data[10] = {
+ git_str data[10] = {
{ "1234567890", 0, 10 }, /* 0 - all ascii text control */
{ "\xC3\x85\xC3\xBC\xE2\x80\xA0\x48\xC3\xB8\xCF\x80\xCE\xA9", 0, 14 }, /* 1 - UTF-8 multibyte text */
{ "\xEF\xBB\xBF\xC3\x9C\xE2\xA4\x92\xC6\x92\x38\xC2\xA3\xE2\x82\xAC", 0, 16 }, /* 2 - UTF-8 with BOM */
@@ -1899,7 +1898,7 @@ void test_diff_workdir__binary_detection(void)
* then we will try with test data in index and ASCII in workdir.
*/
- cl_git_pass(git_buf_sets(&b, "empty_standard_repo/0"));
+ cl_git_pass(git_str_sets(&b, "empty_standard_repo/0"));
for (i = 0; i < 10; ++i) {
b.ptr[b.size - 1] = '0' + i;
cl_git_mkfile(b.ptr, "baseline");
@@ -1931,7 +1930,7 @@ void test_diff_workdir__binary_detection(void)
git_diff_free(diff);
- cl_git_pass(git_buf_sets(&b, "empty_standard_repo/0"));
+ cl_git_pass(git_str_sets(&b, "empty_standard_repo/0"));
for (i = 0; i < 10; ++i) {
b.ptr[b.size - 1] = '0' + i;
cl_git_pass(git_index_add_bypath(idx, &b.ptr[b.size - 1]));
@@ -1959,7 +1958,7 @@ void test_diff_workdir__binary_detection(void)
git_diff_free(diff);
git_index_free(idx);
- git_buf_dispose(&b);
+ git_str_dispose(&b);
}
void test_diff_workdir__to_index_conflicted(void) {
@@ -2006,7 +2005,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
git_reference *head;
git_object *head_object;
git_oid initial, first, second;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct stat st;
struct p_timeval times[2];
@@ -2040,7 +2039,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
cl_assert(!git_oid_equal(&initial, &first));
/* touch all the files so stat times are different */
- cl_git_pass(git_buf_sets(&path, "status"));
+ cl_git_pass(git_str_sets(&path, "status"));
cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
@@ -2050,7 +2049,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
git_oid_cpy(&second, git_index_checksum(index));
cl_assert(!git_oid_equal(&first, &second));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_object_free(head_object);
git_reference_free(head);
git_index_free(index);
diff --git a/tests/email/create.c b/tests/email/create.c
index ccf79c2aa..27a665582 100644
--- a/tests/email/create.c
+++ b/tests/email/create.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "diff_generate.h"
static git_repository *repo;
@@ -43,7 +42,7 @@ static void assert_email_match(
git_buf buf = GIT_BUF_INIT;
email_for_commit(&buf, commit_id, opts);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, buf.ptr);
git_buf_dispose(&buf);
}
@@ -54,15 +53,17 @@ static void assert_subject_match(
git_email_create_options *opts)
{
git_buf buf = GIT_BUF_INIT;
- const char *loc;
+ char *subject, *nl;
email_for_commit(&buf, commit_id, opts);
- cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL);
- git_buf_consume(&buf, (loc + 10));
- git_buf_truncate_at_char(&buf, '\n');
+ cl_assert((subject = strstr(buf.ptr, "\nSubject: ")) != NULL);
+ subject += 10;
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ if ((nl = strchr(subject, '\n')) != NULL)
+ *nl = '\0';
+
+ cl_assert_equal_s(expected, subject);
git_buf_dispose(&buf);
}
@@ -327,7 +328,7 @@ void test_email_create__custom_summary_and_body(void)
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, buf.ptr);
git_diff_free(diff);
git_commit_free(commit);
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 6881af40a..0de712be8 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -78,7 +78,7 @@ void test_fetchhead_nonetwork__write(void)
{
git_vector fetchhead_vector = GIT_VECTOR_INIT;
git_fetchhead_ref *fetchhead_ref;
- git_buf fetchhead_buf = GIT_BUF_INIT;
+ git_str fetchhead_buf = GIT_STR_INIT;
int equals = 0;
size_t i;
@@ -94,7 +94,7 @@ void test_fetchhead_nonetwork__write(void)
equals = (strcmp(fetchhead_buf.ptr, FETCH_HEAD_WILDCARD_DATA_LOCAL) == 0);
- git_buf_dispose(&fetchhead_buf);
+ git_str_dispose(&fetchhead_buf);
git_vector_foreach(&fetchhead_vector, i, fetchhead_ref) {
git_fetchhead_ref_free(fetchhead_ref);
@@ -431,7 +431,7 @@ int find_master_haacked(const char *ref_name, const char *remote_url, const git_
void test_fetchhead_nonetwork__create_when_refpecs_given(void)
{
git_remote *remote;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *refspec1 = "refs/heads/master";
char *refspec2 = "refs/heads/haacked";
char *refspecs[] = { refspec1, refspec2 };
@@ -443,7 +443,7 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
cl_set_cleanup(&cleanup_repository, "./test1");
cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
cl_git_pass(git_remote_create(&remote, g_repo, "origin", cl_fixture("testrepo.git")));
cl_assert(!git_path_exists(path.ptr));
@@ -456,7 +456,7 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
cl_assert(found_haacked);
git_remote_free(remote);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static bool count_refs_called;
@@ -488,7 +488,7 @@ int count_refs(const char *ref_name, const char *remote_url, const git_oid *oid,
void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
{
git_remote *remote;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(&cleanup_repository, "./test1");
cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
@@ -499,7 +499,7 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
/* Pick up the new refspec */
cl_git_pass(git_remote_lookup(&remote, g_repo, "origin"));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
cl_assert(!git_path_exists(path.ptr));
cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
cl_assert(git_path_exists(path.ptr));
@@ -520,7 +520,7 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void)
}
git_remote_free(remote);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_fetchhead_nonetwork__credentials_are_stripped(void)
diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
index bc9c7f289..925ea58d2 100644
--- a/tests/filter/crlf.c
+++ b/tests/filter/crlf.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
-#include "buffer.h"
static git_repository *g_repo = NULL;
diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c
index ee3b6353b..7aa3777e6 100644
--- a/tests/filter/custom_helpers.c
+++ b/tests/filter/custom_helpers.c
@@ -8,8 +8,8 @@
int bitflip_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source)
{
const unsigned char *src = (const unsigned char *)from->ptr;
@@ -25,7 +25,7 @@ int bitflip_filter_apply(
if (!from->size)
return 0;
- cl_git_pass(git_buf_grow(to, from->size));
+ cl_git_pass(git_str_grow(to, from->size));
dst = (unsigned char *)to->ptr;
@@ -70,8 +70,8 @@ git_filter *create_bitflip_filter(void)
int reverse_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source)
{
const unsigned char *src = (const unsigned char *)from->ptr;
@@ -87,7 +87,7 @@ int reverse_filter_apply(
if (!from->size)
return 0;
- cl_git_pass(git_buf_grow(to, from->size));
+ cl_git_pass(git_str_grow(to, from->size));
dst = (unsigned char *)to->ptr + from->size - 1;
diff --git a/tests/filter/custom_helpers.h b/tests/filter/custom_helpers.h
index 537a51da2..0936c581b 100644
--- a/tests/filter/custom_helpers.h
+++ b/tests/filter/custom_helpers.h
@@ -7,13 +7,13 @@ extern git_filter *create_erroneous_filter(const char *attr);
extern int bitflip_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source);
extern int reverse_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source);
diff --git a/tests/filter/file.c b/tests/filter/file.c
index 521c01c02..3b7ab19e2 100644
--- a/tests/filter/file.c
+++ b/tests/filter/file.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "crlf.h"
-#include "buffer.h"
static git_repository *g_repo = NULL;
@@ -53,13 +52,13 @@ void test_filter_file__apply(void)
struct buf_writestream {
git_writestream base;
- git_buf buf;
+ git_str buf;
};
int buf_writestream_write(git_writestream *s, const char *buf, size_t len)
{
struct buf_writestream *stream = (struct buf_writestream *)s;
- return git_buf_put(&stream->buf, buf, len);
+ return git_str_put(&stream->buf, buf, len);
}
int buf_writestream_close(git_writestream *s)
@@ -71,7 +70,7 @@ int buf_writestream_close(git_writestream *s)
void buf_writestream_free(git_writestream *s)
{
struct buf_writestream *stream = (struct buf_writestream *)s;
- git_buf_dispose(&stream->buf);
+ git_str_dispose(&stream->buf);
}
void test_filter_file__apply_stream(void)
diff --git a/tests/filter/query.c b/tests/filter/query.c
index 6889d715b..429c10443 100644
--- a/tests/filter/query.c
+++ b/tests/filter/query.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "crlf.h"
-#include "buffer.h"
static git_repository *g_repo = NULL;
diff --git a/tests/filter/stream.c b/tests/filter/stream.c
index b6a4c3ca1..0f85f9c47 100644
--- a/tests/filter/stream.c
+++ b/tests/filter/stream.c
@@ -137,12 +137,12 @@ git_filter *create_compress_filter(void)
static void writefile(const char *filename, size_t numchunks)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char buf[CHUNKSIZE];
size_t i = 0, j = 0;
int fd;
- cl_git_pass(git_buf_joinpath(&path, "empty_standard_repo", filename));
+ cl_git_pass(git_str_joinpath(&path, "empty_standard_repo", filename));
fd = p_open(path.ptr, O_RDWR|O_CREAT, 0666);
cl_assert(fd >= 0);
@@ -156,7 +156,7 @@ static void writefile(const char *filename, size_t numchunks)
}
p_close(fd);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void test_stream(size_t numchunks)
diff --git a/tests/filter/systemattrs.c b/tests/filter/systemattrs.c
index 4996b3b1e..b687b4b44 100644
--- a/tests/filter/systemattrs.c
+++ b/tests/filter/systemattrs.c
@@ -3,29 +3,33 @@
#include "path.h"
static git_repository *g_repo = NULL;
-static git_buf system_attr_path = GIT_BUF_INIT;
+static git_str system_attr_path = GIT_STR_INIT;
void test_filter_systemattrs__initialize(void)
{
+ git_buf system_path = GIT_BUF_INIT;
+
g_repo = cl_git_sandbox_init("crlf");
cl_must_pass(p_unlink("crlf/.gitattributes"));
cl_git_pass(git_libgit2_opts(
- GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_attr_path));
- cl_git_pass(git_buf_joinpath(&system_attr_path,
- system_attr_path.ptr, "gitattributes"));
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_path));
+ cl_git_pass(git_str_joinpath(&system_attr_path,
+ system_path.ptr, "gitattributes"));
cl_git_mkfile(system_attr_path.ptr,
"*.txt text\n"
"*.bin binary\n"
"*.crlf text eol=crlf\n"
"*.lf text eol=lf\n");
+
+ git_buf_dispose(&system_path);
}
void test_filter_systemattrs__cleanup(void)
{
cl_must_pass(p_unlink(system_attr_path.ptr));
- git_buf_dispose(&system_attr_path);
+ git_str_dispose(&system_attr_path);
cl_git_sandbox_cleanup();
}
diff --git a/tests/filter/wildcard.c b/tests/filter/wildcard.c
index 0c9c13b1e..ee61a8dba 100644
--- a/tests/filter/wildcard.c
+++ b/tests/filter/wildcard.c
@@ -78,8 +78,8 @@ static int wildcard_filter_check(
static int wildcard_filter_apply(
git_filter *self,
void **payload,
- git_buf *to,
- const git_buf *from,
+ git_str *to,
+ const git_str *from,
const git_filter_source *source)
{
const char *filtername = *payload;
diff --git a/tests/graph/commit_graph.c b/tests/graph/commit_graph.c
index 5926dca6f..83f53f1d4 100644
--- a/tests/graph/commit_graph.c
+++ b/tests/graph/commit_graph.c
@@ -12,12 +12,12 @@ void test_graph_commit_graph__parse(void)
struct git_commit_graph_file *file;
struct git_commit_graph_entry e, parent;
git_oid id;
- git_buf commit_graph_path = GIT_BUF_INIT;
+ git_str commit_graph_path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_commit_graph_file_open(&file, git_buf_cstr(&commit_graph_path)));
- cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_buf_cstr(&commit_graph_path)), 0);
+ cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
+ cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
+ cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_str_cstr(&commit_graph_path)), 0);
cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
@@ -47,7 +47,7 @@ void test_graph_commit_graph__parse(void)
git_commit_graph_file_free(file);
git_repository_free(repo);
- git_buf_dispose(&commit_graph_path);
+ git_str_dispose(&commit_graph_path);
}
void test_graph_commit_graph__parse_octopus_merge(void)
@@ -56,11 +56,11 @@ void test_graph_commit_graph__parse_octopus_merge(void)
struct git_commit_graph_file *file;
struct git_commit_graph_entry e, parent;
git_oid id;
- git_buf commit_graph_path = GIT_BUF_INIT;
+ git_str commit_graph_path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("merge-recursive/.gitted")));
- cl_git_pass(git_buf_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_commit_graph_file_open(&file, git_buf_cstr(&commit_graph_path)));
+ cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
+ cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
cl_git_pass(git_oid_fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
@@ -88,7 +88,7 @@ void test_graph_commit_graph__parse_octopus_merge(void)
git_commit_graph_file_free(file);
git_repository_free(repo);
- git_buf_dispose(&commit_graph_path);
+ git_str_dispose(&commit_graph_path);
}
void test_graph_commit_graph__writer(void)
@@ -97,12 +97,13 @@ void test_graph_commit_graph__writer(void)
git_commit_graph_writer *w = NULL;
git_revwalk *walk;
git_commit_graph_writer_options opts = GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT;
- git_buf cgraph = GIT_BUF_INIT, expected_cgraph = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_buf cgraph = GIT_BUF_INIT;
+ git_str expected_cgraph = GIT_STR_INIT, path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/info"));
- cl_git_pass(git_commit_graph_writer_new(&w, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info"));
+ cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path)));
/* This is equivalent to `git commit-graph write --reachable`. */
cl_git_pass(git_revwalk_new(&walk, repo));
@@ -111,15 +112,15 @@ void test_graph_commit_graph__writer(void)
git_revwalk_free(walk);
cl_git_pass(git_commit_graph_writer_dump(&cgraph, w, &opts));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_futils_readbuffer(&expected_cgraph, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info/commit-graph"));
+ cl_git_pass(git_futils_readbuffer(&expected_cgraph, git_str_cstr(&path)));
- cl_assert_equal_i(git_buf_len(&cgraph), git_buf_len(&expected_cgraph));
- cl_assert_equal_i(memcmp(git_buf_cstr(&cgraph), git_buf_cstr(&expected_cgraph), git_buf_len(&cgraph)), 0);
+ cl_assert_equal_i(cgraph.size, git_str_len(&expected_cgraph));
+ cl_assert_equal_i(memcmp(cgraph.ptr, git_str_cstr(&expected_cgraph), cgraph.size), 0);
git_buf_dispose(&cgraph);
- git_buf_dispose(&expected_cgraph);
- git_buf_dispose(&path);
+ git_str_dispose(&expected_cgraph);
+ git_str_dispose(&path);
git_commit_graph_writer_free(w);
git_repository_free(repo);
}
diff --git a/tests/graph/reachable_from_any.c b/tests/graph/reachable_from_any.c
index 5c8416499..9693d7d67 100644
--- a/tests/graph/reachable_from_any.c
+++ b/tests/graph/reachable_from_any.c
@@ -200,12 +200,12 @@ void test_graph_reachable_from_any__exhaustive(void)
descendants,
n_descendants);
if (actual_reachable != expected_reachable) {
- git_buf error_message_buf = GIT_BUF_INIT;
+ git_str error_message_buf = GIT_STR_INIT;
char parent_oidbuf[9] = {0}, child_oidbuf[9] = {0};
cl_git_pass(git_oid_nfmt(
parent_oidbuf, 8, git_commit_id(parent_commit)));
- git_buf_printf(&error_message_buf,
+ git_str_printf(&error_message_buf,
"git_graph_reachable_from_any(\"%s\", %zu, "
"{",
parent_oidbuf,
@@ -216,14 +216,14 @@ void test_graph_reachable_from_any__exhaustive(void)
git_oid_nfmt(child_oidbuf,
8,
&descendants[descendant_i]));
- git_buf_printf(&error_message_buf, " \"%s\"", child_oidbuf);
+ git_str_printf(&error_message_buf, " \"%s\"", child_oidbuf);
}
- git_buf_printf(&error_message_buf,
+ git_str_printf(&error_message_buf,
" }) = %d, expected = %d",
actual_reachable,
expected_reachable);
cl_check_(actual_reachable == expected_reachable,
- git_buf_cstr(&error_message_buf));
+ git_str_cstr(&error_message_buf));
}
}
}
diff --git a/tests/ignore/status.c b/tests/ignore/status.c
index 83e821bdd..deb717590 100644
--- a/tests/ignore/status.c
+++ b/tests/ignore/status.c
@@ -610,12 +610,12 @@ void test_ignore_status__filenames_with_special_prefixes_do_not_interfere_with_s
int i;
for (i = 0; *(test_cases + i) != NULL; i++) {
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
char *file_name = *(test_cases + i);
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_buf_joinpath(&file, "empty_standard_repo", file_name));
- cl_git_mkfile(git_buf_cstr(&file), "Please don't ignore me!");
+ cl_git_pass(git_str_joinpath(&file, "empty_standard_repo", file_name));
+ cl_git_mkfile(git_str_cstr(&file), "Please don't ignore me!");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(repo, cb_status__single, &st));
@@ -626,7 +626,7 @@ void test_ignore_status__filenames_with_special_prefixes_do_not_interfere_with_s
cl_assert(st.status == GIT_STATUS_WT_NEW);
cl_git_sandbox_cleanup();
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
}
diff --git a/tests/index/crlf.c b/tests/index/crlf.c
index 26c19d76d..8d2a5fcce 100644
--- a/tests/index/crlf.c
+++ b/tests/index/crlf.c
@@ -14,7 +14,7 @@
static git_repository *g_repo;
static git_index *g_index;
-static git_buf expected_fixture = GIT_BUF_INIT;
+static git_str expected_fixture = GIT_STR_INIT;
void test_index_crlf__initialize(void)
{
@@ -29,7 +29,7 @@ void test_index_crlf__cleanup(void)
if (expected_fixture.size) {
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
+ git_str_dispose(&expected_fixture);
}
}
@@ -42,11 +42,11 @@ struct compare_data
const char *attrs;
};
-static int add_and_check_file(void *payload, git_buf *actual_path)
+static int add_and_check_file(void *payload, git_str *actual_path)
{
- git_buf expected_path = GIT_BUF_INIT;
- git_buf expected_path_fail = GIT_BUF_INIT;
- git_buf expected_contents = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
+ git_str expected_path_fail = GIT_STR_INIT;
+ git_str expected_contents = GIT_STR_INIT;
struct compare_data *cd = payload;
char *basename;
const git_index_entry *entry;
@@ -60,10 +60,10 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
goto done;
}
- cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
+ cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename));
- cl_git_pass(git_buf_puts(&expected_path_fail, expected_path.ptr));
- cl_git_pass(git_buf_puts(&expected_path_fail, ".fail"));
+ cl_git_pass(git_str_puts(&expected_path_fail, expected_path.ptr));
+ cl_git_pass(git_str_puts(&expected_path_fail, ".fail"));
if (git_path_isfile(expected_path.ptr)) {
cl_git_pass(git_index_add_bypath(g_index, basename));
@@ -79,7 +79,7 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
git_blob_free(blob);
} else if (git_path_isfile(expected_path_fail.ptr)) {
cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path_fail.ptr));
- git_buf_rtrim(&expected_contents);
+ git_str_rtrim(&expected_contents);
if (git_index_add_bypath(g_index, basename) == 0 ||
git_error_last()->klass != GIT_ERROR_FILTER ||
@@ -93,18 +93,18 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
done:
if (failed) {
- git_buf details = GIT_BUF_INIT;
- git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}",
+ git_str details = GIT_STR_INIT;
+ git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}",
basename, cd->systype, cd->autocrlf, cd->safecrlf, cd->attrs);
clar__fail(__FILE__, __func__, __LINE__,
"index contents did not match expected", details.ptr, 0);
- git_buf_dispose(&details);
+ git_str_dispose(&details);
}
git__free(basename);
- git_buf_dispose(&expected_contents);
- git_buf_dispose(&expected_path);
- git_buf_dispose(&expected_path_fail);
+ git_str_dispose(&expected_contents);
+ git_str_dispose(&expected_path);
+ git_str_dispose(&expected_path_fail);
return 0;
}
@@ -118,34 +118,34 @@ static const char *system_type(void)
static void test_add_index(const char *safecrlf, const char *autocrlf, const char *attrs)
{
- git_buf attrbuf = GIT_BUF_INIT;
- git_buf expected_dirname = GIT_BUF_INIT;
- git_buf sandboxname = GIT_BUF_INIT;
- git_buf reponame = GIT_BUF_INIT;
+ git_str attrbuf = GIT_STR_INIT;
+ git_str expected_dirname = GIT_STR_INIT;
+ git_str sandboxname = GIT_STR_INIT;
+ git_str reponame = GIT_STR_INIT;
struct compare_data compare_data = { system_type(), NULL, safecrlf, autocrlf, attrs };
const char *c;
- git_buf_puts(&reponame, "crlf");
+ git_str_puts(&reponame, "crlf");
- git_buf_puts(&sandboxname, "autocrlf_");
- git_buf_puts(&sandboxname, autocrlf);
+ git_str_puts(&sandboxname, "autocrlf_");
+ git_str_puts(&sandboxname, autocrlf);
- git_buf_puts(&sandboxname, ",safecrlf_");
- git_buf_puts(&sandboxname, safecrlf);
+ git_str_puts(&sandboxname, ",safecrlf_");
+ git_str_puts(&sandboxname, safecrlf);
if (*attrs) {
- git_buf_puts(&sandboxname, ",");
+ git_str_puts(&sandboxname, ",");
for (c = attrs; *c; c++) {
if (*c == ' ')
- git_buf_putc(&sandboxname, ',');
+ git_str_putc(&sandboxname, ',');
else if (*c == '=')
- git_buf_putc(&sandboxname, '_');
+ git_str_putc(&sandboxname, '_');
else
- git_buf_putc(&sandboxname, *c);
+ git_str_putc(&sandboxname, *c);
}
- git_buf_printf(&attrbuf, "* %s\n", attrs);
+ git_str_printf(&attrbuf, "* %s\n", attrs);
cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr);
}
@@ -154,23 +154,23 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha
cl_git_pass(git_index_clear(g_index));
- git_buf_joinpath(&expected_dirname, "crlf_data", system_type());
- git_buf_puts(&expected_dirname, "_to_odb");
+ git_str_joinpath(&expected_dirname, "crlf_data", system_type());
+ git_str_puts(&expected_dirname, "_to_odb");
- git_buf_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr);
+ git_str_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr);
cl_fixture_sandbox(expected_fixture.ptr);
compare_data.dirname = sandboxname.ptr;
cl_git_pass(git_path_direach(&reponame, 0, add_and_check_file, &compare_data));
cl_fixture_cleanup(expected_fixture.ptr);
- git_buf_dispose(&expected_fixture);
+ git_str_dispose(&expected_fixture);
- git_buf_dispose(&attrbuf);
- git_buf_dispose(&expected_fixture);
- git_buf_dispose(&expected_dirname);
- git_buf_dispose(&sandboxname);
- git_buf_dispose(&reponame);
+ git_str_dispose(&attrbuf);
+ git_str_dispose(&expected_fixture);
+ git_str_dispose(&expected_dirname);
+ git_str_dispose(&sandboxname);
+ git_str_dispose(&reponame);
}
static void set_up_workingdir(const char *name)
@@ -196,16 +196,16 @@ static void set_up_workingdir(const char *name)
git_path_dirload(&contents, cl_fixture("crlf"), 0, 0);
git_vector_foreach(&contents, i, fn) {
char *basename = git_path_basename(fn);
- git_buf dest_filename = GIT_BUF_INIT;
+ git_str dest_filename = GIT_STR_INIT;
if (strcmp(basename, ".gitted") &&
strcmp(basename, ".gitattributes")) {
- git_buf_joinpath(&dest_filename, name, basename);
+ git_str_joinpath(&dest_filename, name, basename);
cl_git_pass(git_futils_cp(fn, dest_filename.ptr, 0644));
}
git__free(basename);
- git_buf_dispose(&dest_filename);
+ git_str_dispose(&dest_filename);
}
git_vector_free_deep(&contents);
}
diff --git a/tests/index/filemodes.c b/tests/index/filemodes.c
index 3d2bb4a03..1ab8a9a7f 100644
--- a/tests/index/filemodes.c
+++ b/tests/index/filemodes.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "index.h"
@@ -36,10 +35,10 @@ void test_index_filemodes__read(void)
static void replace_file_with_mode(
const char *filename, const char *backup, unsigned int create_mode)
{
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, "filemodes", filename));
- cl_git_pass(git_buf_printf(&content, "%s as %08u (%d)",
+ cl_git_pass(git_str_joinpath(&path, "filemodes", filename));
+ cl_git_pass(git_str_printf(&content, "%s as %08u (%d)",
filename, create_mode, rand()));
cl_git_pass(p_rename(path.ptr, backup));
@@ -47,8 +46,8 @@ static void replace_file_with_mode(
path.ptr, content.ptr, content.size,
O_WRONLY|O_CREAT|O_TRUNC, create_mode);
- git_buf_dispose(&path);
- git_buf_dispose(&content);
+ git_str_dispose(&path);
+ git_str_dispose(&content);
}
#define add_and_check_mode(I,F,X) add_and_check_mode_(I,F,X,__FILE__,__func__,__LINE__)
diff --git a/tests/index/nsec.c b/tests/index/nsec.c
index 6edcf030a..3efd855a7 100644
--- a/tests/index/nsec.c
+++ b/tests/index/nsec.c
@@ -47,16 +47,16 @@ static bool try_create_file_with_nsec_timestamp(const char *path)
*/
static bool should_expect_nsecs(void)
{
- git_buf nsec_path = GIT_BUF_INIT;
+ git_str nsec_path = GIT_STR_INIT;
bool expect;
- git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");
+ git_str_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");
expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);
cl_must_pass(p_unlink(nsec_path.ptr));
- git_buf_dispose(&nsec_path);
+ git_str_dispose(&nsec_path);
return expect;
}
diff --git a/tests/index/racy.c b/tests/index/racy.c
index b06f55de4..07b3b73d4 100644
--- a/tests/index/racy.c
+++ b/tests/index/racy.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "../checkout/checkout_helpers.h"
-#include "buffer.h"
#include "index.h"
#include "repository.h"
@@ -24,9 +23,9 @@ void test_index_racy__diff(void)
{
git_index *index;
git_diff *diff;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
/* Put 'A' into the index */
@@ -46,21 +45,21 @@ void test_index_racy__diff(void)
git_index_free(index);
git_diff_free(diff);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_index_racy__write_index_just_after_file(void)
{
git_index *index;
git_diff *diff;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
struct p_timeval times[2];
/* Make sure we do have a timestamp */
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_write(index));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
/* Force the file's timestamp to be a second after we wrote the index */
times[0].tv_sec = index->stamp.mtime.tv_sec + 1;
@@ -95,7 +94,7 @@ void test_index_racy__write_index_just_after_file(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
cl_assert_equal_i(1, git_diff_num_deltas(diff));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_diff_free(diff);
git_index_free(index);
}
@@ -103,7 +102,7 @@ void test_index_racy__write_index_just_after_file(void)
static void setup_race(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index *index;
git_index_entry *entry;
struct stat st;
@@ -112,7 +111,7 @@ static void setup_race(void)
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
cl_git_pass(git_index_write(index));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
cl_git_pass(git_index_add_bypath(index, "A"));
@@ -129,7 +128,7 @@ static void setup_race(void)
entry->mtime.seconds = (int32_t)st.st_mtime;
entry->mtime.nanoseconds = (int32_t)st.st_mtime_nsec;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_index_racy__smudges_index_entry_on_save(void)
@@ -169,14 +168,14 @@ void test_index_racy__detects_diff_of_change_in_identical_timestamp(void)
static void setup_uptodate_files(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index *index;
const git_index_entry *a_entry;
git_index_entry new_entry = {{0}};
cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
/* Put 'A' into the index */
@@ -196,7 +195,7 @@ static void setup_uptodate_files(void)
cl_git_pass(git_index_add_from_buffer(index, &new_entry, "hello!\n", 7));
git_index_free(index);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_index_racy__adding_to_index_is_uptodate(void)
diff --git a/tests/index/tests.c b/tests/index/tests.c
index d9d8371dd..9b28028e6 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -28,7 +28,7 @@ static struct test_entry test_entries[] = {
/* Helpers */
static void copy_file(const char *src, const char *dst)
{
- git_buf source_buf = GIT_BUF_INIT;
+ git_str source_buf = GIT_STR_INIT;
git_file dst_fd;
cl_git_pass(git_futils_readbuffer(&source_buf, src));
@@ -40,28 +40,28 @@ static void copy_file(const char *src, const char *dst)
cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size));
cleanup:
- git_buf_dispose(&source_buf);
+ git_str_dispose(&source_buf);
p_close(dst_fd);
}
static void files_are_equal(const char *a, const char *b)
{
- git_buf buf_a = GIT_BUF_INIT;
- git_buf buf_b = GIT_BUF_INIT;
+ git_str buf_a = GIT_STR_INIT;
+ git_str buf_b = GIT_STR_INIT;
int pass;
if (git_futils_readbuffer(&buf_a, a) < 0)
cl_assert(0);
if (git_futils_readbuffer(&buf_b, b) < 0) {
- git_buf_dispose(&buf_a);
+ git_str_dispose(&buf_a);
cl_assert(0);
}
pass = (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size));
- git_buf_dispose(&buf_a);
- git_buf_dispose(&buf_b);
+ git_str_dispose(&buf_a);
+ git_str_dispose(&buf_b);
cl_assert(pass);
}
@@ -544,12 +544,12 @@ void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
static void assert_add_bypath_fails(git_repository *repo, const char *fn)
{
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_repository_index(&index, repo));
cl_assert(git_index_entrycount(index) == 0);
- git_buf_joinpath(&path, "./invalid", fn);
+ git_str_joinpath(&path, "./invalid", fn);
cl_git_mkfile(path.ptr, NULL);
cl_git_fail(git_index_add_bypath(index, fn));
@@ -557,7 +557,7 @@ static void assert_add_bypath_fails(git_repository *repo, const char *fn)
cl_assert(git_index_entrycount(index) == 0);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
}
@@ -592,7 +592,7 @@ void test_index_tests__cannot_add_invalid_filename(void)
static void assert_add_fails(git_repository *repo, const char *fn)
{
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index_entry entry = {{0}};
cl_git_pass(git_repository_index(&index, repo));
@@ -606,7 +606,7 @@ static void assert_add_fails(git_repository *repo, const char *fn)
cl_assert(git_index_entrycount(index) == 0);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
}
@@ -659,7 +659,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
git_index *index;
git_oid expected;
const git_index_entry *entry;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *fn;
cl_git_pass(git_repository_index(&index, repo));
@@ -673,7 +673,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
replace_char(fn, '/', '_');
replace_char(fn, ':', '!');
- git_buf_joinpath(&path, "./invalid", fn);
+ git_str_joinpath(&path, "./invalid", fn);
cl_git_mkfile(path.ptr, NULL);
@@ -691,7 +691,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig)
p_unlink(path.ptr);
cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
git__free(fn);
}
diff --git a/tests/iterator/index.c b/tests/iterator/index.c
index 25d8c2990..69b795f5c 100644
--- a/tests/iterator/index.c
+++ b/tests/iterator/index.c
@@ -279,12 +279,12 @@ static const char *expected_index_ci[] = {
void test_iterator_index__case_folding(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int fs_is_ci = 0;
- cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
+ cl_git_pass(git_str_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
fs_is_ci = git_path_exists(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
index_iterator_test(
"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
@@ -978,22 +978,22 @@ void test_iterator_index__pathlist_with_directory(void)
static void create_paths(git_index *index, const char *root, int depth)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
git_index_entry entry;
size_t root_len;
int i;
if (root) {
- cl_git_pass(git_buf_puts(&fullpath, root));
- cl_git_pass(git_buf_putc(&fullpath, '/'));
+ cl_git_pass(git_str_puts(&fullpath, root));
+ cl_git_pass(git_str_putc(&fullpath, '/'));
}
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
- git_buf_truncate(&fullpath, root_len);
- cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+ git_str_truncate(&fullpath, root_len);
+ cl_git_pass(git_str_printf(&fullpath, "item%d", i));
if (file) {
memset(&entry, 0, sizeof(git_index_entry));
@@ -1007,7 +1007,7 @@ static void create_paths(git_index *index, const char *root, int depth)
}
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
void test_iterator_index__pathlist_for_deeply_nested_item(void)
diff --git a/tests/iterator/tree.c b/tests/iterator/tree.c
index f7fb9a7ee..4145c8dea 100644
--- a/tests/iterator/tree.c
+++ b/tests/iterator/tree.c
@@ -623,7 +623,7 @@ static void build_test_tree(
const char *scan = fmt, *next;
char type, delimiter;
git_filemode_t mode = GIT_FILEMODE_BLOB;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
va_list arglist;
cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); /* start builder */
@@ -640,7 +640,7 @@ static void build_test_tree(
delimiter = *scan++; /* read and skip delimiter */
for (next = scan; *next && *next != delimiter; ++next)
/* seek end */;
- cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
+ cl_git_pass(git_str_set(&name, scan, (size_t)(next - scan)));
for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
/* skip delimiter and optional comma */;
@@ -653,7 +653,7 @@ static void build_test_tree(
cl_git_pass(git_treebuilder_write(out, builder));
git_treebuilder_free(builder);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
}
void test_iterator_tree__case_conflicts_0(void)
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 82ee363f9..7ca726c24 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -643,7 +643,7 @@ void test_iterator_workdir__filesystem2(void)
*/
void test_iterator_workdir__filesystem_gunk(void)
{
- git_buf parent = GIT_BUF_INIT;
+ git_str parent = GIT_STR_INIT;
git_iterator *i;
int n;
@@ -653,8 +653,8 @@ void test_iterator_workdir__filesystem_gunk(void)
g_repo = cl_git_sandbox_init("testrepo");
for (n = 0; n < 100000; n++) {
- git_buf_clear(&parent);
- cl_git_pass(git_buf_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
+ git_str_clear(&parent);
+ cl_git_pass(git_str_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
cl_git_pass(git_futils_mkdir(parent.ptr, 0775, GIT_MKDIR_PATH));
}
@@ -667,7 +667,7 @@ void test_iterator_workdir__filesystem_gunk(void)
expect_iterator_items(i, 17, NULL, 16, NULL);
git_iterator_free(i);
- git_buf_dispose(&parent);
+ git_str_dispose(&parent);
}
void test_iterator_workdir__skips_unreadable_dirs(void)
@@ -1019,19 +1019,19 @@ void test_iterator_workdir__pathlist_with_dirs(void)
static void create_paths(const char *root, int depth)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
size_t root_len;
int i;
- cl_git_pass(git_buf_puts(&fullpath, root));
+ cl_git_pass(git_str_puts(&fullpath, root));
cl_git_pass(git_path_to_dir(&fullpath));
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
- git_buf_truncate(&fullpath, root_len);
- cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+ git_str_truncate(&fullpath, root_len);
+ cl_git_pass(git_str_printf(&fullpath, "item%d", i));
if (file) {
cl_git_rewritefile(fullpath.ptr, "This is a file!\n");
@@ -1043,7 +1043,7 @@ static void create_paths(const char *root, int depth)
}
}
- git_buf_dispose(&fullpath);
+ git_str_dispose(&fullpath);
}
void test_iterator_workdir__pathlist_for_deeply_nested_item(void)
diff --git a/tests/mailmap/parsing.c b/tests/mailmap/parsing.c
index ba3b3a2f6..5ea470f34 100644
--- a/tests/mailmap/parsing.c
+++ b/tests/mailmap/parsing.c
@@ -103,15 +103,15 @@ void test_mailmap_parsing__string(void)
void test_mailmap_parsing__windows_string(void)
{
- git_buf unixbuf = GIT_BUF_INIT;
- git_buf winbuf = GIT_BUF_INIT;
+ git_str unixbuf = GIT_STR_INIT;
+ git_str winbuf = GIT_STR_INIT;
/* Parse with windows-style line endings */
- git_buf_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
- cl_git_pass(git_buf_lf_to_crlf(&winbuf, &unixbuf));
+ git_str_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
+ cl_git_pass(git_str_lf_to_crlf(&winbuf, &unixbuf));
cl_git_pass(git_mailmap_from_buffer(&g_mailmap, winbuf.ptr, winbuf.size));
- git_buf_dispose(&winbuf);
+ git_str_dispose(&winbuf);
/* We should have parsed all of the entries */
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
diff --git a/tests/merge/analysis.c b/tests/merge/analysis.c
index 1432a7d11..8c61303e3 100644
--- a/tests/merge/analysis.c
+++ b/tests/merge/analysis.c
@@ -53,28 +53,28 @@ static void analysis_from_branch(
const char *our_branchname,
const char *their_branchname)
{
- git_buf our_refname = GIT_BUF_INIT;
- git_buf their_refname = GIT_BUF_INIT;
+ git_str our_refname = GIT_STR_INIT;
+ git_str their_refname = GIT_STR_INIT;
git_reference *our_ref;
git_reference *their_ref;
git_annotated_commit *their_head;
if (our_branchname != NULL) {
- cl_git_pass(git_buf_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
- cl_git_pass(git_reference_lookup(&our_ref, repo, git_buf_cstr(&our_refname)));
+ cl_git_pass(git_str_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
+ cl_git_pass(git_reference_lookup(&our_ref, repo, git_str_cstr(&our_refname)));
} else {
cl_git_pass(git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE));
}
- cl_git_pass(git_buf_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
+ cl_git_pass(git_str_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
- cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&their_refname)));
+ cl_git_pass(git_reference_lookup(&their_ref, repo, git_str_cstr(&their_refname)));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge_analysis_for_ref(merge_analysis, merge_pref, repo, our_ref, (const git_annotated_commit **)&their_head, 1));
- git_buf_dispose(&our_refname);
- git_buf_dispose(&their_refname);
+ git_str_dispose(&our_refname);
+ git_str_dispose(&their_refname);
git_annotated_commit_free(their_head);
git_reference_free(our_ref);
git_reference_free(their_ref);
@@ -120,15 +120,15 @@ void test_merge_analysis__unborn(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
- git_buf master = GIT_BUF_INIT;
+ git_str master = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
- cl_must_pass(p_unlink(git_buf_cstr(&master)));
+ cl_git_pass(git_str_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
+ cl_must_pass(p_unlink(git_str_cstr(&master)));
analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis);
- git_buf_dispose(&master);
+ git_str_dispose(&master);
}
void test_merge_analysis__fastforward_with_config_noff(void)
diff --git a/tests/merge/driver.c b/tests/merge/driver.c
index a3fececb4..b7d320cbb 100644
--- a/tests/merge/driver.c
+++ b/tests/merge/driver.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#define TEST_REPO_PATH "merge-resolve"
@@ -71,14 +70,23 @@ static int test_driver_apply(
const char *filter_name,
const git_merge_driver_source *src)
{
+ git_str str = GIT_STR_INIT;
+ int error;
+
GIT_UNUSED(s);
GIT_UNUSED(src);
*path_out = "applied.txt";
*mode_out = GIT_FILEMODE_BLOB;
- return git_buf_printf(merged_out, "This is the `%s` driver.\n",
+ error = git_str_printf(&str, "This is the `%s` driver.\n",
filter_name);
+
+ merged_out->ptr = str.ptr;
+ merged_out->size = str.size;
+ merged_out->reserved = 0;
+
+ return error;
}
static struct test_merge_driver test_driver_custom = {
@@ -117,19 +125,19 @@ static void test_drivers_unregister(void)
static void set_gitattributes_to(const char *driver)
{
- git_buf line = GIT_BUF_INIT;
+ git_str line = GIT_STR_INIT;
if (driver && strcmp(driver, ""))
- git_buf_printf(&line, "automergeable.txt merge=%s\n", driver);
+ git_str_printf(&line, "automergeable.txt merge=%s\n", driver);
else if (driver)
- git_buf_printf(&line, "automergeable.txt merge\n");
+ git_str_printf(&line, "automergeable.txt merge\n");
else
- git_buf_printf(&line, "automergeable.txt -merge\n");
+ git_str_printf(&line, "automergeable.txt -merge\n");
- cl_assert(!git_buf_oom(&line));
+ cl_assert(!git_str_oom(&line));
cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", line.ptr);
- git_buf_dispose(&line);
+ git_str_dispose(&line);
}
static void merge_branch(void)
@@ -172,11 +180,11 @@ void test_merge_driver__shutdown_is_called(void)
test_driver_custom.shutdown = 0;
test_driver_wildcard.initialized = 0;
test_driver_wildcard.shutdown = 0;
-
+
/* run the merge with the custom driver */
set_gitattributes_to("custom");
merge_branch();
-
+
/* unregister the drivers, ensure their shutdown function is called */
test_drivers_unregister();
diff --git a/tests/merge/files.c b/tests/merge/files.c
index 6877f9848..fbc54e11e 100644
--- a/tests/merge/files.c
+++ b/tests/merge/files.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "merge_helpers.h"
#include "conflict_data.h"
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 27f355f35..1eb423ef7 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -17,15 +17,15 @@ int merge_trees_from_branches(
git_commit *our_commit, *their_commit, *ancestor_commit = NULL;
git_tree *our_tree, *their_tree, *ancestor_tree = NULL;
git_oid our_oid, their_oid, ancestor_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
int error;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
@@ -43,7 +43,7 @@ int merge_trees_from_branches(
error = git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, opts);
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
@@ -61,21 +61,21 @@ int merge_commits_from_branches(
{
git_commit *our_commit, *their_commit;
git_oid our_oid, their_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
int error;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
error = git_merge_commits(index, repo, our_commit, their_commit, opts);
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_commit_free(our_commit);
git_commit_free(their_commit);
@@ -328,12 +328,12 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[],
return 1;
}
-int dircount(void *payload, git_buf *pathbuf)
+int dircount(void *payload, git_str *pathbuf)
{
size_t *entries = payload;
- size_t len = git_buf_len(pathbuf);
+ size_t len = git_str_len(pathbuf);
- if (len < 5 || strcmp(pathbuf->ptr + (git_buf_len(pathbuf) - 5), "/.git") != 0)
+ if (len < 5 || strcmp(pathbuf->ptr + (git_str_len(pathbuf) - 5), "/.git") != 0)
(*entries)++;
return 0;
@@ -343,9 +343,9 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
{
size_t actual_len = 0, i;
git_oid actual_oid, expected_oid;
- git_buf wd = GIT_BUF_INIT;
+ git_str wd = GIT_STR_INIT;
- git_buf_puts(&wd, repo->workdir);
+ git_str_puts(&wd, repo->workdir);
git_path_direach(&wd, 0, dircount, &actual_len);
if (actual_len != expected_len)
@@ -359,7 +359,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
return 0;
}
- git_buf_dispose(&wd);
+ git_str_dispose(&wd);
return 1;
}
diff --git a/tests/merge/trees/automerge.c b/tests/merge/trees/automerge.c
index dd26464fb..3bf6c5208 100644
--- a/tests/merge/trees/automerge.c
+++ b/tests/merge/trees/automerge.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "futils.h"
#include "../merge_helpers.h"
diff --git a/tests/merge/trees/modeconflict.c b/tests/merge/trees/modeconflict.c
index 32866ea6d..a0521c4e8 100644
--- a/tests/merge/trees/modeconflict.c
+++ b/tests/merge/trees/modeconflict.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
diff --git a/tests/merge/trees/renames.c b/tests/merge/trees/renames.c
index eef7bc96b..26f6d3306 100644
--- a/tests/merge/trees/renames.c
+++ b/tests/merge/trees/renames.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
@@ -279,7 +278,7 @@ void test_merge_trees_renames__cache_recomputation(void)
{
git_oid blob, binary, ancestor_oid, theirs_oid, ours_oid;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_treebuilder *builder;
git_tree *ancestor_tree, *their_tree, *our_tree;
git_index *index;
@@ -307,9 +306,9 @@ void test_merge_trees_renames__cache_recomputation(void)
*/
cl_git_pass(git_treebuilder_new(&builder, repo, NULL));
for (i = 0; i < 1000; i++) {
- cl_git_pass(git_buf_printf(&path, "%"PRIuZ".txt", i));
+ cl_git_pass(git_str_printf(&path, "%"PRIuZ".txt", i));
cl_git_pass(git_treebuilder_insert(NULL, builder, path.ptr, &blob, GIT_FILEMODE_BLOB));
- git_buf_clear(&path);
+ git_str_clear(&path);
}
cl_git_pass(git_treebuilder_insert(NULL, builder, "original.bin", &binary, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_write(&ancestor_oid, builder));
@@ -344,7 +343,7 @@ void test_merge_trees_renames__cache_recomputation(void)
cl_git_pass(git_merge_trees(&index, repo, ancestor_tree, our_tree, their_tree, &opts));
git_treebuilder_free(builder);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_index_free(index);
git_tree_free(ancestor_tree);
git_tree_free(their_tree);
diff --git a/tests/merge/trees/trivial.c b/tests/merge/trees/trivial.c
index ac4f09f80..dce392c86 100644
--- a/tests/merge/trees/trivial.c
+++ b/tests/merge/trees/trivial.c
@@ -30,15 +30,15 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
git_commit *our_commit, *their_commit, *ancestor_commit;
git_tree *our_tree, *their_tree, *ancestor_tree;
git_oid our_oid, their_oid, ancestor_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
@@ -51,7 +51,7 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
cl_git_pass(git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, &opts));
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
diff --git a/tests/merge/trees/whitespace.c b/tests/merge/trees/whitespace.c
index ce7703496..9917df506 100644
--- a/tests/merge/trees/whitespace.c
+++ b/tests/merge/trees/whitespace.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index 6044bca43..b9c2ad033 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "index.h"
#include "../merge_helpers.h"
@@ -109,29 +108,29 @@ static int merge_branch(void)
static void write_files(char *files[])
{
char *filename;
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
size_t i;
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
- git_buf_clear(&path);
- git_buf_clear(&content);
+ git_str_clear(&path);
+ git_str_clear(&content);
- git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename);
- git_buf_printf(&content, "This is a dirty file in the working directory!\n\n"
+ git_str_printf(&path, "%s/%s", TEST_REPO_PATH, filename);
+ git_str_printf(&content, "This is a dirty file in the working directory!\n\n"
"It will not be staged! Its filename is %s.\n", filename);
cl_git_mkfile(path.ptr, content.ptr);
}
- git_buf_dispose(&path);
- git_buf_dispose(&content);
+ git_str_dispose(&path);
+ git_str_dispose(&content);
}
static void hack_index(char *files[])
{
char *filename;
struct stat statbuf;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_index_entry *entry;
struct p_timeval times[2];
time_t now;
@@ -153,12 +152,12 @@ static void hack_index(char *files[])
times[1].tv_usec = 0;
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
- git_buf_clear(&path);
+ git_str_clear(&path);
cl_assert(entry = (git_index_entry *)
git_index_get_bypath(repo_index, filename, 0));
- cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
+ cl_git_pass(git_str_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_pass(p_utimes(path.ptr, times));
cl_git_pass(p_stat(path.ptr, &statbuf));
@@ -178,7 +177,7 @@ static void hack_index(char *files[])
entry->file_size = (uint32_t)statbuf.st_size;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void stage_random_files(char *files[])
@@ -196,7 +195,7 @@ static void stage_content(char *content[])
{
git_reference *head;
git_object *head_object;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
char *filename, *text;
size_t i;
@@ -208,9 +207,9 @@ static void stage_content(char *content[])
filename && text;
filename = content[++i], text = content[++i]) {
- git_buf_clear(&path);
+ git_str_clear(&path);
- cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
+ cl_git_pass(git_str_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_mkfile(path.ptr, text);
cl_git_pass(git_index_add_bypath(repo_index, filename));
@@ -218,7 +217,7 @@ static void stage_content(char *content[])
git_object_free(head_object);
git_reference_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static int merge_dirty_files(char *dirty_files[])
diff --git a/tests/merge/workdir/recursive.c b/tests/merge/workdir/recursive.c
index e7dc267e4..7669e1b1a 100644
--- a/tests/merge/workdir/recursive.c
+++ b/tests/merge/workdir/recursive.c
@@ -23,7 +23,7 @@ void test_merge_workdir_recursive__writes_conflict_with_virtual_base(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -46,7 +46,7 @@ void test_merge_workdir_recursive__writes_conflict_with_virtual_base(void)
cl_assert_equal_s(CONFLICTING_RECURSIVE_F1_TO_F2, conflicting_buf.ptr);
git_index_free(index);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
}
void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
@@ -54,7 +54,7 @@ void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -80,5 +80,5 @@ void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
cl_assert_equal_s(CONFLICTING_RECURSIVE_H2_TO_H1_WITH_DIFF3, conflicting_buf.ptr);
git_index_free(index);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
}
diff --git a/tests/merge/workdir/renames.c b/tests/merge/workdir/renames.c
index e8cd333af..1b5128cf1 100644
--- a/tests/merge/workdir/renames.c
+++ b/tests/merge/workdir/renames.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index 0b85f2712..fe33e21f2 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -46,29 +46,29 @@ void test_merge_workdir_setup__cleanup(void)
static bool test_file_contents(const char *filename, const char *expected)
{
- git_buf file_path_buf = GIT_BUF_INIT, file_buf = GIT_BUF_INIT;
+ git_str file_path_buf = GIT_STR_INIT, file_buf = GIT_STR_INIT;
bool equals;
- git_buf_joinpath(&file_path_buf, git_repository_path(repo), filename);
+ git_str_joinpath(&file_path_buf, git_repository_path(repo), filename);
cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr));
equals = (strcmp(file_buf.ptr, expected) == 0);
- git_buf_dispose(&file_path_buf);
- git_buf_dispose(&file_buf);
+ git_str_dispose(&file_path_buf);
+ git_str_dispose(&file_buf);
return equals;
}
static void write_file_contents(const char *filename, const char *output)
{
- git_buf file_path_buf = GIT_BUF_INIT;
+ git_str file_path_buf = GIT_STR_INIT;
- git_buf_joinpath(&file_path_buf, git_repository_path(repo),
+ git_str_joinpath(&file_path_buf, git_repository_path(repo),
filename);
cl_git_rewritefile(file_path_buf.ptr, output);
- git_buf_dispose(&file_path_buf);
+ git_str_dispose(&file_path_buf);
}
/* git merge --no-ff octo1 */
@@ -464,41 +464,41 @@ static int create_remote_tracking_branch(const char *branch_name, const char *oi
{
int error = 0;
- git_buf remotes_path = GIT_BUF_INIT,
- origin_path = GIT_BUF_INIT,
- filename = GIT_BUF_INIT,
- data = GIT_BUF_INIT;
+ git_str remotes_path = GIT_STR_INIT,
+ origin_path = GIT_STR_INIT,
+ filename = GIT_STR_INIT,
+ data = GIT_STR_INIT;
- if ((error = git_buf_puts(&remotes_path, git_repository_path(repo))) < 0 ||
- (error = git_buf_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
+ if ((error = git_str_puts(&remotes_path, git_repository_path(repo))) < 0 ||
+ (error = git_str_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
goto done;
- if (!git_path_exists(git_buf_cstr(&remotes_path)) &&
- (error = p_mkdir(git_buf_cstr(&remotes_path), 0777)) < 0)
+ if (!git_path_exists(git_str_cstr(&remotes_path)) &&
+ (error = p_mkdir(git_str_cstr(&remotes_path), 0777)) < 0)
goto done;
- if ((error = git_buf_puts(&origin_path, git_buf_cstr(&remotes_path))) < 0 ||
- (error = git_buf_puts(&origin_path, "origin")) < 0)
+ if ((error = git_str_puts(&origin_path, git_str_cstr(&remotes_path))) < 0 ||
+ (error = git_str_puts(&origin_path, "origin")) < 0)
goto done;
- if (!git_path_exists(git_buf_cstr(&origin_path)) &&
- (error = p_mkdir(git_buf_cstr(&origin_path), 0777)) < 0)
+ if (!git_path_exists(git_str_cstr(&origin_path)) &&
+ (error = p_mkdir(git_str_cstr(&origin_path), 0777)) < 0)
goto done;
- if ((error = git_buf_puts(&filename, git_buf_cstr(&origin_path))) < 0 ||
- (error = git_buf_puts(&filename, "/")) < 0 ||
- (error = git_buf_puts(&filename, branch_name)) < 0 ||
- (error = git_buf_puts(&data, oid_str)) < 0 ||
- (error = git_buf_puts(&data, "\n")) < 0)
+ if ((error = git_str_puts(&filename, git_str_cstr(&origin_path))) < 0 ||
+ (error = git_str_puts(&filename, "/")) < 0 ||
+ (error = git_str_puts(&filename, branch_name)) < 0 ||
+ (error = git_str_puts(&data, oid_str)) < 0 ||
+ (error = git_str_puts(&data, "\n")) < 0)
goto done;
- cl_git_rewritefile(git_buf_cstr(&filename), git_buf_cstr(&data));
+ cl_git_rewritefile(git_str_cstr(&filename), git_str_cstr(&data));
done:
- git_buf_dispose(&remotes_path);
- git_buf_dispose(&origin_path);
- git_buf_dispose(&filename);
- git_buf_dispose(&data);
+ git_str_dispose(&remotes_path);
+ git_str_dispose(&origin_path);
+ git_str_dispose(&filename);
+ git_str_dispose(&data);
return error;
}
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index 6b4e17492..6c4cf7e3c 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "../conflict_data.h"
@@ -126,7 +125,7 @@ void test_merge_workdir_simple__automerge(void)
{
git_index *index;
const git_index_entry *entry;
- git_buf automergeable_buf = GIT_BUF_INIT;
+ git_str automergeable_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -155,7 +154,7 @@ void test_merge_workdir_simple__automerge(void)
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
cl_assert(strcmp(automergeable_buf.ptr, AUTOMERGEABLE_MERGED_FILE) == 0);
- git_buf_dispose(&automergeable_buf);
+ git_str_dispose(&automergeable_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -202,7 +201,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
#ifdef GIT_WIN32
git_index *index;
const git_index_entry *entry;
- git_buf automergeable_buf = GIT_BUF_INIT;
+ git_str automergeable_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -230,7 +229,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
cl_assert(strcmp(automergeable_buf.ptr, AUTOMERGEABLE_MERGED_FILE_CRLF) == 0);
- git_buf_dispose(&automergeable_buf);
+ git_str_dispose(&automergeable_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -246,7 +245,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
void test_merge_workdir_simple__mergefile(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -276,13 +275,13 @@ void test_merge_workdir_simple__mergefile(void)
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
- cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
+ cl_assert(strcmp(git_str_cstr(&mergemsg_buf),
"Merge commit '7cb63eed597130ba4abb87b3e544b85021905520'\n" \
"\n" \
"Conflicts:\n" \
"\tconflicting.txt\n") == 0);
- git_buf_dispose(&conflicting_buf);
- git_buf_dispose(&mergemsg_buf);
+ git_str_dispose(&conflicting_buf);
+ git_str_dispose(&mergemsg_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -290,7 +289,7 @@ void test_merge_workdir_simple__mergefile(void)
void test_merge_workdir_simple__diff3(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -318,7 +317,7 @@ void test_merge_workdir_simple__diff3(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -326,7 +325,7 @@ void test_merge_workdir_simple__diff3(void)
void test_merge_workdir_simple__union(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -353,7 +352,7 @@ void test_merge_workdir_simple__union(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
@@ -361,7 +360,7 @@ void test_merge_workdir_simple__union(void)
void test_merge_workdir_simple__gitattributes_union(void)
{
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -389,7 +388,7 @@ void test_merge_workdir_simple__gitattributes_union(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
@@ -398,7 +397,7 @@ void test_merge_workdir_simple__gitattributes_union(void)
void test_merge_workdir_simple__diff3_from_config(void)
{
git_config *config;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -429,7 +428,7 @@ void test_merge_workdir_simple__diff3_from_config(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
@@ -440,7 +439,7 @@ void test_merge_workdir_simple__diff3_from_config(void)
void test_merge_workdir_simple__merge_overrides_config(void)
{
git_config *config;
- git_buf conflicting_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -471,7 +470,7 @@ void test_merge_workdir_simple__merge_overrides_config(void)
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
diff --git a/tests/merge/workdir/submodules.c b/tests/merge/workdir/submodules.c
index 35280e61e..5117be789 100644
--- a/tests/merge/workdir/submodules.c
+++ b/tests/merge/workdir/submodules.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
-#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
diff --git a/tests/merge/workdir/trivial.c b/tests/merge/workdir/trivial.c
index c5bb7030e..fe8374851 100644
--- a/tests/merge/workdir/trivial.c
+++ b/tests/merge/workdir/trivial.c
@@ -30,26 +30,26 @@ void test_merge_workdir_trivial__cleanup(void)
static int merge_trivial(const char *ours, const char *theirs)
{
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *our_ref, *their_ref;
git_annotated_commit *their_heads[1];
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1, NULL));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, their_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL));
- git_buf_dispose(&branch_buf);
+ git_str_dispose(&branch_buf);
git_reference_free(our_ref);
git_reference_free(their_ref);
git_annotated_commit_free(their_heads[0]);
diff --git a/tests/message/trailer.c b/tests/message/trailer.c
index 9cc83de72..919e10a49 100644
--- a/tests/message/trailer.c
+++ b/tests/message/trailer.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "message.h"
static void assert_trailers(const char *message, git_message_trailer *trailers)
{
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index 13f03100b..302d1544c 100644
--- a/tests/network/fetchlocal.c
+++ b/tests/network/fetchlocal.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "remote.h"
diff --git a/tests/network/remote/defaultbranch.c b/tests/network/remote/defaultbranch.c
index b0417f764..a7c0d81f6 100644
--- a/tests/network/remote/defaultbranch.c
+++ b/tests/network/remote/defaultbranch.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "refspec.h"
#include "remote.h"
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index 16cce6777..f174044d7 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -1,11 +1,10 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "posix.h"
#include "git2/sys/repository.h"
static git_repository *repo;
-static git_buf file_path_buf = GIT_BUF_INIT;
+static git_str file_path_buf = GIT_STR_INIT;
static git_remote *remote;
static char *push_refspec_strings[] = {
@@ -25,7 +24,7 @@ void test_network_remote_local__initialize(void)
void test_network_remote_local__cleanup(void)
{
- git_buf_dispose(&file_path_buf);
+ git_str_dispose(&file_path_buf);
git_remote_free(remote);
remote = NULL;
@@ -38,9 +37,9 @@ void test_network_remote_local__cleanup(void)
static void connect_to_local_repository(const char *local_repository)
{
- git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
+ git_str_sets(&file_path_buf, cl_git_path_url(local_repository));
- cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_create_anonymous(&remote, repo, git_str_cstr(&file_path_buf)));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
}
@@ -70,9 +69,9 @@ void test_network_remote_local__retrieve_advertised_before_connect(void)
const git_remote_head **refs;
size_t refs_len = 0;
- git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
+ git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
- cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_create_anonymous(&remote, repo, git_str_cstr(&file_path_buf)));
cl_git_fail(git_remote_ls(&refs, &refs_len, remote));
}
@@ -472,10 +471,10 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void)
git_repository *inmemory;
git_remote *remote;
- git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
+ git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
cl_git_pass(git_repository_new(&inmemory));
- cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_buf_cstr(&file_path_buf)));
+ cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_str_cstr(&file_path_buf)));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
cl_assert(git_remote_connected(remote));
git_remote_disconnect(remote);
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index ed6a89075..79c4f39fa 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "config/config_helpers.h"
-#include "buffer.h"
#include "refspec.h"
#include "remote.h"
@@ -28,7 +27,7 @@ void test_network_remote_remotes__cleanup(void)
void test_network_remote_remotes__parsing(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_remote *_remote2 = NULL;
cl_assert_equal_s(git_remote_name(_remote), "test");
@@ -53,7 +52,7 @@ void test_network_remote_remotes__parsing(void)
cl_assert_equal_s(url.ptr, "git://github.com/libgit2/pushlibgit2");
git_remote_free(_remote2);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
static int remote_ready_callback(git_remote *remote, int direction, void *payload)
@@ -79,7 +78,7 @@ static int remote_ready_callback(git_remote *remote, int direction, void *payloa
void test_network_remote_remotes__remote_ready(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
callbacks.remote_ready = remote_ready_callback;
@@ -95,29 +94,31 @@ void test_network_remote_remotes__remote_ready(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
cl_assert_equal_s(url.ptr, "push_url");
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
#ifndef GIT_DEPRECATE_HARD
static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
{
+ int error = -1;
+
cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0);
cl_assert(strcmp(payload, "payload") == 0);
cl_assert(url_resolved->size == 0);
if (direction == GIT_DIRECTION_PUSH)
- git_buf_sets(url_resolved, "pushresolve");
+ error = git_buf_set(url_resolved, "pushresolve", strlen("pushresolve") + 1);
if (direction == GIT_DIRECTION_FETCH)
- git_buf_sets(url_resolved, "fetchresolve");
+ error = git_buf_set(url_resolved, "fetchresolve", strlen("fetchresolve") + 1);
- return GIT_OK;
+ return error;
}
#endif
void test_network_remote_remotes__urlresolve(void)
{
#ifndef GIT_DEPRECATE_HARD
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
callbacks.resolve_url = urlresolve_callback;
@@ -133,7 +134,7 @@ void test_network_remote_remotes__urlresolve(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
cl_assert_equal_s(url.ptr, "pushresolve");
- git_buf_dispose(&url);
+ git_str_dispose(&url);
#endif
}
@@ -151,7 +152,7 @@ static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *ur
void test_network_remote_remotes__urlresolve_passthrough(void)
{
#ifndef GIT_DEPRECATE_HARD
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
const char *orig_url = "git://github.com/libgit2/libgit2";
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
@@ -167,13 +168,13 @@ void test_network_remote_remotes__urlresolve_passthrough(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
cl_assert_equal_s(url.ptr, orig_url);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
#endif
}
void test_network_remote_remotes__instance_url(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
const char *orig_url = "git://github.com/libgit2/libgit2";
cl_assert_equal_s(git_remote_name(_remote), "test");
@@ -181,11 +182,11 @@ void test_network_remote_remotes__instance_url(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_s(url.ptr, orig_url);
- git_buf_clear(&url);
+ git_str_clear(&url);
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
cl_assert_equal_s(url.ptr, orig_url);
- git_buf_clear(&url);
+ git_str_clear(&url);
/* Setting the instance url updates the fetch and push URLs */
git_remote_set_instance_url(_remote, "https://github.com/new/remote/url");
@@ -194,11 +195,11 @@ void test_network_remote_remotes__instance_url(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
/* Setting the instance push url updates only the push URL */
git_remote_set_instance_pushurl(_remote, "https://github.com/new/push/url");
@@ -207,13 +208,13 @@ void test_network_remote_remotes__instance_url(void)
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
cl_assert_equal_s(url.ptr, "https://github.com/new/push/url");
- git_buf_clear(&url);
+ git_str_clear(&url);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_network_remote_remotes__pushurl(void)
diff --git a/tests/notes/notes.c b/tests/notes/notes.c
index af9686790..dd9ad1e4b 100644
--- a/tests/notes/notes.c
+++ b/tests/notes/notes.c
@@ -1,7 +1,5 @@
#include "clar_libgit2.h"
-#include "buffer.h"
-
static git_repository *_repo;
static git_signature *_sig;
@@ -282,7 +280,7 @@ void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_def
create_note(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
cl_git_pass(git_note_read(&note, _repo, NULL, &target_oid));
- cl_git_pass(git_note_read(&default_namespace_note, _repo, git_buf_cstr(&default_ref), &target_oid));
+ cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref.ptr, &target_oid));
assert_note_equal(note, "hello world\n", &note_oid);
assert_note_equal(default_namespace_note, "hello world\n", &note_oid);
diff --git a/tests/notes/notesref.c b/tests/notes/notesref.c
index 3bcb05f20..6ba324c76 100644
--- a/tests/notes/notesref.c
+++ b/tests/notes/notesref.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "notes.h"
-#include "buffer.h"
static git_repository *_repo;
static git_note *_note;
@@ -57,7 +56,7 @@ void test_notes_notesref__config_corenotesref(void)
cl_git_pass(git_note_default_ref(&default_ref, _repo));
cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref.ptr);
- git_buf_clear(&default_ref);
+ git_buf_dispose(&default_ref);
cl_git_pass(git_config_delete_entry(_cfg, "core.notesRef"));
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index a8e3d3097..00b553e71 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -24,7 +24,7 @@ static off64_t g_crlf_raw_len[CRLF_NUM_TEST_OBJECTS] = {
static git_oid g_crlf_oids[CRLF_NUM_TEST_OBJECTS];
-static git_buf g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
+static git_str g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
{ "", 0, 0 },
{ "foo\nbar\n", 0, 8 },
{ "foo\rbar\r", 0, 8 },
@@ -36,16 +36,16 @@ static git_buf g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
{ "\xFE\xFF\x00T\x00h\x00i\x00s\x00!", 0, 12 }
};
-static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
+static git_str_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
{ 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 2, 0, 6, 0 },
{ 0, 0, 2, 0, 0, 6, 0 },
{ 0, 0, 2, 2, 2, 6, 0 },
{ 0, 0, 4, 4, 1, 31, 0 },
{ 0, 1, 1, 2, 1, 9, 5 },
- { GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
- { GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
- { GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
+ { GIT_STR_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
+ { GIT_STR_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
+ { GIT_STR_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
};
void test_object_blob_filter__initialize(void)
@@ -90,19 +90,19 @@ void test_object_blob_filter__stats(void)
{
int i;
git_blob *blob;
- git_buf buf = GIT_BUF_INIT;
- git_buf_text_stats stats;
+ git_str buf = GIT_STR_INIT;
+ git_str_text_stats stats;
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
cl_git_pass(git_blob__getbuf(&buf, blob));
- git_buf_gather_text_stats(&stats, &buf, false);
+ git_str_gather_text_stats(&stats, &buf, false);
cl_assert_equal_i(
0, memcmp(&g_crlf_filtered_stats[i], &stats, sizeof(stats)));
git_blob_free(blob);
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_object_blob_filter__to_odb(void)
diff --git a/tests/object/blob/fromstream.c b/tests/object/blob/fromstream.c
index df229f98f..60ff3991b 100644
--- a/tests/object/blob/fromstream.c
+++ b/tests/object/blob/fromstream.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
@@ -48,15 +47,15 @@ void test_object_blob_fromstream__multiple_write(void)
static void write_attributes(git_repository *repo)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "info"));
- cl_git_pass(git_buf_joinpath(&buf, git_buf_cstr(&buf), "attributes"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_path(repo), "info"));
+ cl_git_pass(git_str_joinpath(&buf, git_str_cstr(&buf), "attributes"));
- cl_git_pass(git_futils_mkpath2file(git_buf_cstr(&buf), 0777));
- cl_git_rewritefile(git_buf_cstr(&buf), GITATTR);
+ cl_git_pass(git_futils_mkpath2file(git_str_cstr(&buf), 0777));
+ cl_git_rewritefile(git_str_cstr(&buf), GITATTR);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void assert_named_chunked_blob(const char *expected_sha, const char *fake_name)
diff --git a/tests/object/blob/write.c b/tests/object/blob/write.c
index 9a18d7cd4..802467498 100644
--- a/tests/object/blob/write.c
+++ b/tests/object/blob/write.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
@@ -38,32 +37,32 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
{
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
repo = cl_git_sandbox_init(WORKDIR);
cl_must_pass(p_mkdir(ELSEWHERE, 0777));
cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
- cl_must_pass(git_buf_puts(&full_path, "test.txt"));
+ cl_must_pass(git_str_puts(&full_path, "test.txt"));
- assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
+ assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void)
{
- git_buf full_path = GIT_BUF_INIT;
+ git_str full_path = GIT_STR_INIT;
repo = cl_git_sandbox_init(BARE_REPO);
cl_must_pass(p_mkdir(ELSEWHERE, 0777));
cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
- cl_must_pass(git_buf_puts(&full_path, "test.txt"));
+ cl_must_pass(git_str_puts(&full_path, "test.txt"));
- assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
+ assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk);
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/object/commit/commitstagedfile.c b/tests/object/commit/commitstagedfile.c
index f7ff05c01..7322a4e86 100644
--- a/tests/object/commit/commitstagedfile.c
+++ b/tests/object/commit/commitstagedfile.c
@@ -25,7 +25,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
git_signature *signature;
git_tree *tree;
- git_buf buffer;
+ git_buf buffer = GIT_BUF_INIT;
/*
* The test below replicates the following git scenario
@@ -111,7 +111,6 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
- memset(&buffer, 0, sizeof(git_buf));
cl_git_pass(git_message_prettify(&buffer, "Initial commit", 0, '#'));
cl_git_pass(git_commit_create_v(
diff --git a/tests/object/lookup.c b/tests/object/lookup.c
index 2458537fc..a7b1ceeb4 100644
--- a/tests/object/lookup.c
+++ b/tests/object/lookup.c
@@ -66,13 +66,13 @@ void test_object_lookup__lookup_corrupt_object_returns_error(void)
{
const char *commit = "8e73b769e97678d684b809b163bebdae2911720f",
*file = "objects/8e/73b769e97678d684b809b163bebdae2911720f";
- git_buf path = GIT_BUF_INIT, contents = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, contents = GIT_STR_INIT;
git_oid oid;
git_object *object;
size_t i;
cl_git_pass(git_oid_fromstr(&oid, commit));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), file));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), file));
cl_git_pass(git_futils_readbuffer(&contents, path.ptr));
/* Corrupt and try to read the object */
@@ -88,8 +88,8 @@ void test_object_lookup__lookup_corrupt_object_returns_error(void)
cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
git_object_free(object);
- git_buf_dispose(&path);
- git_buf_dispose(&contents);
+ git_str_dispose(&path);
+ git_str_dispose(&contents);
}
void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
@@ -97,15 +97,15 @@ void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
const char *oldloose = "objects/8e/73b769e97678d684b809b163bebdae2911720f",
*newloose = "objects/8e/73b769e97678d684b809b163bebdae2911720e",
*commit = "8e73b769e97678d684b809b163bebdae2911720e";
- git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
+ git_str oldpath = GIT_STR_INIT, newpath = GIT_STR_INIT;
git_object *object;
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, commit));
/* Copy object to another location with wrong hash */
- cl_git_pass(git_buf_joinpath(&oldpath, git_repository_path(g_repo), oldloose));
- cl_git_pass(git_buf_joinpath(&newpath, git_repository_path(g_repo), newloose));
+ cl_git_pass(git_str_joinpath(&oldpath, git_repository_path(g_repo), oldloose));
+ cl_git_pass(git_str_joinpath(&newpath, git_repository_path(g_repo), newloose));
cl_git_pass(git_futils_cp(oldpath.ptr, newpath.ptr, 0644));
/* Verify that lookup fails due to a hashsum mismatch */
@@ -117,6 +117,6 @@ void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1));
git_object_free(object);
- git_buf_dispose(&oldpath);
- git_buf_dispose(&newpath);
+ git_str_dispose(&oldpath);
+ git_str_dispose(&newpath);
}
diff --git a/tests/object/message.c b/tests/object/message.c
index bc005340b..d87c8ef70 100644
--- a/tests/object/message.c
+++ b/tests/object/message.c
@@ -1,13 +1,11 @@
#include "clar_libgit2.h"
-#include "buffer.h"
-#include "message.h"
static void assert_message_prettifying(char *expected_output, char *input, int strip_comments)
{
git_buf prettified_message = GIT_BUF_INIT;
git_message_prettify(&prettified_message, input, strip_comments, '#');
- cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message));
+ cl_assert_equal_s(expected_output, prettified_message.ptr);
git_buf_dispose(&prettified_message);
}
diff --git a/tests/object/raw/hash.c b/tests/object/raw/hash.c
index 3be1f83b3..5a3e81855 100644
--- a/tests/object/raw/hash.c
+++ b/tests/object/raw/hash.c
@@ -56,7 +56,7 @@ void test_object_raw_hash__hash_buffer_in_single_call(void)
void test_object_raw_hash__hash_vector(void)
{
git_oid id1, id2;
- git_buf_vec vec[2];
+ git_str_vec vec[2];
cl_git_pass(git_oid_fromstr(&id1, hello_id));
diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c
index 1bc5a50a0..a4ceb35b6 100644
--- a/tests/object/tree/write.c
+++ b/tests/object/tree/write.c
@@ -394,12 +394,12 @@ void test_object_tree_write__cruel_paths(void)
for (i = 0; i < count; ++i) {
for (j = 0; j < count; ++j) {
- git_buf b = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&b, the_paths[i], the_paths[j]));
+ git_str b = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&b, the_paths[i], the_paths[j]));
cl_git_pass(git_tree_entry_bypath(&te, tree, b.ptr));
cl_assert_equal_s(the_paths[j], git_tree_entry_name(te));
git_tree_entry_free(te);
- git_buf_dispose(&b);
+ git_str_dispose(&b);
}
}
diff --git a/tests/odb/alternates.c b/tests/odb/alternates.c
index f65a44bb5..e36010b75 100644
--- a/tests/odb/alternates.c
+++ b/tests/odb/alternates.c
@@ -2,7 +2,7 @@
#include "odb.h"
#include "filebuf.h"
-static git_buf destpath, filepath;
+static git_str destpath, filepath;
static const char *paths[] = {
"A.git", "B.git", "C.git", "D.git", "E.git", "F.git", "G.git"
};
@@ -13,8 +13,8 @@ void test_odb_alternates__cleanup(void)
{
size_t i;
- git_buf_dispose(&destpath);
- git_buf_dispose(&filepath);
+ git_str_dispose(&destpath);
+ git_str_dispose(&filepath);
for (i = 0; i < ARRAY_SIZE(paths); i++)
cl_fixture_cleanup(paths[i]);
@@ -22,18 +22,18 @@ void test_odb_alternates__cleanup(void)
static void init_linked_repo(const char *path, const char *alternate)
{
- git_buf_clear(&destpath);
- git_buf_clear(&filepath);
+ git_str_clear(&destpath);
+ git_str_clear(&filepath);
cl_git_pass(git_repository_init(&repo, path, 1));
cl_git_pass(git_path_prettify(&destpath, alternate, NULL));
- cl_git_pass(git_buf_joinpath(&destpath, destpath.ptr, "objects"));
- cl_git_pass(git_buf_joinpath(&filepath, git_repository_path(repo), "objects/info"));
+ cl_git_pass(git_str_joinpath(&destpath, destpath.ptr, "objects"));
+ cl_git_pass(git_str_joinpath(&filepath, git_repository_path(repo), "objects/info"));
cl_git_pass(git_futils_mkdir(filepath.ptr, 0755, GIT_MKDIR_PATH));
- cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
+ cl_git_pass(git_str_joinpath(&filepath, filepath.ptr , "alternates"));
- cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0, 0666));
- git_filebuf_printf(&file, "%s\n", git_buf_cstr(&destpath));
+ cl_git_pass(git_filebuf_open(&file, git_str_cstr(&filepath), 0, 0666));
+ git_filebuf_printf(&file, "%s\n", git_str_cstr(&destpath));
cl_git_pass(git_filebuf_commit(&file));
git_repository_free(repo);
diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c
index 02112380b..c2a448363 100644
--- a/tests/odb/foreach.c
+++ b/tests/odb/foreach.c
@@ -2,7 +2,6 @@
#include "odb.h"
#include "git2/odb_backend.h"
#include "pack.h"
-#include "buffer.h"
static git_odb *_odb;
static git_repository *_repo;
@@ -121,15 +120,15 @@ void test_odb_foreach__files_in_objects_dir(void)
{
git_repository *repo;
git_odb *odb;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int nobj = 0;
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
- cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "objects/somefile"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_path(repo), "objects/somefile"));
cl_git_mkfile(buf.ptr, "");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_foreach(odb, foreach_cb, &nobj));
diff --git a/tests/odb/freshen.c b/tests/odb/freshen.c
index 1ecd92a8d..2396e3774 100644
--- a/tests/odb/freshen.c
+++ b/tests/odb/freshen.c
@@ -19,7 +19,7 @@ void test_odb_freshen__cleanup(void)
static void set_time_wayback(struct stat *out, const char *fn)
{
- git_buf fullpath = GIT_BUF_INIT;
+ git_str fullpath = GIT_STR_INIT;
struct p_timeval old[2];
old[0].tv_sec = 1234567890;
@@ -27,11 +27,11 @@ static void set_time_wayback(struct stat *out, const char *fn)
old[1].tv_sec = 1234567890;
old[1].tv_usec = 0;
- git_buf_joinpath(&fullpath, "testrepo.git/objects", fn);
+ git_str_joinpath(&fullpath, "testrepo.git/objects", fn);
- cl_must_pass(p_utimes(git_buf_cstr(&fullpath), old));
- cl_must_pass(p_lstat(git_buf_cstr(&fullpath), out));
- git_buf_dispose(&fullpath);
+ cl_must_pass(p_utimes(git_str_cstr(&fullpath), old));
+ cl_must_pass(p_lstat(git_str_cstr(&fullpath), out));
+ git_str_dispose(&fullpath);
}
#define LOOSE_STR "my new file\n"
diff --git a/tests/odb/largefiles.c b/tests/odb/largefiles.c
index ff82291b3..acc786ee4 100644
--- a/tests/odb/largefiles.c
+++ b/tests/odb/largefiles.c
@@ -23,11 +23,11 @@ void test_odb_largefiles__cleanup(void)
static void writefile(git_oid *oid)
{
static git_odb_stream *stream;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t i;
for (i = 0; i < 3041; i++)
- cl_git_pass(git_buf_puts(&buf, "Hello, world.\n"));
+ cl_git_pass(git_str_puts(&buf, "Hello, world.\n"));
cl_git_pass(git_odb_open_wstream(&stream, odb, LARGEFILE_SIZE, GIT_OBJECT_BLOB));
for (i = 0; i < 126103; i++)
@@ -36,13 +36,13 @@ static void writefile(git_oid *oid)
cl_git_pass(git_odb_stream_finalize_write(oid, stream));
git_odb_stream_free(stream);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_odb_largefiles__write_from_memory(void)
{
git_oid expected, oid;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
size_t i;
#ifndef GIT_ARCH_64
@@ -55,7 +55,7 @@ void test_odb_largefiles__write_from_memory(void)
cl_skip();
for (i = 0; i < (3041*126103); i++)
- cl_git_pass(git_buf_puts(&buf, "Hello, world.\n"));
+ cl_git_pass(git_str_puts(&buf, "Hello, world.\n"));
git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c");
cl_git_pass(git_odb_write(&oid, odb, buf.ptr, buf.size, GIT_OBJECT_BLOB));
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 7d43c6a09..c55cf9f95 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -180,7 +180,7 @@ static int fetch_progress(const git_indexer_progress *stats, void *payload)
void test_online_clone__can_checkout_a_cloned_repo(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_reference *head, *remote_head;
bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false;
@@ -193,8 +193,8 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&path)));
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
@@ -209,7 +209,7 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
git_reference_free(remote_head);
git_reference_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static int remote_mirror_cb(git_remote **out, git_repository *repo,
@@ -406,16 +406,16 @@ void test_online_clone__credentials(void)
void test_online_clone__credentials_via_custom_headers(void)
{
const char *creds = "libgit3:libgit3";
- git_buf auth = GIT_BUF_INIT;
+ git_str auth = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&auth, "Authorization: Basic "));
- cl_git_pass(git_buf_encode_base64(&auth, creds, strlen(creds)));
+ cl_git_pass(git_str_puts(&auth, "Authorization: Basic "));
+ cl_git_pass(git_str_encode_base64(&auth, creds, strlen(creds)));
g_options.fetch_opts.custom_headers.count = 1;
g_options.fetch_opts.custom_headers.strings = &auth.ptr;
cl_git_pass(git_clone(&g_repo, "https://bitbucket.org/libgit2/testgitrepository.git", "./foo", &g_options));
- git_buf_dispose(&auth);
+ git_str_dispose(&auth);
}
void test_online_clone__bitbucket_style(void)
@@ -807,12 +807,12 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl
void test_online_clone__proxy_credentials_request(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_host));
@@ -824,17 +824,17 @@ void test_online_clone__proxy_credentials_request(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_url(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -845,12 +845,12 @@ void test_online_clone__proxy_credentials_in_url(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 0);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_environment(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
@@ -863,7 +863,7 @@ void test_online_clone__proxy_credentials_in_environment(void)
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -873,17 +873,17 @@ void test_online_clone__proxy_credentials_in_environment(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_url_https(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -895,7 +895,7 @@ void test_online_clone__proxy_credentials_in_url_https(void)
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 0);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__proxy_auto_not_detected(void)
@@ -907,12 +907,12 @@ void test_online_clone__proxy_auto_not_detected(void)
void test_online_clone__proxy_cred_callback_after_failed_url_creds(void)
{
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://invalid_user_name:INVALID_pass_WORD@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://invalid_user_name:INVALID_pass_WORD@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_host));
@@ -924,7 +924,7 @@ void test_online_clone__proxy_cred_callback_after_failed_url_creds(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
void test_online_clone__azurerepos(void)
diff --git a/tests/online/customcert.c b/tests/online/customcert.c
index c7a0de1a1..098212b14 100644
--- a/tests/online/customcert.c
+++ b/tests/online/customcert.c
@@ -28,22 +28,22 @@ void test_online_customcert__initialize(void)
g_repo = NULL;
if (!initialized) {
- git_buf path = GIT_BUF_INIT, file = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, file = GIT_STR_INIT;
char cwd[GIT_PATH_MAX];
cl_fixture_sandbox(CUSTOM_CERT_ONE_PATH);
cl_fixture_sandbox(CUSTOM_CERT_TWO_FILE);
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
- cl_git_pass(git_buf_joinpath(&path, cwd, CUSTOM_CERT_ONE_PATH));
- cl_git_pass(git_buf_joinpath(&file, cwd, CUSTOM_CERT_TWO_FILE));
+ cl_git_pass(git_str_joinpath(&path, cwd, CUSTOM_CERT_ONE_PATH));
+ cl_git_pass(git_str_joinpath(&file, cwd, CUSTOM_CERT_TWO_FILE));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS,
file.ptr, path.ptr));
initialized = true;
- git_buf_dispose(&file);
- git_buf_dispose(&path);
+ git_str_dispose(&file);
+ git_str_dispose(&path);
}
#endif
}
diff --git a/tests/online/fetch.c b/tests/online/fetch.c
index 67dfd69ed..914291015 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -226,13 +226,13 @@ void test_online_fetch__twice(void)
void test_online_fetch__proxy(void)
{
git_remote *remote;
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
git_fetch_options fetch_opts;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
- cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ cl_git_pass(git_str_printf(&url, "%s://%s:%s@%s/",
_remote_proxy_scheme ? _remote_proxy_scheme : "http",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
@@ -245,5 +245,5 @@ void test_online_fetch__proxy(void)
cl_git_pass(git_remote_fetch(remote, NULL, &fetch_opts, NULL));
git_remote_free(remote);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
diff --git a/tests/online/fetchhead.c b/tests/online/fetchhead.c
index b61993138..30cce3a90 100644
--- a/tests/online/fetchhead.c
+++ b/tests/online/fetchhead.c
@@ -52,7 +52,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
{
git_remote *remote;
git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
- git_buf fetchhead_buf = GIT_BUF_INIT;
+ git_str fetchhead_buf = GIT_STR_INIT;
int equals = 0;
git_strarray array, *active_refs = NULL;
@@ -72,7 +72,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
equals = (strcmp(fetchhead_buf.ptr, expected_fetchhead) == 0);
- git_buf_dispose(&fetchhead_buf);
+ git_str_dispose(&fetchhead_buf);
cl_assert(equals);
}
@@ -157,7 +157,7 @@ void test_online_fetchhead__colon_only_dst_refspec_creates_no_branch(void)
void test_online_fetchhead__creds_get_stripped(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_remote *remote;
cl_git_pass(git_repository_init(&g_repo, "./foo", 0));
@@ -169,5 +169,5 @@ void test_online_fetchhead__creds_get_stripped(void)
"49322bb17d3acc9146f98c97d078513228bbf3c0\t\thttps://github.com/libgit2/TestGitRepository\n");
git_remote_free(remote);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
diff --git a/tests/online/push.c b/tests/online/push.c
index c82b606cb..51adc3930 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "posix.h"
#include "vector.h"
#include "../submodule/submodule_helpers.h"
@@ -129,28 +128,28 @@ static void do_verify_push_status(record_callbacks_data *data, const push_status
}
if (failed) {
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
- git_buf_puts(&msg, "Expected and actual push statuses differ:\nEXPECTED:\n");
+ git_str_puts(&msg, "Expected and actual push statuses differ:\nEXPECTED:\n");
for(i = 0; i < expected_len; i++) {
- git_buf_printf(&msg, "%s: %s\n",
+ git_str_printf(&msg, "%s: %s\n",
expected[i].ref,
expected[i].success ? "success" : "failed");
}
- git_buf_puts(&msg, "\nACTUAL:\n");
+ git_str_puts(&msg, "\nACTUAL:\n");
git_vector_foreach(actual, i, iter) {
if (iter->success)
- git_buf_printf(&msg, "%s: success\n", iter->ref);
+ git_str_printf(&msg, "%s: success\n", iter->ref);
else
- git_buf_printf(&msg, "%s: failed with message: %s", iter->ref, iter->msg);
+ git_str_printf(&msg, "%s: failed with message: %s", iter->ref, iter->msg);
}
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
}
git_vector_foreach(actual, i, iter) {
@@ -192,7 +191,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
{
git_refspec *fetch_spec;
size_t i, j;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
git_buf ref_name = GIT_BUF_INIT;
git_vector actual_refs = GIT_VECTOR_INIT;
git_branch_iterator *iter;
@@ -230,12 +229,12 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
/* Find matching remote branch */
git_vector_foreach(&actual_refs, j, actual_ref) {
- if (!strcmp(git_buf_cstr(&ref_name), actual_ref))
+ if (!strcmp(ref_name.ptr, actual_ref))
break;
}
if (j == actual_refs.length) {
- git_buf_printf(&msg, "Did not find expected tracking branch '%s'.", git_buf_cstr(&ref_name));
+ git_str_printf(&msg, "Did not find expected tracking branch '%s'.", ref_name.ptr);
failed = 1;
goto failed;
}
@@ -244,7 +243,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
cl_git_pass(git_reference_name_to_id(&oid, remote->repo, actual_ref));
if (git_oid_cmp(expected_refs[i].oid, &oid) != 0) {
- git_buf_puts(&msg, "Tracking branch commit does not match expected ID.");
+ git_str_puts(&msg, "Tracking branch commit does not match expected ID.");
failed = 1;
goto failed;
}
@@ -255,27 +254,27 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
/* Make sure there are no extra branches */
if (actual_refs.length > 0) {
- git_buf_puts(&msg, "Unexpected remote tracking branches exist.");
+ git_str_puts(&msg, "Unexpected remote tracking branches exist.");
failed = 1;
goto failed;
}
failed:
if (failed)
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
git_vector_foreach(&actual_refs, i, actual_ref)
git__free(actual_ref);
git_vector_free(&actual_refs);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
git_buf_dispose(&ref_name);
}
static void verify_update_tips_callback(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
{
git_refspec *fetch_spec;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
git_buf ref_name = GIT_BUF_INIT;
updated_tip *tip = NULL;
size_t i, j;
@@ -293,18 +292,18 @@ static void verify_update_tips_callback(git_remote *remote, expected_ref expecte
/* Find matching update_tip entry */
git_vector_foreach(&_record_cbs_data.updated_tips, j, tip) {
- if (!strcmp(git_buf_cstr(&ref_name), tip->name))
+ if (!strcmp(ref_name.ptr, tip->name))
break;
}
if (j == _record_cbs_data.updated_tips.length) {
- git_buf_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", git_buf_cstr(&ref_name));
+ git_str_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", ref_name.ptr);
failed = 1;
goto failed;
}
if (git_oid_cmp(expected_refs[i].oid, &tip->new_oid) != 0) {
- git_buf_printf(&msg, "Updated tip ID does not match expected ID");
+ git_str_printf(&msg, "Updated tip ID does not match expected ID");
failed = 1;
goto failed;
}
@@ -312,10 +311,10 @@ static void verify_update_tips_callback(git_remote *remote, expected_ref expecte
failed:
if (failed)
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
git_buf_dispose(&ref_name);
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
}
void test_online_push__initialize(void)
diff --git a/tests/online/push_util.c b/tests/online/push_util.c
index b39f78114..94e310f3d 100644
--- a/tests/online/push_util.c
+++ b/tests/online/push_util.c
@@ -1,6 +1,4 @@
-
#include "clar_libgit2.h"
-#include "buffer.h"
#include "vector.h"
#include "push_util.h"
@@ -57,7 +55,7 @@ int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *
int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, size_t heads_len)
{
- git_buf del_spec = GIT_BUF_INIT;
+ git_str del_spec = GIT_STR_INIT;
int valid;
size_t i;
@@ -70,9 +68,9 @@ int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, siz
/* Create a refspec that deletes a branch in the remote */
if (strcmp(head->name, "refs/heads/master")) {
- cl_git_pass(git_buf_putc(&del_spec, ':'));
- cl_git_pass(git_buf_puts(&del_spec, head->name));
- cl_git_pass(git_vector_insert(out, git_buf_detach(&del_spec)));
+ cl_git_pass(git_str_putc(&del_spec, ':'));
+ cl_git_pass(git_str_puts(&del_spec, head->name));
+ cl_git_pass(git_vector_insert(out, git_str_detach(&del_spec)));
}
}
@@ -88,7 +86,7 @@ int record_ref_cb(git_remote_head *head, void *payload)
void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len)
{
size_t i, j = 0;
- git_buf msg = GIT_BUF_INIT;
+ git_str msg = GIT_STR_INIT;
const git_remote_head *actual;
char *oid_str;
bool master_present = false;
@@ -120,24 +118,24 @@ void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs
return;
failed:
- git_buf_puts(&msg, "Expected and actual refs differ:\nEXPECTED:\n");
+ git_str_puts(&msg, "Expected and actual refs differ:\nEXPECTED:\n");
for(i = 0; i < expected_refs_len; i++) {
oid_str = git_oid_tostr_s(expected_refs[i].oid);
- cl_git_pass(git_buf_printf(&msg, "%s = %s\n", expected_refs[i].name, oid_str));
+ cl_git_pass(git_str_printf(&msg, "%s = %s\n", expected_refs[i].name, oid_str));
}
- git_buf_puts(&msg, "\nACTUAL:\n");
+ git_str_puts(&msg, "\nACTUAL:\n");
for (i = 0; i < actual_refs_len; i++) {
actual = actual_refs[i];
if (master_present && !strcmp(actual->name, "refs/heads/master"))
continue;
oid_str = git_oid_tostr_s(&actual->oid);
- cl_git_pass(git_buf_printf(&msg, "%s = %s\n", actual->name, oid_str));
+ cl_git_pass(git_str_printf(&msg, "%s = %s\n", actual->name, oid_str));
}
- cl_fail(git_buf_cstr(&msg));
+ cl_fail(git_str_cstr(&msg));
- git_buf_dispose(&msg);
+ git_str_dispose(&msg);
}
diff --git a/tests/pack/filelimit.c b/tests/pack/filelimit.c
index 5e0b77e9b..2b7bf6e95 100644
--- a/tests/pack/filelimit.c
+++ b/tests/pack/filelimit.c
@@ -34,12 +34,12 @@ void test_pack_filelimit__initialize_unlimited(void)
void test_pack_filelimit__cleanup(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_MWINDOW_FILE_LIMIT, original_mwindow_file_limit));
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "repo.git"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "repo.git"));
cl_fixture_cleanup(path.ptr);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/*
@@ -54,7 +54,7 @@ void create_packfile_commit(
size_t commit_index,
size_t commit_count)
{
- git_buf file_contents = GIT_BUF_INIT;
+ git_str file_contents = GIT_STR_INIT;
git_treebuilder *treebuilder;
git_packbuilder *packbuilder;
git_signature *s;
@@ -67,7 +67,7 @@ void create_packfile_commit(
cl_git_pass(git_blob_create_from_buffer(&oid, repo, "", 0));
cl_git_pass(git_treebuilder_insert(NULL, treebuilder, "README.md", &oid, 0100644));
- cl_git_pass(git_buf_printf(&file_contents, "Commit %zd/%zd", commit_index, commit_count));
+ cl_git_pass(git_str_printf(&file_contents, "Commit %zd/%zd", commit_index, commit_count));
cl_git_pass(git_blob_create_from_buffer(&oid, repo, file_contents.ptr, file_contents.size));
cl_git_pass(git_treebuilder_insert(NULL, treebuilder, "file.txt", &oid, 0100644));
@@ -82,7 +82,7 @@ void create_packfile_commit(
cl_git_pass(git_oid_cpy(out_commit_id, &commit_id));
- git_buf_dispose(&file_contents);
+ git_str_dispose(&file_contents);
git_treebuilder_free(treebuilder);
git_packbuilder_free(packbuilder);
git_signature_free(s);
@@ -90,7 +90,7 @@ void create_packfile_commit(
void test_pack_filelimit__open_repo_with_multiple_packfiles(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
git_repository *repo;
git_revwalk *walk;
@@ -103,7 +103,7 @@ void test_pack_filelimit__open_repo_with_multiple_packfiles(void)
* Create a repository and populate it with 16 commits, each in its own
* packfile.
*/
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "repo.git"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "repo.git"));
cl_git_pass(git_repository_init(&repo, path.ptr, true));
for (i = 0; i < commit_count; ++i) {
create_packfile_commit(repo, &id, parent_id, i + 1, commit_count);
@@ -130,7 +130,7 @@ void test_pack_filelimit__open_repo_with_multiple_packfiles(void)
cl_assert_equal_i(expected_open_mwindow_files, open_windows);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_revwalk_free(walk);
git_repository_free(repo);
}
diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c
index 422c3def4..5958bc4ba 100644
--- a/tests/pack/indexer.c
+++ b/tests/pack/indexer.c
@@ -279,10 +279,10 @@ void test_pack_indexer__out_of_order_with_connectivity_checks(void)
git_indexer_free(idx);
}
-static int find_tmp_file_recurs(void *opaque, git_buf *path)
+static int find_tmp_file_recurs(void *opaque, git_str *path)
{
int error = 0;
- git_buf *first_tmp_file = opaque;
+ git_str *first_tmp_file = opaque;
struct stat st;
if ((error = p_lstat_posixly(path->ptr, &st)) < 0)
@@ -292,8 +292,8 @@ static int find_tmp_file_recurs(void *opaque, git_buf *path)
return git_path_direach(path, 0, find_tmp_file_recurs, opaque);
/* This is the template that's used in git_futils_mktmp. */
- if (strstr(git_buf_cstr(path), "_git2_") != NULL)
- return git_buf_sets(first_tmp_file, git_buf_cstr(path));
+ if (strstr(git_str_cstr(path), "_git2_") != NULL)
+ return git_str_sets(first_tmp_file, git_str_cstr(path));
return 0;
}
@@ -301,21 +301,21 @@ static int find_tmp_file_recurs(void *opaque, git_buf *path)
void test_pack_indexer__no_tmp_files(void)
{
git_indexer *idx = NULL;
- git_buf path = GIT_BUF_INIT;
- git_buf first_tmp_file = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
+ git_str first_tmp_file = GIT_STR_INIT;
/* Precondition: there are no temporary files. */
- cl_git_pass(git_buf_sets(&path, clar_sandbox_path()));
+ cl_git_pass(git_str_sets(&path, clar_sandbox_path()));
cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
- git_buf_dispose(&path);
- cl_assert(git_buf_len(&first_tmp_file) == 0);
+ git_str_dispose(&path);
+ cl_assert(git_str_len(&first_tmp_file) == 0);
cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL));
git_indexer_free(idx);
- cl_git_pass(git_buf_sets(&path, clar_sandbox_path()));
+ cl_git_pass(git_str_sets(&path, clar_sandbox_path()));
cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
- git_buf_dispose(&path);
- cl_assert(git_buf_len(&first_tmp_file) == 0);
- git_buf_dispose(&first_tmp_file);
+ git_str_dispose(&path);
+ cl_assert(git_str_len(&first_tmp_file) == 0);
+ git_str_dispose(&first_tmp_file);
}
diff --git a/tests/pack/midx.c b/tests/pack/midx.c
index d5b91d28b..9dd949363 100644
--- a/tests/pack/midx.c
+++ b/tests/pack/midx.c
@@ -12,12 +12,12 @@ void test_pack_midx__parse(void)
struct git_midx_file *idx;
struct git_midx_entry e;
git_oid id;
- git_buf midx_path = GIT_BUF_INIT;
+ git_str midx_path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_pass(git_midx_open(&idx, git_buf_cstr(&midx_path)));
- cl_assert_equal_i(git_midx_needs_refresh(idx, git_buf_cstr(&midx_path)), 0);
+ cl_git_pass(git_str_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
+ cl_git_pass(git_midx_open(&idx, git_str_cstr(&midx_path)));
+ cl_assert_equal_i(git_midx_needs_refresh(idx, git_str_cstr(&midx_path)), 0);
cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
cl_git_pass(git_midx_entry_find(&e, idx, &id, GIT_OID_HEXSZ));
@@ -28,7 +28,7 @@ void test_pack_midx__parse(void)
git_midx_free(idx);
git_repository_free(repo);
- git_buf_dispose(&midx_path);
+ git_str_dispose(&midx_path);
}
void test_pack_midx__lookup(void)
@@ -51,27 +51,28 @@ void test_pack_midx__writer(void)
{
git_repository *repo;
git_midx_writer *w = NULL;
- git_buf midx = GIT_BUF_INIT, expected_midx = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_buf midx = GIT_BUF_INIT;
+ git_str expected_midx = GIT_STR_INIT, path = GIT_STR_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/pack"));
- cl_git_pass(git_midx_writer_new(&w, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/pack"));
+ cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path)));
cl_git_pass(git_midx_writer_add(w, "pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx"));
cl_git_pass(git_midx_writer_add(w, "pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx"));
cl_git_pass(git_midx_writer_add(w, "pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"));
cl_git_pass(git_midx_writer_dump(&midx, w));
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_pass(git_futils_readbuffer(&expected_midx, git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/pack/multi-pack-index"));
+ cl_git_pass(git_futils_readbuffer(&expected_midx, git_str_cstr(&path)));
- cl_assert_equal_i(git_buf_len(&midx), git_buf_len(&expected_midx));
- cl_assert_equal_strn(git_buf_cstr(&midx), git_buf_cstr(&expected_midx), git_buf_len(&midx));
+ cl_assert_equal_i(midx.size, git_str_len(&expected_midx));
+ cl_assert_equal_strn(midx.ptr, git_str_cstr(&expected_midx), midx.size);
git_buf_dispose(&midx);
- git_buf_dispose(&expected_midx);
- git_buf_dispose(&path);
+ git_str_dispose(&expected_midx);
+ git_str_dispose(&path);
git_midx_writer_free(w);
git_repository_free(repo);
}
@@ -81,30 +82,30 @@ void test_pack_midx__odb_create(void)
git_repository *repo;
git_odb *odb;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- git_buf midx = GIT_BUF_INIT, expected_midx = GIT_BUF_INIT, midx_path = GIT_BUF_INIT;
+ git_str midx = GIT_STR_INIT, expected_midx = GIT_STR_INIT, midx_path = GIT_STR_INIT;
struct stat st;
opts.bare = true;
opts.local = GIT_CLONE_LOCAL;
cl_git_pass(git_clone(&repo, cl_fixture("testrepo/.gitted"), "./clone.git", &opts));
- cl_git_pass(git_buf_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_fail(p_stat(git_buf_cstr(&midx_path), &st));
+ cl_git_pass(git_str_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
+ cl_git_fail(p_stat(git_str_cstr(&midx_path), &st));
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_write_multi_pack_index(odb));
git_odb_free(odb);
- cl_git_pass(p_stat(git_buf_cstr(&midx_path), &st));
+ cl_git_pass(p_stat(git_str_cstr(&midx_path), &st));
cl_git_pass(git_futils_readbuffer(&expected_midx, cl_fixture("testrepo.git/objects/pack/multi-pack-index")));
- cl_git_pass(git_futils_readbuffer(&midx, git_buf_cstr(&midx_path)));
- cl_assert_equal_i(git_buf_len(&midx), git_buf_len(&expected_midx));
- cl_assert_equal_strn(git_buf_cstr(&midx), git_buf_cstr(&expected_midx), git_buf_len(&midx));
+ cl_git_pass(git_futils_readbuffer(&midx, git_str_cstr(&midx_path)));
+ cl_assert_equal_i(git_str_len(&midx), git_str_len(&expected_midx));
+ cl_assert_equal_strn(git_str_cstr(&midx), git_str_cstr(&expected_midx), git_str_len(&midx));
git_repository_free(repo);
- git_buf_dispose(&midx);
- git_buf_dispose(&midx_path);
- git_buf_dispose(&expected_midx);
+ git_str_dispose(&midx);
+ git_str_dispose(&midx_path);
+ git_str_dispose(&expected_midx);
cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES));
-} \ No newline at end of file
+}
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index 5d93ede06..b4c655c5e 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -96,7 +96,7 @@ static int feed_indexer(void *ptr, size_t len, void *payload)
void test_pack_packbuilder__create_pack(void)
{
git_indexer_progress stats;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
git_hash_ctx ctx;
git_oid hash;
char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
@@ -108,7 +108,7 @@ void test_pack_packbuilder__create_pack(void)
cl_git_pass(git_indexer_commit(_indexer, &stats));
git_oid_fmt(hex, git_indexer_hash(_indexer));
- git_buf_printf(&path, "pack-%s.pack", hex);
+ git_str_printf(&path, "pack-%s.pack", hex);
/*
* By default, packfiles are created with only one thread.
@@ -124,15 +124,15 @@ void test_pack_packbuilder__create_pack(void)
*
*/
- cl_git_pass(git_futils_readbuffer(&buf, git_buf_cstr(&path)));
+ cl_git_pass(git_futils_readbuffer(&buf, git_str_cstr(&path)));
cl_git_pass(git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1));
cl_git_pass(git_hash_update(&ctx, buf.ptr, buf.size));
cl_git_pass(git_hash_final(hash.id, &ctx));
git_hash_ctx_cleanup(&ctx);
- git_buf_dispose(&path);
- git_buf_dispose(&buf);
+ git_str_dispose(&path);
+ git_str_dispose(&buf);
git_oid_fmt(hex, &hash);
diff --git a/tests/patch/parse.c b/tests/patch/parse.c
index 3f89eb51a..a3c4c6730 100644
--- a/tests/patch/parse.c
+++ b/tests/patch/parse.c
@@ -27,13 +27,14 @@ static void ensure_patch_validity(git_patch *patch)
cl_assert_equal_i(0, delta->new_file.size);
}
-static void ensure_identical_patch_inout(const char *content) {
+static void ensure_identical_patch_inout(const char *content)
+{
git_buf buf = GIT_BUF_INIT;
git_patch *patch;
cl_git_pass(git_patch_from_buffer(&patch, content, strlen(content), NULL));
cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_strn(git_buf_cstr(&buf), content, strlen(content));
+ cl_assert_equal_strn(buf.ptr, content, strlen(content));
git_patch_free(patch);
git_buf_dispose(&buf);
@@ -131,12 +132,13 @@ void test_patch_parse__files_with_whitespaces_succeeds(void)
void test_patch_parse__lifetime_of_patch_does_not_depend_on_buffer(void)
{
- git_buf diff = GIT_BUF_INIT, rendered = GIT_BUF_INIT;
+ git_str diff = GIT_STR_INIT;
+ git_buf rendered = GIT_BUF_INIT;
git_patch *patch;
- cl_git_pass(git_buf_sets(&diff, PATCH_ORIGINAL_TO_CHANGE_MIDDLE));
+ cl_git_pass(git_str_sets(&diff, PATCH_ORIGINAL_TO_CHANGE_MIDDLE));
cl_git_pass(git_patch_from_buffer(&patch, diff.ptr, diff.size, NULL));
- git_buf_dispose(&diff);
+ git_str_dispose(&diff);
cl_git_pass(git_patch_to_buf(&rendered, patch));
cl_assert_equal_s(PATCH_ORIGINAL_TO_CHANGE_MIDDLE, rendered.ptr);
diff --git a/tests/path/core.c b/tests/path/core.c
index c875a862c..1d6066933 100644
--- a/tests/path/core.c
+++ b/tests/path/core.c
@@ -12,11 +12,11 @@ static void test_make_relative(
const char *parent,
int expected_status)
{
- git_buf buf = GIT_BUF_INIT;
- git_buf_puts(&buf, path);
+ git_str buf = GIT_STR_INIT;
+ git_str_puts(&buf, path);
cl_assert_equal_i(expected_status, git_path_make_relative(&buf, parent));
cl_assert_equal_s(expected_path, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_path_core__make_relative(void)
@@ -373,19 +373,19 @@ static void test_join_unrooted(
const char *path,
const char *base)
{
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
ssize_t root_at;
cl_git_pass(git_path_join_unrooted(&result, path, base, &root_at));
cl_assert_equal_s(expected_result, result.ptr);
cl_assert_equal_i(expected_rootlen, root_at);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
}
void test_path_core__join_unrooted(void)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
test_join_unrooted("foo", 0, "foo", NULL);
test_join_unrooted("foo/bar", 0, "foo/bar", NULL);
@@ -421,7 +421,7 @@ void test_path_core__join_unrooted(void)
/* Trailing slash in the base is ignored */
test_join_unrooted("c:/foo/bar/foobar", 6, "c:/foo/bar/foobar", "c:/foo/");
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
void test_path_core__join_unrooted_respects_funny_windows_roots(void)
diff --git a/tests/rebase/sign.c b/tests/rebase/sign.c
index 06c18937a..dc99407dd 100644
--- a/tests/rebase/sign.c
+++ b/tests/rebase/sign.c
@@ -263,8 +263,8 @@ int signing_cb_passthrough(
const char *commit_content,
void *payload)
{
- cl_assert_equal_b(false, git_buf_is_allocated(signature));
- cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
+ cl_assert_equal_i(0, signature->size);
+ cl_assert_equal_i(0, signature_field->size);
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
return GIT_PASSTHROUGH;
@@ -342,8 +342,8 @@ cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
=KbsY\n\
-----END PGP SIGNATURE-----";
- cl_assert_equal_b(false, git_buf_is_allocated(signature));
- cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
+ cl_assert_equal_i(0, signature->size);
+ cl_assert_equal_i(0, signature_field->size);
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
@@ -426,8 +426,10 @@ int signing_cb_magic_field(
const char *signature_content = "magic word: pretty please";
const char *signature_field_content = "magicsig";
- cl_assert_equal_b(false, git_buf_is_allocated(signature));
- cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
+ cl_assert_equal_p(NULL, signature->ptr);
+ cl_assert_equal_i(0, signature->size);
+ cl_assert_equal_p(NULL, signature_field->ptr);
+ cl_assert_equal_i(0, signature_field->size);
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
diff --git a/tests/rebase/submodule.c b/tests/rebase/submodule.c
index a28b3f4b2..0b3c2d5b5 100644
--- a/tests/rebase/submodule.c
+++ b/tests/rebase/submodule.c
@@ -65,7 +65,7 @@ void test_rebase_submodule__init_untracked(void)
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
- git_buf untracked_path = GIT_BUF_INIT;
+ git_str untracked_path = GIT_STR_INIT;
FILE *fp;
git_submodule *submodule;
@@ -78,11 +78,11 @@ void test_rebase_submodule__init_untracked(void)
cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule"));
cl_git_pass(git_submodule_update(submodule, 1, NULL));
- git_buf_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
- fp = fopen(git_buf_cstr(&untracked_path), "w");
+ git_str_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
+ fp = fopen(git_str_cstr(&untracked_path), "w");
fprintf(fp, "An untracked file in a submodule should not block a rebase\n");
fclose(fp);
- git_buf_dispose(&untracked_path);
+ git_str_dispose(&untracked_path);
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
diff --git a/tests/refs/basic.c b/tests/refs/basic.c
index 9e4c22964..32742f9cc 100644
--- a/tests/refs/basic.c
+++ b/tests/refs/basic.c
@@ -49,7 +49,7 @@ void test_refs_basic__longpaths(void)
const char *base;
size_t base_len, extra_len;
ssize_t remain_len, i;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
git_reference *one = NULL, *two = NULL;
git_oid id;
@@ -62,10 +62,10 @@ void test_refs_basic__longpaths(void)
remain_len = (ssize_t)MAX_PATH - (base_len + extra_len);
cl_assert(remain_len > 0);
- cl_git_pass(git_buf_puts(&refname, "refs/heads/"));
+ cl_git_pass(git_str_puts(&refname, "refs/heads/"));
for (i = 0; i < remain_len; i++) {
- cl_git_pass(git_buf_putc(&refname, 'a'));
+ cl_git_pass(git_str_putc(&refname, 'a'));
}
/*
@@ -75,11 +75,11 @@ void test_refs_basic__longpaths(void)
cl_git_pass(git_reference_create(&one, g_repo, refname.ptr, &id, 0, NULL));
/* Adding one more character gives us a path that is too long. */
- cl_git_pass(git_buf_putc(&refname, 'z'));
+ cl_git_pass(git_str_putc(&refname, 'z'));
cl_git_fail(git_reference_create(&two, g_repo, refname.ptr, &id, 0, NULL));
git_reference_free(one);
git_reference_free(two);
- git_buf_dispose(&refname);
+ git_str_dispose(&refname);
#endif
}
diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index 70ffad88d..7a49ad548 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -120,19 +120,19 @@ static void assert_branch_matches_name(
const char *expected, const char *lookup_as)
{
git_reference *ref;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
cl_git_pass(git_branch_lookup(&ref, repo, lookup_as, GIT_BRANCH_LOCAL));
- cl_git_pass(git_buf_sets(&b, "refs/heads/"));
- cl_git_pass(git_buf_puts(&b, expected));
+ cl_git_pass(git_str_sets(&b, "refs/heads/"));
+ cl_git_pass(git_str_puts(&b, expected));
cl_assert_equal_s(b.ptr, git_reference_name(ref));
cl_git_pass(
git_oid_cmp(git_reference_target(ref), git_commit_id(target)));
git_reference_free(ref);
- git_buf_dispose(&b);
+ git_str_dispose(&b);
}
void test_refs_branches_create__can_create_branch_with_unicode(void)
diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c
index 6093c7886..aad5c090f 100644
--- a/tests/refs/branches/delete.c
+++ b/tests/refs/branches/delete.c
@@ -153,8 +153,8 @@ void test_refs_branches_delete__removes_empty_folders(void)
git_oid oidzero = {{0}};
git_signature *sig;
- git_buf ref_folder = GIT_BUF_INIT;
- git_buf reflog_folder = GIT_BUF_INIT;
+ git_str ref_folder = GIT_STR_INIT;
+ git_str reflog_folder = GIT_STR_INIT;
/* Create a new branch with a nested name */
cl_git_pass(git_oid_fromstr(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
@@ -170,19 +170,19 @@ void test_refs_branches_delete__removes_empty_folders(void)
git_signature_free(sig);
git_reflog_free(log);
- cl_git_pass(git_buf_joinpath(&ref_folder, commondir, "refs/heads/some/deep"));
- cl_git_pass(git_buf_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep"));
+ cl_git_pass(git_str_joinpath(&ref_folder, commondir, "refs/heads/some/deep"));
+ cl_git_pass(git_str_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep"));
- cl_assert(git_path_exists(git_buf_cstr(&ref_folder)) == true);
- cl_assert(git_path_exists(git_buf_cstr(&reflog_folder)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == true);
cl_git_pass(git_branch_delete(branch));
- cl_assert(git_path_exists(git_buf_cstr(&ref_folder)) == false);
- cl_assert(git_path_exists(git_buf_cstr(&reflog_folder)) == false);
+ cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == false);
+ cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == false);
git_reference_free(branch);
- git_buf_dispose(&ref_folder);
- git_buf_dispose(&reflog_folder);
+ git_str_dispose(&ref_folder);
+ git_str_dispose(&reflog_folder);
}
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index 2cba9dfd3..46a5082d2 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -67,16 +67,14 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
{
git_reference *original_ref, *new_ref;
git_config *config;
- git_buf buf = GIT_BUF_INIT;
- char *original_remote, *original_merge;
+ git_buf original_remote = GIT_BUF_INIT,
+ original_merge = GIT_BUF_INIT;
const char *str;
cl_git_pass(git_repository_config_snapshot(&config, repo));
- cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.remote"));
- original_remote = git_buf_detach(&buf);
- cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.merge"));
- original_merge = git_buf_detach(&buf);
+ cl_git_pass(git_config_get_string_buf(&original_remote, config, "branch.master.remote"));
+ cl_git_pass(git_config_get_string_buf(&original_merge, config, "branch.master.merge"));
git_config_free(config);
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
@@ -88,9 +86,9 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, str);
+ cl_assert_equal_s(original_remote.ptr, str);
cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, str);
+ cl_assert_equal_s(original_merge.ptr, str);
git_config_free(config);
cl_assert_equal_i(GIT_EEXISTS,
@@ -100,9 +98,9 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, str);
+ cl_assert_equal_s(original_remote.ptr, str);
cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, str);
+ cl_assert_equal_s(original_merge.ptr, str);
git_config_free(config);
git_reference_free(original_ref);
@@ -115,11 +113,12 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, str);
+ cl_assert_equal_s(original_remote.ptr, str);
cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, str);
+ cl_assert_equal_s(original_merge.ptr, str);
- git__free(original_remote); git__free(original_merge);
+ git_buf_dispose(&original_remote);
+ git_buf_dispose(&original_merge);
git_reference_free(original_ref);
git_config_free(config);
}
diff --git a/tests/refs/branches/remote.c b/tests/refs/branches/remote.c
index 27a3b0c44..e2bd3485a 100644
--- a/tests/refs/branches/remote.c
+++ b/tests/refs/branches/remote.c
@@ -32,10 +32,9 @@ void test_refs_branches_remote__can_get_remote_for_branch(void)
void test_refs_branches_remote__no_matching_remote_returns_error(void)
{
const char *unknown = "refs/remotes/nonexistent/master";
- git_buf buf;
+ git_buf buf = GIT_BUF_INIT;
git_error_clear();
- memset(&buf, 0, sizeof(git_buf));
cl_git_fail_with(git_branch_remote_name(&buf, g_repo, unknown), GIT_ENOTFOUND);
cl_assert(git_error_last() != NULL);
}
@@ -43,10 +42,9 @@ void test_refs_branches_remote__no_matching_remote_returns_error(void)
void test_refs_branches_remote__local_remote_returns_error(void)
{
const char *local = "refs/heads/master";
- git_buf buf;
+ git_buf buf = GIT_BUF_INIT;
git_error_clear();
- memset(&buf, 0, sizeof(git_buf));
cl_git_fail_with(git_branch_remote_name(&buf, g_repo, local), GIT_ERROR);
cl_assert(git_error_last() != NULL);
}
@@ -54,7 +52,7 @@ void test_refs_branches_remote__local_remote_returns_error(void)
void test_refs_branches_remote__ambiguous_remote_returns_error(void)
{
git_remote *remote;
- git_buf buf;
+ git_buf buf = GIT_BUF_INIT;
/* Create the remote */
cl_git_pass(git_remote_create_with_fetchspec(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2", "refs/heads/*:refs/remotes/test/*"));
@@ -62,7 +60,6 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void)
git_remote_free(remote);
git_error_clear();
- memset(&buf, 0, sizeof(git_buf));
cl_git_fail_with(git_branch_remote_name(&buf, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS);
cl_assert(git_error_last() != NULL);
}
diff --git a/tests/refs/branches/upstreamname.c b/tests/refs/branches/upstreamname.c
index 2eb639738..5bae154d2 100644
--- a/tests/refs/branches/upstreamname.c
+++ b/tests/refs/branches/upstreamname.c
@@ -8,7 +8,6 @@ void test_refs_branches_upstreamname__initialize(void)
{
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- git_buf_init(&upstream_name, 0);
}
void test_refs_branches_upstreamname__cleanup(void)
@@ -24,7 +23,7 @@ void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference
cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/master"));
- cl_assert_equal_s("refs/remotes/test/master", git_buf_cstr(&upstream_name));
+ cl_assert_equal_s("refs/remotes/test/master", upstream_name.ptr);
}
void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_name_of_a_local_branch(void)
@@ -32,5 +31,5 @@ void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_
cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/track-local"));
- cl_assert_equal_s("refs/heads/master", git_buf_cstr(&upstream_name));
+ cl_assert_equal_s("refs/heads/master", upstream_name.ptr);
}
diff --git a/tests/refs/delete.c b/tests/refs/delete.c
index 3e99a7959..c76d126eb 100644
--- a/tests/refs/delete.c
+++ b/tests/refs/delete.c
@@ -29,10 +29,10 @@ void test_refs_delete__packed_loose(void)
{
/* deleting a ref which is both packed and loose should remove both tracks in the filesystem */
git_reference *looked_up_ref, *another_looked_up_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
/* Ensure the loose reference exists on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
cl_assert(git_path_exists(temp_path.ptr));
/* Lookup the reference */
@@ -52,7 +52,7 @@ void test_refs_delete__packed_loose(void)
cl_assert(!git_path_exists(temp_path.ptr));
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_delete__packed_only(void)
diff --git a/tests/refs/pack.c b/tests/refs/pack.c
index 676fb1759..125b1adb0 100644
--- a/tests/refs/pack.c
+++ b/tests/refs/pack.c
@@ -33,11 +33,11 @@ static void packall(void)
void test_refs_pack__empty(void)
{
/* create a packfile for an empty folder */
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
+ cl_git_pass(git_str_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
cl_git_pass(git_futils_mkdir_r(temp_path.ptr, GIT_REFS_DIR_MODE));
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
packall();
}
@@ -46,7 +46,7 @@ void test_refs_pack__loose(void)
{
/* create a packfile from all the loose refs in a repo */
git_reference *reference;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
/* Ensure a known loose ref can be looked up */
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
@@ -62,7 +62,7 @@ void test_refs_pack__loose(void)
packall();
/* Ensure the packed-refs file exists */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE));
cl_assert(git_path_exists(temp_path.ptr));
/* Ensure the known ref can still be looked up but is now packed */
@@ -71,11 +71,11 @@ void test_refs_pack__loose(void)
cl_assert_equal_s(reference->name, loose_tag_ref_name);
/* Ensure the known ref has been removed from the loose folder structure */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name));
cl_assert(!git_path_exists(temp_path.ptr));
git_reference_free(reference);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_pack__symbolic(void)
diff --git a/tests/refs/read.c b/tests/refs/read.c
index 1bbc38766..a622c770b 100644
--- a/tests/refs/read.c
+++ b/tests/refs/read.c
@@ -31,7 +31,7 @@ void test_refs_read__loose_tag(void)
/* lookup a loose tag reference */
git_reference *reference;
git_object *object;
- git_buf ref_name_from_tag_name = GIT_BUF_INIT;
+ git_str ref_name_from_tag_name = GIT_STR_INIT;
cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name));
cl_assert(git_reference_type(reference) & GIT_REFERENCE_DIRECT);
@@ -43,9 +43,9 @@ void test_refs_read__loose_tag(void)
cl_assert(git_object_type(object) == GIT_OBJECT_TAG);
/* Ensure the name of the tag matches the name of the reference */
- cl_git_pass(git_buf_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)));
+ cl_git_pass(git_str_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)));
cl_assert_equal_s(ref_name_from_tag_name.ptr, loose_tag_ref_name);
- git_buf_dispose(&ref_name_from_tag_name);
+ git_str_dispose(&ref_name_from_tag_name);
git_object_free(object);
diff --git a/tests/refs/ref_helpers.c b/tests/refs/ref_helpers.c
index 42b49216c..e55364c6e 100644
--- a/tests/refs/ref_helpers.c
+++ b/tests/refs/ref_helpers.c
@@ -2,24 +2,23 @@
#include "git2/refs.h"
#include "common.h"
#include "util.h"
-#include "buffer.h"
#include "path.h"
int reference_is_packed(git_reference *ref)
{
- git_buf ref_path = GIT_BUF_INIT;
+ git_str ref_path = GIT_STR_INIT;
int packed;
assert(ref);
- if (git_buf_joinpath(&ref_path,
+ if (git_str_joinpath(&ref_path,
git_repository_path(git_reference_owner(ref)),
git_reference_name(ref)) < 0)
return -1;
packed = !git_path_isfile(ref_path.ptr);
- git_buf_dispose(&ref_path);
+ git_str_dispose(&ref_path);
return packed;
}
diff --git a/tests/refs/reflog/messages.c b/tests/refs/reflog/messages.c
index 53b8c6f3e..ed183d2f2 100644
--- a/tests/refs/reflog/messages.c
+++ b/tests/refs/reflog/messages.c
@@ -338,7 +338,7 @@ void test_refs_reflog_messages__updating_a_direct_reference(void)
void test_refs_reflog_messages__creating_branches_default_messages(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
git_object *obj;
git_commit *target;
@@ -350,11 +350,11 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));
- cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
+ cl_git_pass(git_str_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
GIT_OID_HEX_ZERO,
git_oid_tostr_s(git_commit_id(target)),
- g_email, git_buf_cstr(&buf));
+ g_email, git_str_cstr(&buf));
cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));
@@ -367,7 +367,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
g_email, "branch: Created from e90810b8df3");
git_annotated_commit_free(annotated);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_commit_free(target);
git_reference_free(branch1);
git_reference_free(branch2);
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index 5cefc3227..5bb6138df 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -100,60 +100,60 @@ void test_refs_reflog_reflog__append_then_read(void)
void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
{
git_reference *master, *new_master;
- git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+ git_str master_log_path = GIT_STR_INIT, moved_log_path = GIT_STR_INIT;
- git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_puts(&moved_log_path, git_buf_cstr(&master_log_path));
- git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
- git_buf_joinpath(&moved_log_path, git_buf_cstr(&moved_log_path), "refs/moved");
+ git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_puts(&moved_log_path, git_str_cstr(&master_log_path));
+ git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master");
+ git_str_joinpath(&moved_log_path, git_str_cstr(&moved_log_path), "refs/moved");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&moved_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&moved_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
git_reference_free(master);
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&moved_log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&moved_log_path)));
git_reference_free(new_master);
- git_buf_dispose(&moved_log_path);
- git_buf_dispose(&master_log_path);
+ git_str_dispose(&moved_log_path);
+ git_str_dispose(&master_log_path);
}
void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void)
{
git_reference *master;
- git_buf master_log_path = GIT_BUF_INIT;
+ git_str master_log_path = GIT_STR_INIT;
- git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
+ git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_delete(master));
git_reference_free(master);
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
- git_buf_dispose(&master_log_path);
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path)));
+ git_str_dispose(&master_log_path);
}
void test_refs_reflog_reflog__removes_empty_reflog_dir(void)
{
git_reference *ref;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
git_oid id;
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&id, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
- git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");
+ git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
cl_git_pass(git_reference_delete(ref));
git_reference_free(ref);
@@ -163,13 +163,13 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void)
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
git_reference_free(ref);
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
}
void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
{
git_reference *ref;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
git_oid id;
/* Create a new branch pointing at the HEAD */
@@ -177,10 +177,10 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
git_reference_free(ref);
- git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
- git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");
+ git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
+ git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head");
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
/* delete the ref manually, leave the reflog */
cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head"));
@@ -190,7 +190,7 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
git_reference_free(ref);
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
}
static void assert_has_reflog(bool expected_result, const char *name)
@@ -209,17 +209,17 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
{
git_reflog *reflog;
const char *refname = "refs/heads/subtrees";
- git_buf subtrees_log_path = GIT_BUF_INIT;
+ git_str subtrees_log_path = GIT_STR_INIT;
- git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path)));
+ git_str_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&subtrees_log_path)));
cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert_equal_i(0, (int)git_reflog_entrycount(reflog));
git_reflog_free(reflog);
- git_buf_dispose(&subtrees_log_path);
+ git_str_dispose(&subtrees_log_path);
}
void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void)
@@ -231,7 +231,7 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void
const git_reflog_entry *entry;
git_reference *ref;
git_oid id;
- git_buf logpath = GIT_BUF_INIT, logcontents = GIT_BUF_INIT;
+ git_str logpath = GIT_STR_INIT, logcontents = GIT_STR_INIT;
char *star;
/* Create a new branch. */
@@ -242,18 +242,18 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void
* Corrupt the branch reflog by introducing a newline inside the reflog message.
* We do this by replacing '*' with '\n'
*/
- cl_git_pass(git_buf_join_n(&logpath, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname));
- cl_git_pass(git_futils_readbuffer(&logcontents, git_buf_cstr(&logpath)));
- cl_assert((star = strchr(git_buf_cstr(&logcontents), '*')) != NULL);
+ cl_git_pass(git_str_join_n(&logpath, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname));
+ cl_git_pass(git_futils_readbuffer(&logcontents, git_str_cstr(&logpath)));
+ cl_assert((star = strchr(git_str_cstr(&logcontents), '*')) != NULL);
*star = '\n';
- cl_git_rewritefile(git_buf_cstr(&logpath), git_buf_cstr(&logcontents));
+ cl_git_rewritefile(git_str_cstr(&logpath), git_str_cstr(&logcontents));
/*
* Confirm that the file was rewritten successfully
* and now contains a '\n' in the expected location
*/
- cl_git_pass(git_futils_readbuffer(&logcontents, git_buf_cstr(&logpath)));
- cl_assert(strstr(git_buf_cstr(&logcontents), "Reflog\nmessage") != NULL);
+ cl_git_pass(git_futils_readbuffer(&logcontents, git_str_cstr(&logpath)));
+ cl_assert(strstr(git_str_cstr(&logcontents), "Reflog\nmessage") != NULL);
cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert(entry = git_reflog_entry_byindex(reflog, 0));
@@ -261,14 +261,14 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void
git_reference_free(ref);
git_reflog_free(reflog);
- git_buf_dispose(&logpath);
- git_buf_dispose(&logcontents);
+ git_str_dispose(&logpath);
+ git_str_dispose(&logcontents);
}
void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
{
git_reference *master, *new_master;
- git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+ git_str master_log_path = GIT_STR_INIT, moved_log_path = GIT_STR_INIT;
git_reflog *reflog;
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
@@ -283,8 +283,8 @@ void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
git_reflog_free(reflog);
git_reference_free(new_master);
- git_buf_dispose(&moved_log_path);
- git_buf_dispose(&master_log_path);
+ git_str_dispose(&moved_log_path);
+ git_str_dispose(&master_log_path);
}
void test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC(void)
diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/refs/reflog/reflog_helpers.c
index aecb78b02..22619a4e3 100644
--- a/tests/refs/reflog/reflog_helpers.c
+++ b/tests/refs/reflog/reflog_helpers.c
@@ -3,7 +3,7 @@
#include "repository.h"
#include "reflog.h"
-static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
+static int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry)
{
char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];
@@ -12,7 +12,7 @@ static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry));
git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry));
- return git_buf_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
+ return git_str_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
}
size_t reflog_entrycount(git_repository *repo, const char *name)
@@ -34,7 +34,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
{
git_reflog *log;
const git_reflog_entry *entry;
- git_buf result = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
cl_git_pass(git_reflog_read(&log, repo, reflog));
entry = git_reflog_entry_byindex(log, idx);
@@ -47,7 +47,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git_object_free(obj);
} else {
@@ -56,7 +56,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git__free(oid);
}
@@ -67,7 +67,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git_object_free(obj);
} else {
@@ -76,26 +76,26 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
- git_buf_puts(&result, "\"\n");
+ git_str_puts(&result, "\"\n");
}
git__free(oid);
}
}
if (email && strcmp(email, git_reflog_entry_committer(entry)->email) != 0)
- git_buf_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
+ git_str_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
if (message) {
const char *entry_msg = git_reflog_entry_message(entry);
if (entry_msg == NULL) entry_msg = "";
if (entry_msg && strcmp(message, entry_msg) != 0)
- git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
+ git_str_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
}
- if (git_buf_len(&result) != 0)
- clar__fail(file, func, line, "Reflog entry mismatch", git_buf_cstr(&result), 1);
+ if (git_str_len(&result) != 0)
+ clar__fail(file, func, line, "Reflog entry mismatch", git_str_cstr(&result), 1);
- git_buf_dispose(&result);
+ git_str_dispose(&result);
git_reflog_free(log);
}
@@ -103,17 +103,17 @@ void reflog_print(git_repository *repo, const char *reflog_name)
{
git_reflog *reflog;
size_t idx;
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
git_reflog_read(&reflog, repo, reflog_name);
for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) {
const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx);
reflog_entry_tostr(&out, entry);
- git_buf_putc(&out, '\n');
+ git_str_putc(&out, '\n');
}
- fprintf(stderr, "%s", git_buf_cstr(&out));
- git_buf_dispose(&out);
+ fprintf(stderr, "%s", git_str_cstr(&out));
+ git_str_dispose(&out);
git_reflog_free(reflog);
}
diff --git a/tests/refs/rename.c b/tests/refs/rename.c
index b1b75cd64..fa732234a 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -36,11 +36,11 @@ void test_refs_rename__loose(void)
{
/* rename a loose reference */
git_reference *looked_up_ref, *new_ref, *another_looked_up_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu";
/* Ensure the ref doesn't exist on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name));
cl_assert(!git_path_exists(temp_path.ptr));
/* Retrieval of the reference to rename */
@@ -66,23 +66,23 @@ void test_refs_rename__loose(void)
cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref can be found in the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name));
cl_assert(git_path_exists(temp_path.ptr));
git_reference_free(new_ref);
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_rename__packed(void)
{
/* rename a packed reference (should make it loose) */
git_reference *looked_up_ref, *new_ref, *another_looked_up_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
/* Ensure the ref doesn't exist on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name));
cl_assert(!git_path_exists(temp_path.ptr));
/* The reference can however be looked-up... */
@@ -108,23 +108,23 @@ void test_refs_rename__packed(void)
cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref now happily lives in the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name));
cl_assert(git_path_exists(temp_path.ptr));
git_reference_free(new_ref);
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_rename__packed_doesnt_pack_others(void)
{
/* renaming a packed reference does not pack another reference which happens to be in both loose and pack state */
git_reference *looked_up_ref, *another_looked_up_ref, *renamed_ref;
- git_buf temp_path = GIT_BUF_INIT;
+ git_str temp_path = GIT_STR_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
/* Ensure the other reference exists on the file system */
- cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
cl_assert(git_path_exists(temp_path.ptr));
/* Lookup the other reference */
@@ -155,7 +155,7 @@ void test_refs_rename__packed_doesnt_pack_others(void)
git_reference_free(renamed_ref);
git_reference_free(another_looked_up_ref);
- git_buf_dispose(&temp_path);
+ git_str_dispose(&temp_path);
}
void test_refs_rename__name_collision(void)
diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c
index bc6e0a4c4..9c960702a 100644
--- a/tests/refs/revparse.c
+++ b/tests/refs/revparse.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/revparse.h"
-#include "buffer.h"
#include "refs.h"
#include "path.h"
@@ -292,7 +291,7 @@ void test_refs_revparse__upstream(void)
void test_refs_revparse__ordinal(void)
{
assert_invalid_single_spec("master@{-2}");
-
+
/* TODO: make the test below actually fail
* cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
*/
@@ -326,19 +325,19 @@ void test_refs_revparse__previous_head(void)
static void create_fake_stash_reference_and_reflog(git_repository *repo)
{
git_reference *master, *new_master;
- git_buf log_path = GIT_BUF_INIT;
+ git_str log_path = GIT_STR_INIT;
- git_buf_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
+ git_str_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
- cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&log_path)));
cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL));
git_reference_free(master);
- cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
+ cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path)));
- git_buf_dispose(&log_path);
+ git_str_dispose(&log_path);
git_reference_free(new_master);
}
@@ -555,7 +554,7 @@ void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void)
/*
* $ echo "aabqhq" | git hash-object -t blob --stdin
* dea509d0b3cb8ee0650f6ca210bc83f4678851ba
- *
+ *
* $ echo "aaazvc" | git hash-object -t blob --stdin
* dea509d097ce692e167dfc6a48a7a280cc5e877e
*/
@@ -569,11 +568,11 @@ void test_refs_revparse__a_not_precise_enough_objectid_returns_EAMBIGUOUS(void)
cl_git_mkfile("testrepo/one.txt", "aabqhq\n");
cl_git_mkfile("testrepo/two.txt", "aaazvc\n");
-
+
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, "one.txt"));
cl_git_pass(git_index_add_bypath(index, "two.txt"));
-
+
cl_git_fail_with(git_revparse_single(&obj, repo, "dea509d0"), GIT_EAMBIGUOUS);
cl_git_pass(git_revparse_single(&obj, repo, "dea509d09"));
@@ -588,7 +587,7 @@ void test_refs_revparse__issue_994(void)
git_repository *repo;
git_reference *head, *with_at;
git_object *target;
-
+
repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(GIT_ENOTFOUND,
diff --git a/tests/remote/fetch.c b/tests/remote/fetch.c
index 7e825ca16..209c42993 100644
--- a/tests/remote/fetch.c
+++ b/tests/remote/fetch.c
@@ -15,24 +15,24 @@ static char *NON_FORCE_FETCHSPEC = "refs/heads/main:refs/remotes/repo1/main";
void test_remote_fetch__initialize(void) {
git_config *c;
- git_buf repo1_path_buf = GIT_BUF_INIT;
- git_buf repo2_path_buf = GIT_BUF_INIT;
+ git_str repo1_path_buf = GIT_STR_INIT;
+ git_str repo2_path_buf = GIT_STR_INIT;
const char *sandbox = clar_sandbox_path();
- cl_git_pass(git_buf_joinpath(&repo1_path_buf, sandbox, "fetchtest_repo1"));
- repo1_path = git_buf_detach(&repo1_path_buf);
+ cl_git_pass(git_str_joinpath(&repo1_path_buf, sandbox, "fetchtest_repo1"));
+ repo1_path = git_str_detach(&repo1_path_buf);
cl_git_pass(git_repository_init(&repo1, repo1_path, true));
- cl_git_pass(git_buf_joinpath(&repo2_path_buf, sandbox, "fetchtest_repo2"));
- repo2_path = git_buf_detach(&repo2_path_buf);
+ cl_git_pass(git_str_joinpath(&repo2_path_buf, sandbox, "fetchtest_repo2"));
+ repo2_path = git_str_detach(&repo2_path_buf);
cl_git_pass(git_repository_init(&repo2, repo2_path, true));
cl_git_pass(git_repository_config(&c, repo1));
cl_git_pass(git_config_set_string(c, "user.email", "some@email"));
cl_git_pass(git_config_set_string(c, "user.name", "some@name"));
git_config_free(c);
- git_buf_dispose(&repo1_path_buf);
- git_buf_dispose(&repo2_path_buf);
+ git_str_dispose(&repo1_path_buf);
+ git_str_dispose(&repo2_path_buf);
}
void test_remote_fetch__cleanup(void) {
diff --git a/tests/repo/config.c b/tests/repo/config.c
index 6ca31f550..0b9daac98 100644
--- a/tests/repo/config.c
+++ b/tests/repo/config.c
@@ -3,7 +3,7 @@
#include "futils.h"
#include <ctype.h>
-static git_buf path = GIT_BUF_INIT;
+static git_str path = GIT_STR_INIT;
void test_repo_config__initialize(void)
{
@@ -11,7 +11,7 @@ void test_repo_config__initialize(void)
cl_git_pass(cl_rename(
"empty_standard_repo/.gitted", "empty_standard_repo/.git"));
- git_buf_clear(&path);
+ git_str_clear(&path);
cl_must_pass(p_mkdir("alternate", 0777));
cl_git_pass(git_path_prettify(&path, "alternate", NULL));
@@ -21,7 +21,7 @@ void test_repo_config__cleanup(void)
{
cl_sandbox_set_search_path_defaults();
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_pass(
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES));
@@ -60,7 +60,7 @@ void test_repo_config__can_open_missing_global_with_separators(void)
git_repository *repo;
git_config *config, *global;
- cl_git_pass(git_buf_printf(
+ cl_git_pass(git_str_printf(
&path, "%c%s", GIT_PATH_LIST_SEPARATOR, "dummy"));
cl_git_pass(git_libgit2_opts(
@@ -70,7 +70,7 @@ void test_repo_config__can_open_missing_global_with_separators(void)
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
@@ -115,7 +115,7 @@ void test_repo_config__read_with_no_configs_at_all(void)
cl_sandbox_set_search_path_defaults();
cl_must_pass(p_mkdir("alternate/1", 0777));
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "1"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "1"));
cl_git_rewritefile("alternate/1/gitconfig", "[core]\n\tabbrev = 10\n");
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
diff --git a/tests/repo/discover.c b/tests/repo/discover.c
index c026eefc3..2a24f1b29 100644
--- a/tests/repo/discover.c
+++ b/tests/repo/discover.c
@@ -28,16 +28,17 @@ static void ensure_repository_discover(const char *start_path,
const char *ceiling_dirs,
const char *expected_path)
{
- git_buf found_path = GIT_BUF_INIT, resolved = GIT_BUF_INIT;
+ git_buf found_path = GIT_BUF_INIT;
+ git_str resolved = GIT_STR_INIT;
- git_buf_attach(&resolved, p_realpath(expected_path, NULL), 0);
+ git_str_attach(&resolved, p_realpath(expected_path, NULL), 0);
cl_assert(resolved.size > 0);
cl_git_pass(git_path_to_dir(&resolved));
cl_git_pass(git_repository_discover(&found_path, start_path, 1, ceiling_dirs));
cl_assert_equal_s(found_path.ptr, resolved.ptr);
- git_buf_dispose(&resolved);
+ git_str_dispose(&resolved);
git_buf_dispose(&found_path);
}
@@ -59,24 +60,24 @@ static void write_file(const char *path, const char *content)
}
/*no check is performed on ceiling_dirs length, so be sure it's long enough */
-static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
+static void append_ceiling_dir(git_str *ceiling_dirs, const char *path)
{
- git_buf pretty_path = GIT_BUF_INIT;
+ git_str pretty_path = GIT_STR_INIT;
char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' };
cl_git_pass(git_path_prettify_dir(&pretty_path, path, NULL));
if (ceiling_dirs->size > 0)
- git_buf_puts(ceiling_dirs, ceiling_separator);
+ git_str_puts(ceiling_dirs, ceiling_separator);
- git_buf_puts(ceiling_dirs, pretty_path.ptr);
+ git_str_puts(ceiling_dirs, pretty_path.ptr);
- git_buf_dispose(&pretty_path);
- cl_assert(git_buf_oom(ceiling_dirs) == 0);
+ git_str_dispose(&pretty_path);
+ cl_assert(git_str_oom(ceiling_dirs) == 0);
}
static git_buf discovered;
-static git_buf ceiling_dirs;
+static git_str ceiling_dirs;
void test_repo_discover__initialize(void)
{
@@ -84,8 +85,7 @@ void test_repo_discover__initialize(void)
const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, mode);
- git_buf_init(&discovered, 0);
- git_buf_init(&ceiling_dirs, 0);
+ git_str_init(&ceiling_dirs, 0);
append_ceiling_dir(&ceiling_dirs, TEMP_REPO_FOLDER);
cl_git_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1));
@@ -115,7 +115,7 @@ void test_repo_discover__initialize(void)
void test_repo_discover__cleanup(void)
{
git_buf_dispose(&discovered);
- git_buf_dispose(&ceiling_dirs);
+ git_str_dispose(&ceiling_dirs);
cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/repo/env.c b/tests/repo/env.c
index 43defc168..4bd45d1a6 100644
--- a/tests/repo/env.c
+++ b/tests/repo/env.c
@@ -38,14 +38,14 @@ static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char
{
int ret;
va_list args;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
va_start(args, fmt);
- cl_git_pass(git_buf_vprintf(&buf, fmt, args));
+ cl_git_pass(git_str_vprintf(&buf, fmt, args));
va_end(args);
- ret = cl_setenv(name, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ ret = cl_setenv(name, git_str_cstr(&buf));
+ git_str_dispose(&buf);
return ret;
}
@@ -80,12 +80,12 @@ static void env_cd_(
void (*passfail_)(const char *, const char *, const char *, int),
const char *file, const char *func, int line)
{
- git_buf cwd_buf = GIT_BUF_INIT;
+ git_str cwd_buf = GIT_STR_INIT;
cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL));
cl_must_pass(p_chdir(path));
passfail_(NULL, file, func, line);
- cl_must_pass(p_chdir(git_buf_cstr(&cwd_buf)));
- git_buf_dispose(&cwd_buf);
+ cl_must_pass(p_chdir(git_str_cstr(&cwd_buf)));
+ git_str_dispose(&cwd_buf);
}
#define env_cd_pass(path) env_cd_((path), env_pass_, __FILE__, __func__, __LINE__)
#define env_cd_fail(path) env_cd_((path), env_fail_, __FILE__, __func__, __LINE__)
@@ -128,7 +128,7 @@ static void env_check_objects_(bool a, bool t, bool p, const char *file, const c
void test_repo_env__open(void)
{
git_repository *repo = NULL;
- git_buf repo_dir_buf = GIT_BUF_INIT;
+ git_str repo_dir_buf = GIT_STR_INIT;
const char *repo_dir = NULL;
git_index *index = NULL;
const char *t_obj = "testrepo.git/objects";
@@ -142,7 +142,7 @@ void test_repo_env__open(void)
cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL));
- repo_dir = git_buf_cstr(&repo_dir_buf);
+ repo_dir = git_str_cstr(&repo_dir_buf);
/* GIT_DIR that doesn't exist */
cl_setenv("GIT_DIR", "does-not-exist");
@@ -271,7 +271,7 @@ void test_repo_env__open(void)
cl_fixture_cleanup("testrepo.git");
cl_fixture_cleanup("attr");
- git_buf_dispose(&repo_dir_buf);
+ git_str_dispose(&repo_dir_buf);
clear_git_env();
}
diff --git a/tests/repo/hashfile.c b/tests/repo/hashfile.c
index bffb51bb5..e23bb77f9 100644
--- a/tests/repo/hashfile.c
+++ b/tests/repo/hashfile.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
static git_repository *_repo;
@@ -18,14 +17,14 @@ void test_repo_hashfile__cleanup(void)
void test_repo_hashfile__simple(void)
{
git_oid a, b;
- git_buf full = GIT_BUF_INIT;
+ git_str full = GIT_STR_INIT;
/* hash with repo relative path */
cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
- cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file"));
+ cl_git_pass(git_str_joinpath(&full, git_repository_workdir(_repo), "current_file"));
/* hash with full path */
cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB));
@@ -36,20 +35,20 @@ void test_repo_hashfile__simple(void)
cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY));
cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_OFS_DELTA, NULL));
- git_buf_dispose(&full);
+ git_str_dispose(&full);
}
void test_repo_hashfile__filtered_in_workdir(void)
{
- git_buf root = GIT_BUF_INIT, txt = GIT_BUF_INIT, bin = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT, txt = GIT_STR_INIT, bin = GIT_STR_INIT;
char cwd[GIT_PATH_MAX];
git_oid a, b;
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
cl_must_pass(p_mkdir("absolute", 0777));
- cl_git_pass(git_buf_joinpath(&root, cwd, "status"));
- cl_git_pass(git_buf_joinpath(&txt, root.ptr, "testfile.txt"));
- cl_git_pass(git_buf_joinpath(&bin, root.ptr, "testfile.bin"));
+ cl_git_pass(git_str_joinpath(&root, cwd, "status"));
+ cl_git_pass(git_str_joinpath(&txt, root.ptr, "testfile.txt"));
+ cl_git_pass(git_str_joinpath(&bin, root.ptr, "testfile.bin"));
cl_repo_set_bool(_repo, "core.autocrlf", true);
@@ -120,22 +119,22 @@ void test_repo_hashfile__filtered_in_workdir(void)
cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_ANY, NULL));
- git_buf_dispose(&txt);
- git_buf_dispose(&bin);
- git_buf_dispose(&root);
+ git_str_dispose(&txt);
+ git_str_dispose(&bin);
+ git_str_dispose(&root);
}
void test_repo_hashfile__filtered_outside_workdir(void)
{
- git_buf root = GIT_BUF_INIT, txt = GIT_BUF_INIT, bin = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT, txt = GIT_STR_INIT, bin = GIT_STR_INIT;
char cwd[GIT_PATH_MAX];
git_oid a, b;
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
cl_must_pass(p_mkdir("absolute", 0777));
- cl_git_pass(git_buf_joinpath(&root, cwd, "absolute"));
- cl_git_pass(git_buf_joinpath(&txt, root.ptr, "testfile.txt"));
- cl_git_pass(git_buf_joinpath(&bin, root.ptr, "testfile.bin"));
+ cl_git_pass(git_str_joinpath(&root, cwd, "absolute"));
+ cl_git_pass(git_str_joinpath(&txt, root.ptr, "testfile.txt"));
+ cl_git_pass(git_str_joinpath(&bin, root.ptr, "testfile.bin"));
cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
@@ -166,7 +165,7 @@ void test_repo_hashfile__filtered_outside_workdir(void)
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
- git_buf_dispose(&txt);
- git_buf_dispose(&bin);
- git_buf_dispose(&root);
+ git_str_dispose(&txt);
+ git_str_dispose(&bin);
+ git_str_dispose(&root);
}
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 1aa326f7f..b41608cca 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -12,7 +12,7 @@ enum repo_mode {
};
static git_repository *g_repo = NULL;
-static git_buf g_global_path = GIT_BUF_INIT;
+static git_str g_global_path = GIT_STR_INIT;
void test_repo_init__initialize(void)
{
@@ -26,7 +26,7 @@ void test_repo_init__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
g_global_path.ptr);
- git_buf_dispose(&g_global_path);
+ git_str_dispose(&g_global_path);
cl_fixture_cleanup("tmp_global_path");
}
@@ -100,16 +100,16 @@ void test_repo_init__bare_repo_noslash(void)
void test_repo_init__bare_repo_escaping_current_workdir(void)
{
- git_buf path_repository = GIT_BUF_INIT;
- git_buf path_current_workdir = GIT_BUF_INIT;
+ git_str path_repository = GIT_STR_INIT;
+ git_str path_current_workdir = GIT_STR_INIT;
cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
- cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c"));
- cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE));
+ cl_git_pass(git_str_joinpath(&path_repository, git_str_cstr(&path_current_workdir), "a/b/c"));
+ cl_git_pass(git_futils_mkdir_r(git_str_cstr(&path_repository), GIT_DIR_MODE));
/* Change the current working directory */
- cl_git_pass(chdir(git_buf_cstr(&path_repository)));
+ cl_git_pass(chdir(git_str_cstr(&path_repository)));
/* Initialize a bare repo with a relative path escaping out of the current working directory */
cl_git_pass(git_repository_init(&g_repo, "../d/e.git", 1));
@@ -121,10 +121,10 @@ void test_repo_init__bare_repo_escaping_current_workdir(void)
/* Open a bare repo with a relative path escaping out of the current working directory */
cl_git_pass(git_repository_open(&g_repo, "../d/e.git"));
- cl_git_pass(chdir(git_buf_cstr(&path_current_workdir)));
+ cl_git_pass(chdir(git_str_cstr(&path_current_workdir)));
- git_buf_dispose(&path_current_workdir);
- git_buf_dispose(&path_repository);
+ git_str_dispose(&path_current_workdir);
+ git_str_dispose(&path_repository);
cleanup_repository("a");
}
@@ -168,26 +168,26 @@ void test_repo_init__reinit_too_recent_bare_repo(void)
void test_repo_init__additional_templates(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(&cleanup_repository, "tester");
ensure_repository_init("tester", 0, "tester/.git/", "tester/");
cl_git_pass(
- git_buf_joinpath(&path, git_repository_path(g_repo), "description"));
- cl_assert(git_path_isfile(git_buf_cstr(&path)));
+ git_str_joinpath(&path, git_repository_path(g_repo), "description"));
+ cl_assert(git_path_isfile(git_str_cstr(&path)));
cl_git_pass(
- git_buf_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
- cl_assert(git_path_isfile(git_buf_cstr(&path)));
+ git_str_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
+ cl_assert(git_path_isfile(git_str_cstr(&path)));
cl_git_pass(
- git_buf_joinpath(&path, git_repository_path(g_repo), "hooks"));
- cl_assert(git_path_isdir(git_buf_cstr(&path)));
+ git_str_joinpath(&path, git_repository_path(g_repo), "hooks"));
+ cl_assert(git_path_isdir(git_str_cstr(&path)));
/* won't confirm specific contents of hooks dir since it may vary */
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void assert_config_entry_on_init_bytype(
@@ -447,7 +447,7 @@ void test_repo_init__extended_1(void)
void test_repo_init__relative_gitdir(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf dot_git_content = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
opts.workdir_path = "../c_wd";
opts.flags =
@@ -472,18 +472,18 @@ void test_repo_init__relative_gitdir(void)
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
cleanup_repository("root");
}
void test_repo_init__relative_gitdir_2(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf dot_git_content = GIT_BUF_INIT;
- git_buf full_path = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
+ git_str full_path = GIT_STR_INIT;
cl_git_pass(git_path_prettify(&full_path, ".", NULL));
- cl_git_pass(git_buf_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
+ cl_git_pass(git_str_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
opts.workdir_path = full_path.ptr;
opts.flags =
@@ -493,7 +493,7 @@ void test_repo_init__relative_gitdir_2(void)
/* make the directory first, then it should succeed */
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
- git_buf_dispose(&full_path);
+ git_str_dispose(&full_path);
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
@@ -509,7 +509,7 @@ void test_repo_init__relative_gitdir_2(void)
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
cleanup_repository("root");
}
@@ -598,7 +598,7 @@ void test_repo_init__at_filesystem_root(void)
{
git_repository *repo;
const char *sandbox = clar_sandbox_path();
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
int root_len;
if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
@@ -607,8 +607,8 @@ void test_repo_init__at_filesystem_root(void)
root_len = git_path_root(sandbox);
cl_assert(root_len >= 0);
- git_buf_put(&root, sandbox, root_len+1);
- git_buf_joinpath(&root, root.ptr, "libgit2_test_dir");
+ git_str_put(&root, sandbox, root_len+1);
+ git_str_joinpath(&root, root.ptr, "libgit2_test_dir");
cl_assert(!git_path_exists(root.ptr));
@@ -616,7 +616,7 @@ void test_repo_init__at_filesystem_root(void)
cl_assert(git_path_isdir(root.ptr));
cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
- git_buf_dispose(&root);
+ git_str_dispose(&root);
git_repository_free(repo);
}
@@ -710,29 +710,29 @@ void test_repo_init__longpath(void)
#ifdef GIT_WIN32
size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_HEXSZ;
size_t max, i;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *one = NULL, *two = NULL;
/*
* Files within repositories need to fit within MAX_PATH;
* that means a repo path must be at most (MAX_PATH - 18).
*/
- cl_git_pass(git_buf_puts(&path, clar_sandbox_path()));
- cl_git_pass(git_buf_putc(&path, '/'));
+ cl_git_pass(git_str_puts(&path, clar_sandbox_path()));
+ cl_git_pass(git_str_putc(&path, '/'));
max = ((MAX_PATH) - path.size) - padding;
for (i = 0; i < max - 1; i++)
- cl_git_pass(git_buf_putc(&path, 'a'));
+ cl_git_pass(git_str_putc(&path, 'a'));
cl_git_pass(git_repository_init(&one, path.ptr, 1));
/* Paths longer than this are rejected */
- cl_git_pass(git_buf_putc(&path, 'z'));
+ cl_git_pass(git_str_putc(&path, 'z'));
cl_git_fail(git_repository_init(&two, path.ptr, 1));
git_repository_free(one);
git_repository_free(two);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
diff --git a/tests/repo/message.c b/tests/repo/message.c
index 14577c8f0..6241f48f9 100644
--- a/tests/repo/message.c
+++ b/tests/repo/message.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "refs.h"
#include "posix.h"
@@ -23,17 +22,18 @@ void test_repo_message__none(void)
void test_repo_message__message(void)
{
- git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
+ git_buf actual = GIT_BUF_INIT;
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&path), expected);
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
+ cl_git_mkfile(git_str_cstr(&path), expected);
cl_git_pass(git_repository_message(&actual, _repo));
- cl_assert_equal_s(expected, git_buf_cstr(&actual));
+ cl_assert_equal_s(expected, actual.ptr);
git_buf_dispose(&actual);
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/repo/open.c b/tests/repo/open.c
index bd60c12c2..6558805c8 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -105,12 +105,12 @@ void test_repo_open__check_if_repository(void)
static void make_gitlink_dir(const char *dir, const char *linktext)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_futils_mkdir(dir, 0777, GIT_MKDIR_VERIFY_DIR));
- cl_git_pass(git_buf_joinpath(&path, dir, ".git"));
+ cl_git_pass(git_str_joinpath(&path, dir, ".git"));
cl_git_rewritefile(path.ptr, linktext);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_repo_open__gitlinked(void)
@@ -136,7 +136,7 @@ void test_repo_open__gitlinked(void)
void test_repo_open__with_symlinked_config(void)
{
#ifndef GIT_WIN32
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_config *cfg;
int32_t value;
@@ -157,9 +157,9 @@ void test_repo_open__with_symlinked_config(void)
git_config_free(cfg);
git_repository_free(repo);
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
cl_sandbox_set_search_path_defaults();
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
@@ -173,7 +173,7 @@ void test_repo_open__from_git_new_workdir(void)
*/
git_repository *repo2;
- git_buf link_tgt = GIT_BUF_INIT, link = GIT_BUF_INIT, body = GIT_BUF_INIT;
+ git_str link_tgt = GIT_STR_INIT, link = GIT_STR_INIT, body = GIT_STR_INIT;
const char **scan;
int link_fd;
static const char *links[] = {
@@ -190,19 +190,19 @@ void test_repo_open__from_git_new_workdir(void)
cl_git_pass(p_mkdir("alternate/.git", 0777));
for (scan = links; *scan != NULL; scan++) {
- git_buf_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
+ git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
if (git_path_exists(link_tgt.ptr)) {
- git_buf_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan);
- git_buf_joinpath(&link, "alternate/.git", *scan);
+ git_str_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan);
+ git_str_joinpath(&link, "alternate/.git", *scan);
if (strchr(*scan, '/'))
git_futils_mkpath2file(link.ptr, 0777);
cl_assert_(symlink(link_tgt.ptr, link.ptr) == 0, strerror(errno));
}
}
for (scan = copies; *scan != NULL; scan++) {
- git_buf_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
+ git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
if (git_path_exists(link_tgt.ptr)) {
- git_buf_joinpath(&link, "alternate/.git", *scan);
+ git_str_joinpath(&link, "alternate/.git", *scan);
cl_git_pass(git_futils_readbuffer(&body, link_tgt.ptr));
cl_assert((link_fd = git_futils_creat_withpath(link.ptr, 0777, 0666)) >= 0);
@@ -211,9 +211,9 @@ void test_repo_open__from_git_new_workdir(void)
}
}
- git_buf_dispose(&link_tgt);
- git_buf_dispose(&link);
- git_buf_dispose(&body);
+ git_str_dispose(&link_tgt);
+ git_str_dispose(&link);
+ git_str_dispose(&body);
cl_git_pass(git_repository_open(&repo2, "alternate"));
@@ -233,10 +233,10 @@ void test_repo_open__from_git_new_workdir(void)
void test_repo_open__failures(void)
{
git_repository *base, *repo;
- git_buf ceiling = GIT_BUF_INIT;
+ git_str ceiling = GIT_STR_INIT;
base = cl_git_sandbox_init("attr");
- cl_git_pass(git_buf_sets(&ceiling, git_repository_workdir(base)));
+ cl_git_pass(git_str_sets(&ceiling, git_repository_workdir(base)));
/* fail with no searching */
cl_git_fail(git_repository_open(&repo, "attr/sub"));
@@ -245,7 +245,7 @@ void test_repo_open__failures(void)
/* fail with ceiling too low */
cl_git_fail(git_repository_open_ext(&repo, "attr/sub", 0, ceiling.ptr));
- cl_git_pass(git_buf_joinpath(&ceiling, ceiling.ptr, "sub"));
+ cl_git_pass(git_str_joinpath(&ceiling, ceiling.ptr, "sub"));
cl_git_fail(git_repository_open_ext(&repo, "attr/sub/sub", 0, ceiling.ptr));
/* fail with no repo */
@@ -260,7 +260,7 @@ void test_repo_open__failures(void)
GIT_REPOSITORY_OPEN_NO_SEARCH | GIT_REPOSITORY_OPEN_NO_DOTGIT,
NULL));
- git_buf_dispose(&ceiling);
+ git_str_dispose(&ceiling);
}
void test_repo_open__bad_gitlinks(void)
@@ -291,7 +291,7 @@ void test_repo_open__bad_gitlinks(void)
}
#ifdef GIT_WIN32
-static void unposix_path(git_buf *path)
+static void unposix_path(git_str *path)
{
char *src, *tgt;
@@ -318,44 +318,44 @@ void test_repo_open__win32_path(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("empty_standard_repo"), *repo2;
- git_buf winpath = GIT_BUF_INIT;
+ git_str winpath = GIT_STR_INIT;
static const char *repo_path = "empty_standard_repo/.git/";
static const char *repo_wd = "empty_standard_repo/";
cl_assert(git__suffixcmp(git_repository_path(repo), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo), repo_wd) == 0);
- cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo)));
+ cl_git_pass(git_str_sets(&winpath, git_repository_path(repo)));
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo)));
- git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
+ cl_git_pass(git_str_sets(&winpath, git_repository_path(repo)));
+ git_str_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo)));
+ cl_git_pass(git_str_sets(&winpath, git_repository_workdir(repo)));
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo)));
- git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
+ cl_git_pass(git_str_sets(&winpath, git_repository_workdir(repo)));
+ git_str_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- git_buf_dispose(&winpath);
+ git_str_dispose(&winpath);
#endif
}
@@ -367,7 +367,7 @@ void test_repo_open__opening_a_non_existing_repository_returns_ENOTFOUND(void)
void test_repo_open__no_config(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_config *config;
@@ -389,7 +389,7 @@ void test_repo_open__no_config(void)
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
diff --git a/tests/repo/repo_helpers.c b/tests/repo/repo_helpers.c
index b22f3f6ba..1efde70a5 100644
--- a/tests/repo/repo_helpers.c
+++ b/tests/repo/repo_helpers.c
@@ -13,25 +13,25 @@ void make_head_unborn(git_repository* repo, const char *target)
void delete_head(git_repository* repo)
{
- git_buf head_path = GIT_BUF_INIT;
+ git_str head_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
- cl_git_pass(p_unlink(git_buf_cstr(&head_path)));
+ cl_git_pass(git_str_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
+ cl_git_pass(p_unlink(git_str_cstr(&head_path)));
- git_buf_dispose(&head_path);
+ git_str_dispose(&head_path);
}
void create_tmp_global_config(const char *dirname, const char *key, const char *val)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config *config;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
GIT_CONFIG_LEVEL_GLOBAL, dirname));
cl_must_pass(p_mkdir(dirname, 0777));
- cl_git_pass(git_buf_joinpath(&path, dirname, ".gitconfig"));
+ cl_git_pass(git_str_joinpath(&path, dirname, ".gitconfig"));
cl_git_pass(git_config_open_ondisk(&config, path.ptr));
cl_git_pass(git_config_set_string(config, key, val));
git_config_free(config);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/repo/reservedname.c b/tests/repo/reservedname.c
index 8e024bcbb..245d8625a 100644
--- a/tests/repo/reservedname.c
+++ b/tests/repo/reservedname.c
@@ -10,7 +10,7 @@ void test_repo_reservedname__cleanup(void)
void test_repo_reservedname__includes_shortname_on_win32(void)
{
git_repository *repo;
- git_buf *reserved;
+ git_str *reserved;
size_t reserved_len;
repo = cl_git_sandbox_init("nasty");
@@ -29,7 +29,7 @@ void test_repo_reservedname__includes_shortname_on_win32(void)
void test_repo_reservedname__includes_shortname_when_requested(void)
{
git_repository *repo;
- git_buf *reserved;
+ git_str *reserved;
size_t reserved_len;
repo = cl_git_sandbox_init("nasty");
@@ -47,7 +47,7 @@ void test_repo_reservedname__custom_shortname_recognized(void)
{
#ifdef GIT_WIN32
git_repository *repo;
- git_buf *reserved;
+ git_str *reserved;
size_t reserved_len;
if (!cl_sandbox_supports_8dot3())
@@ -83,7 +83,7 @@ void test_repo_reservedname__submodule_pointer(void)
#ifdef GIT_WIN32
git_repository *super_repo, *sub_repo;
git_submodule *sub;
- git_buf *sub_reserved;
+ git_str *sub_reserved;
size_t sub_reserved_len;
if (!cl_sandbox_supports_8dot3())
@@ -117,16 +117,16 @@ void test_repo_reservedname__submodule_pointer_during_create(void)
git_repository *repo;
git_submodule *sm;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
- git_buf url = GIT_BUF_INIT;
+ git_str url = GIT_STR_INIT;
repo = setup_fixture_super();
- cl_git_pass(git_buf_joinpath(&url, clar_sandbox_path(), "sub.git"));
+ cl_git_pass(git_str_joinpath(&url, clar_sandbox_path(), "sub.git"));
cl_repo_set_string(repo, "submodule.sub.url", url.ptr);
cl_git_pass(git_submodule_lookup(&sm, repo, "sub"));
cl_git_pass(git_submodule_update(sm, 1, &update_options));
git_submodule_free(sm);
- git_buf_dispose(&url);
+ git_str_dispose(&url);
}
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index 1fac627f6..2c33db0db 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
-#include "buffer.h"
#include "posix.h"
#include "util.h"
#include "path.h"
@@ -47,20 +46,20 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
- git_buf content = GIT_BUF_INIT;
+ git_str content = GIT_STR_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
cl_assert(git_path_isfile("./new_workdir/.git"));
cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
- cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
- cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
- git_buf_dispose(&content);
+ cl_assert(git__prefixcmp(git_str_cstr(&content), "gitdir: ") == 0);
+ cl_assert(git__suffixcmp(git_str_cstr(&content), "testrepo.git/") == 0);
+ git_str_dispose(&content);
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
- cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);
+ cl_assert(git__suffixcmp(buf.ptr, "new_workdir/") == 0);
git_buf_dispose(&buf);
git_config_free(cfg);
@@ -81,7 +80,7 @@ void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_o
git_index_free(new_index);
- /*
+ /*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
@@ -102,7 +101,7 @@ void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_pro
git_odb_free(new_odb);
- /*
+ /*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
diff --git a/tests/repo/state.c b/tests/repo/state.c
index afb361787..92b272dce 100644
--- a/tests/repo/state.c
+++ b/tests/repo/state.c
@@ -1,11 +1,10 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "refs.h"
#include "posix.h"
#include "futils.h"
static git_repository *_repo;
-static git_buf _path;
+static git_str _path;
void test_repo_state__initialize(void)
{
@@ -15,14 +14,14 @@ void test_repo_state__initialize(void)
void test_repo_state__cleanup(void)
{
cl_git_sandbox_cleanup();
- git_buf_dispose(&_path);
+ git_str_dispose(&_path);
}
static void setup_simple_state(const char *filename)
{
- cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
- git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
- cl_git_mkfile(git_buf_cstr(&_path), "dummy");
+ cl_git_pass(git_str_joinpath(&_path, git_repository_path(_repo), filename));
+ git_futils_mkpath2file(git_str_cstr(&_path), 0777);
+ cl_git_mkfile(git_str_cstr(&_path), "dummy");
}
static void assert_repo_state(git_repository_state_t state)
diff --git a/tests/repo/template.c b/tests/repo/template.c
index 3513190ac..6f369c6d6 100644
--- a/tests/repo/template.c
+++ b/tests/repo/template.c
@@ -7,7 +7,7 @@
static git_repository *_repo = NULL;
static mode_t g_umask = 0;
-static git_buf _global_path = GIT_BUF_INIT;
+static git_str _global_path = GIT_STR_INIT;
static const char *fixture_repo;
static const char *fixture_templates;
@@ -27,7 +27,7 @@ void test_repo_template__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
_global_path.ptr);
- git_buf_dispose(&_global_path);
+ git_str_dispose(&_global_path);
cl_fixture_cleanup("tmp_global_path");
@@ -51,14 +51,14 @@ static void assert_hooks_match(
const char *hook_path,
bool core_filemode)
{
- git_buf expected = GIT_BUF_INIT;
- git_buf actual = GIT_BUF_INIT;
+ git_str expected = GIT_STR_INIT;
+ git_str actual = GIT_STR_INIT;
struct stat expected_st, st;
- cl_git_pass(git_buf_joinpath(&expected, template_dir, hook_path));
+ cl_git_pass(git_str_joinpath(&expected, template_dir, hook_path));
cl_git_pass(git_path_lstat(expected.ptr, &expected_st));
- cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
+ cl_git_pass(git_str_joinpath(&actual, repo_dir, hook_path));
cl_git_pass(git_path_lstat(actual.ptr, &st));
cl_assert(expected_st.st_size == st.st_size);
@@ -76,20 +76,20 @@ static void assert_hooks_match(
cl_assert_equal_i_fmt(expected_mode, st.st_mode, "%07o");
}
- git_buf_dispose(&expected);
- git_buf_dispose(&actual);
+ git_str_dispose(&expected);
+ git_str_dispose(&actual);
}
static void assert_mode_seems_okay(
const char *base, const char *path,
git_filemode_t expect_mode, bool expect_setgid, bool core_filemode)
{
- git_buf full = GIT_BUF_INIT;
+ git_str full = GIT_STR_INIT;
struct stat st;
- cl_git_pass(git_buf_joinpath(&full, base, path));
+ cl_git_pass(git_str_joinpath(&full, base, path));
cl_git_pass(git_path_lstat(full.ptr, &st));
- git_buf_dispose(&full);
+ git_str_dispose(&full);
if (!core_filemode) {
CLEAR_FOR_CORE_FILEMODE(expect_mode);
@@ -115,7 +115,7 @@ static void setup_repo(const char *name, git_repository_init_options *opts)
static void setup_templates(const char *name, bool setup_globally)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_fixture_sandbox("template");
if (strcmp(name, "template"))
@@ -127,40 +127,40 @@ static void setup_templates(const char *name, bool setup_globally)
* Create a symlink from link.sample to update.sample if the filesystem
* supports it.
*/
- cl_git_pass(git_buf_join3(&path, '/', name, "hooks", "link.sample"));
+ cl_git_pass(git_str_join3(&path, '/', name, "hooks", "link.sample"));
#ifdef GIT_WIN32
cl_git_mkfile(path.ptr, "#!/bin/sh\necho hello, world\n");
#else
cl_must_pass(p_symlink("update.sample", path.ptr));
#endif
- git_buf_clear(&path);
+ git_str_clear(&path);
/* Create a file starting with a dot */
- cl_git_pass(git_buf_join3(&path, '/', name, "hooks", ".dotfile"));
+ cl_git_pass(git_str_join3(&path, '/', name, "hooks", ".dotfile"));
cl_git_mkfile(path.ptr, "something\n");
- git_buf_clear(&path);
+ git_str_clear(&path);
if (setup_globally) {
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), name));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), name));
create_tmp_global_config("tmp_global_path", "init.templatedir", path.ptr);
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void validate_templates(git_repository *repo, const char *template_path)
{
- git_buf path = GIT_BUF_INIT, expected = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, expected = GIT_STR_INIT, actual = GIT_STR_INIT;
int filemode;
- cl_git_pass(git_buf_joinpath(&path, template_path, "description"));
+ cl_git_pass(git_str_joinpath(&path, template_path, "description"));
cl_git_pass(git_futils_readbuffer(&expected, path.ptr));
- git_buf_clear(&path);
+ git_str_clear(&path);
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "description"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "description"));
cl_git_pass(git_futils_readbuffer(&actual, path.ptr));
cl_assert_equal_s(expected.ptr, actual.ptr);
@@ -177,9 +177,9 @@ static void validate_templates(git_repository *repo, const char *template_path)
template_path, git_repository_path(repo),
"hooks/.dotfile", filemode);
- git_buf_dispose(&expected);
- git_buf_dispose(&actual);
- git_buf_dispose(&path);
+ git_str_dispose(&expected);
+ git_str_dispose(&actual);
+ git_str_dispose(&path);
}
void test_repo_template__external_templates_specified_in_options(void)
@@ -252,7 +252,7 @@ void test_repo_template__extended_with_template_and_shared_mode(void)
void test_repo_template__templated_head_is_used(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf head = GIT_BUF_INIT;
+ git_str head = GIT_STR_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
@@ -263,13 +263,13 @@ void test_repo_template__templated_head_is_used(void)
cl_git_pass(git_futils_readbuffer(&head, "repo/.git/HEAD"));
cl_assert_equal_s("foobar\n", head.ptr);
- git_buf_dispose(&head);
+ git_str_dispose(&head);
}
void test_repo_template__initial_head_option_overrides_template_head(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_buf head = GIT_BUF_INIT;
+ git_str head = GIT_STR_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
opts.initial_head = "manual";
@@ -281,7 +281,7 @@ void test_repo_template__initial_head_option_overrides_template_head(void)
cl_git_pass(git_futils_readbuffer(&head, "repo/.git/HEAD"));
cl_assert_equal_s("ref: refs/heads/manual\n", head.ptr);
- git_buf_dispose(&head);
+ git_str_dispose(&head);
}
void test_repo_template__empty_template_path(void)
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 1ea1d13fb..36e8f1470 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -40,7 +40,7 @@ static int strequal_ignore_eol(const char *exp, const char *str)
void test_reset_hard__resetting_reverts_modified_files(void)
{
- git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, content = GIT_STR_INIT;
int i;
static const char *files[4] = {
"current_file",
@@ -64,7 +64,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_assert(wd);
for (i = 0; i < 4; ++i) {
- cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_str_joinpath(&path, wd, files[i]));
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert_equal_s(before[i], content.ptr);
}
@@ -74,7 +74,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
for (i = 0; i < 4; ++i) {
- cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
+ cl_git_pass(git_str_joinpath(&path, wd, files[i]));
if (after[i]) {
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert(strequal_ignore_eol(after[i], content.ptr));
@@ -83,8 +83,8 @@ void test_reset_hard__resetting_reverts_modified_files(void)
}
}
- git_buf_dispose(&content);
- git_buf_dispose(&path);
+ git_str_dispose(&content);
+ git_str_dispose(&path);
}
void test_reset_hard__cannot_reset_in_a_bare_repository(void)
@@ -165,42 +165,42 @@ void test_reset_hard__resetting_reverts_unmerged(void)
void test_reset_hard__cleans_up_merge(void)
{
- git_buf merge_head_path = GIT_BUF_INIT,
- merge_msg_path = GIT_BUF_INIT,
- merge_mode_path = GIT_BUF_INIT,
- orig_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT,
+ merge_msg_path = GIT_STR_INIT,
+ merge_mode_path = GIT_STR_INIT,
+ orig_head_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_str_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
- cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
+ cl_git_pass(git_str_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
+ cl_git_mkfile(git_str_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
- cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
- cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");
+ cl_git_pass(git_str_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
+ cl_git_mkfile(git_str_cstr(&merge_mode_path), "");
- cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
- cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
+ cl_git_pass(git_str_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
+ cl_git_mkfile(git_str_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
- cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_head_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_msg_path)));
+ cl_assert(!git_path_exists(git_str_cstr(&merge_mode_path)));
- cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
- cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));
+ cl_assert(git_path_exists(git_str_cstr(&orig_head_path)));
+ cl_git_pass(p_unlink(git_str_cstr(&orig_head_path)));
- git_buf_dispose(&merge_head_path);
- git_buf_dispose(&merge_msg_path);
- git_buf_dispose(&merge_mode_path);
- git_buf_dispose(&orig_head_path);
+ git_str_dispose(&merge_head_path);
+ git_str_dispose(&merge_msg_path);
+ git_str_dispose(&merge_mode_path);
+ git_str_dispose(&orig_head_path);
}
void test_reset_hard__reflog_is_correct(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Add a file which name should appear before the "
"\"subdir/\" folder while being dealt with by the treewalker";
@@ -218,12 +218,12 @@ void test_reset_hard__reflog_is_correct(void)
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ cl_git_pass(git_str_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
- reflog_check(repo, "HEAD", 4, NULL, git_buf_cstr(&buf));
- reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));
+ reflog_check(repo, "HEAD", 4, NULL, git_str_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 4, NULL, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
diff --git a/tests/reset/mixed.c b/tests/reset/mixed.c
index 9928c6871..4a78d4c37 100644
--- a/tests/reset/mixed.c
+++ b/tests/reset/mixed.c
@@ -50,7 +50,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
void test_reset_mixed__reflog_is_correct(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
@@ -68,12 +68,12 @@ void test_reset_mixed__reflog_is_correct(void)
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
- git_buf_clear(&buf);
- cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
- reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
- reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ reflog_check(repo, "HEAD", 10, NULL, git_str_cstr(&buf));
+ reflog_check(repo, "refs/heads/master", 10, NULL, git_str_cstr(&buf));
+ git_str_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
diff --git a/tests/reset/soft.c b/tests/reset/soft.c
index d9cfb0553..aca0834f2 100644
--- a/tests/reset/soft.c
+++ b/tests/reset/soft.c
@@ -116,33 +116,33 @@ void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_lo
void test_reset_soft__fails_when_merging(void)
{
- git_buf merge_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT;
cl_git_pass(git_repository_detach_head(repo));
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_mkfile(git_str_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
- cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
+ cl_git_pass(p_unlink(git_str_cstr(&merge_head_path)));
- git_buf_dispose(&merge_head_path);
+ git_str_dispose(&merge_head_path);
}
void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE_HEAD_file_existence(void)
{
git_index *index;
git_reference *head;
- git_buf merge_head_path = GIT_BUF_INIT;
+ git_str merge_head_path = GIT_STR_INIT;
cl_git_sandbox_cleanup();
repo = cl_git_sandbox_init("mergedrepo");
- cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
- cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
- git_buf_dispose(&merge_head_path);
+ cl_git_pass(git_str_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
+ cl_git_pass(p_unlink(git_str_cstr(&merge_head_path)));
+ git_str_dispose(&merge_head_path);
cl_git_pass(git_repository_index(&index, repo));
cl_assert_equal_i(true, git_index_has_conflicts(index));
diff --git a/tests/revert/bare.c b/tests/revert/bare.c
index 03cffbf3e..9261cfe86 100644
--- a/tests/revert/bare.c
+++ b/tests/revert/bare.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/revert.h"
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 2ad059d99..36824044b 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -1,7 +1,6 @@
#include "clar.h"
#include "clar_libgit2.h"
-#include "buffer.h"
#include "futils.h"
#include "git2/revert.h"
@@ -66,7 +65,7 @@ void test_revert_workdir__conflicts(void)
git_reference *head_ref;
git_commit *head, *commit;
git_oid revert_oid;
- git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
+ git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 1, "file1.txt" },
@@ -126,8 +125,8 @@ void test_revert_workdir__conflicts(void)
git_commit_free(commit);
git_commit_free(head);
git_reference_free(head_ref);
- git_buf_dispose(&mergemsg_buf);
- git_buf_dispose(&conflicting_buf);
+ git_str_dispose(&mergemsg_buf);
+ git_str_dispose(&conflicting_buf);
}
/* git reset --hard 39467716290f6df775a91cdb9a4eb39295018145
@@ -308,7 +307,7 @@ void test_revert_workdir__again_after_edit(void)
*/
void test_revert_workdir__again_after_edit_two(void)
{
- git_buf diff_buf = GIT_BUF_INIT;
+ git_str diff_buf = GIT_STR_INIT;
git_config *config;
git_oid head_commit_oid, revert_commit_oid;
git_commit *head_commit, *revert_commit;
@@ -350,7 +349,7 @@ void test_revert_workdir__again_after_edit_two(void)
git_commit_free(revert_commit);
git_commit_free(head_commit);
git_config_free(config);
- git_buf_dispose(&diff_buf);
+ git_str_dispose(&diff_buf);
}
/* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45
diff --git a/tests/stash/apply.c b/tests/stash/apply.c
index 5eb59545e..c3d1ef0c2 100644
--- a/tests/stash/apply.c
+++ b/tests/stash/apply.c
@@ -70,7 +70,7 @@ void test_stash_apply__cleanup(void)
void test_stash_apply__with_default(void)
{
- git_buf where = GIT_BUF_INIT;
+ git_str where = GIT_STR_INIT;
cl_git_pass(git_stash_apply(repo, 0, NULL));
@@ -85,7 +85,7 @@ void test_stash_apply__with_default(void)
cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
cl_assert_equal_s("....\n", where.ptr);
- git_buf_dispose(&where);
+ git_str_dispose(&where);
}
void test_stash_apply__with_existing_file(void)
@@ -114,7 +114,7 @@ void test_stash_apply__merges_new_file(void)
void test_stash_apply__with_reinstate_index(void)
{
- git_buf where = GIT_BUF_INIT;
+ git_str where = GIT_STR_INIT;
git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
@@ -132,7 +132,7 @@ void test_stash_apply__with_reinstate_index(void)
cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
cl_assert_equal_s("....\n", where.ptr);
- git_buf_dispose(&where);
+ git_str_dispose(&where);
}
void test_stash_apply__conflict_index_with_default(void)
diff --git a/tests/stash/save.c b/tests/stash/save.c
index d568567d5..1fbcf0957 100644
--- a/tests/stash/save.c
+++ b/tests/stash/save.c
@@ -201,12 +201,12 @@ void test_stash_save__untracked_regression(void)
const char *paths[] = {"what", "where", "how", "why"};
git_reference *head;
git_commit *head_commit;
- git_buf untracked_dir;
+ git_str untracked_dir;
const char* workdir = git_repository_workdir(repo);
- git_buf_init(&untracked_dir, 0);
- git_buf_printf(&untracked_dir, "%sz", workdir);
+ git_str_init(&untracked_dir, 0);
+ git_str_printf(&untracked_dir, "%sz", workdir);
cl_assert(!p_mkdir(untracked_dir.ptr, 0777));
@@ -227,7 +227,7 @@ void test_stash_save__untracked_regression(void)
git_reference_free(head);
git_commit_free(head_commit);
- git_buf_dispose(&untracked_dir);
+ git_str_dispose(&untracked_dir);
}
#define MESSAGE "Look Ma! I'm on TV!"
diff --git a/tests/status/renames.c b/tests/status/renames.c
index 7deec980f..e69dbcce0 100644
--- a/tests/status/renames.c
+++ b/tests/status/renames.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "posix.h"
#include "status_helpers.h"
@@ -23,11 +22,11 @@ void test_status_renames__cleanup(void)
static void _rename_helper(
git_repository *repo, const char *from, const char *to, const char *extra)
{
- git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
+ git_str oldpath = GIT_STR_INIT, newpath = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(
+ cl_git_pass(git_str_joinpath(
&oldpath, git_repository_workdir(repo), from));
- cl_git_pass(git_buf_joinpath(
+ cl_git_pass(git_str_joinpath(
&newpath, git_repository_workdir(repo), to));
cl_git_pass(p_rename(oldpath.ptr, newpath.ptr));
@@ -35,8 +34,8 @@ static void _rename_helper(
if (extra)
cl_git_append2file(newpath.ptr, extra);
- git_buf_dispose(&oldpath);
- git_buf_dispose(&newpath);
+ git_str_dispose(&oldpath);
+ git_str_dispose(&newpath);
}
#define rename_file(R,O,N) _rename_helper((R), (O), (N), NULL)
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index d9fce4404..4ab04094a 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -100,9 +100,9 @@ void test_status_worktree__empty_repository(void)
cl_assert_equal_i(0, count);
}
-static int remove_file_cb(void *data, git_buf *file)
+static int remove_file_cb(void *data, git_str *file)
{
- const char *filename = git_buf_cstr(file);
+ const char *filename = git_str_cstr(file);
GIT_UNUSED(data);
@@ -112,7 +112,7 @@ static int remove_file_cb(void *data, git_buf *file)
if (git_path_isdir(filename))
cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_RMDIR_REMOVE_FILES));
else
- cl_git_pass(p_unlink(git_buf_cstr(file)));
+ cl_git_pass(p_unlink(git_str_cstr(file)));
return 0;
}
@@ -122,12 +122,12 @@ void test_status_worktree__purged_worktree(void)
{
status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
- git_buf workdir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT;
/* first purge the contents of the worktree */
- cl_git_pass(git_buf_sets(&workdir, git_repository_workdir(repo)));
+ cl_git_pass(git_str_sets(&workdir, git_repository_workdir(repo)));
cl_git_pass(git_path_direach(&workdir, 0, remove_file_cb, NULL));
- git_buf_dispose(&workdir);
+ git_str_dispose(&workdir);
/* now get status */
memset(&counts, 0x0, sizeof(status_entry_counts));
@@ -369,78 +369,78 @@ static int cb_status__check_592(const char *p, unsigned int s, void *payload)
void test_status_worktree__issue_592(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "l.txt"));
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "l.txt"));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_assert(!git_path_exists("issue_592/l.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "l.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_2(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_3(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c"));
+ cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_4(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "t/b.txt"));
- cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "t/b.txt"));
+ cl_git_pass(p_unlink(git_str_cstr(&path)));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "t/b.txt"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_5(void)
{
git_repository *repo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "t"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
- cl_git_pass(p_mkdir(git_buf_cstr(&path), 0777));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "t"));
+ cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(p_mkdir(git_str_cstr(&path), 0777));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_status_worktree__issue_592_ignores_0(void)
@@ -610,8 +610,8 @@ void test_status_worktree__filemode_non755(void)
git_repository *repo = cl_git_sandbox_init("filemodes");
status_entry_counts counts;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
- git_buf executable_path = GIT_BUF_INIT;
- git_buf nonexecutable_path = GIT_BUF_INIT;
+ git_str executable_path = GIT_STR_INIT;
+ git_str nonexecutable_path = GIT_STR_INIT;
if (!cl_is_chmod_supported())
return;
@@ -620,14 +620,14 @@ void test_status_worktree__filemode_non755(void)
GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
- git_buf_joinpath(&executable_path, git_repository_workdir(repo), "exec_on");
- cl_must_pass(p_chmod(git_buf_cstr(&executable_path), 0744));
- git_buf_dispose(&executable_path);
+ git_str_joinpath(&executable_path, git_repository_workdir(repo), "exec_on");
+ cl_must_pass(p_chmod(git_str_cstr(&executable_path), 0744));
+ git_str_dispose(&executable_path);
- git_buf_joinpath(&nonexecutable_path, git_repository_workdir(repo), "exec_off");
+ git_str_joinpath(&nonexecutable_path, git_repository_workdir(repo), "exec_off");
- cl_must_pass(p_chmod(git_buf_cstr(&nonexecutable_path), 0655));
- git_buf_dispose(&nonexecutable_path);
+ cl_must_pass(p_chmod(git_str_cstr(&nonexecutable_path), 0655));
+ git_str_dispose(&nonexecutable_path);
memset(&counts, 0, sizeof(counts));
counts.expected_entry_count = filemode_count;
@@ -789,7 +789,7 @@ static void assert_ignore_case(
int expected_camel_cased_file_status)
{
unsigned int status;
- git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
+ git_str lower_case_path = GIT_STR_INIT, camel_case_path = GIT_STR_INIT;
git_repository *repo, *repo2;
repo = cl_git_sandbox_init("empty_standard_repo");
@@ -797,10 +797,10 @@ static void assert_ignore_case(
cl_repo_set_bool(repo, "core.ignorecase", should_ignore_case);
- cl_git_pass(git_buf_joinpath(&lower_case_path,
+ cl_git_pass(git_str_joinpath(&lower_case_path,
git_repository_workdir(repo), "plop"));
- cl_git_mkfile(git_buf_cstr(&lower_case_path), "");
+ cl_git_mkfile(git_str_cstr(&lower_case_path), "");
stage_and_commit(repo, "plop");
@@ -809,10 +809,10 @@ static void assert_ignore_case(
cl_git_pass(git_status_file(&status, repo2, "plop"));
cl_assert_equal_i(GIT_STATUS_CURRENT, status);
- cl_git_pass(git_buf_joinpath(&camel_case_path,
+ cl_git_pass(git_str_joinpath(&camel_case_path,
git_repository_workdir(repo), "Plop"));
- cl_git_pass(p_rename(git_buf_cstr(&lower_case_path), git_buf_cstr(&camel_case_path)));
+ cl_git_pass(p_rename(git_str_cstr(&lower_case_path), git_str_cstr(&camel_case_path)));
cl_git_pass(git_status_file(&status, repo2, "plop"));
cl_assert_equal_i(expected_lower_cased_file_status, status);
@@ -821,8 +821,8 @@ static void assert_ignore_case(
cl_assert_equal_i(expected_camel_cased_file_status, status);
git_repository_free(repo2);
- git_buf_dispose(&lower_case_path);
- git_buf_dispose(&camel_case_path);
+ git_str_dispose(&lower_case_path);
+ git_str_dispose(&camel_case_path);
}
void test_status_worktree__file_status_honors_core_ignorecase_true(void)
diff --git a/tests/str/basic.c b/tests/str/basic.c
new file mode 100644
index 000000000..5d2556805
--- /dev/null
+++ b/tests/str/basic.c
@@ -0,0 +1,50 @@
+#include "clar_libgit2.h"
+
+static const char *test_string = "Have you seen that? Have you seeeen that??";
+
+void test_str_basic__resize(void)
+{
+ git_str buf1 = GIT_STR_INIT;
+ git_str_puts(&buf1, test_string);
+ cl_assert(git_str_oom(&buf1) == 0);
+ cl_assert_equal_s(git_str_cstr(&buf1), test_string);
+
+ git_str_puts(&buf1, test_string);
+ cl_assert(strlen(git_str_cstr(&buf1)) == strlen(test_string) * 2);
+ git_str_dispose(&buf1);
+}
+
+void test_str_basic__resize_incremental(void)
+{
+ git_str buf1 = GIT_STR_INIT;
+
+ /* Presently, asking for 6 bytes will round up to 8. */
+ cl_git_pass(git_str_puts(&buf1, "Hello"));
+ cl_assert_equal_i(5, buf1.size);
+ cl_assert_equal_i(8, buf1.asize);
+
+ /* Ensure an additional byte does not realloc. */
+ cl_git_pass(git_str_grow_by(&buf1, 1));
+ cl_assert_equal_i(5, buf1.size);
+ cl_assert_equal_i(8, buf1.asize);
+
+ /* But requesting many does. */
+ cl_git_pass(git_str_grow_by(&buf1, 16));
+ cl_assert_equal_i(5, buf1.size);
+ cl_assert(buf1.asize > 8);
+
+ git_str_dispose(&buf1);
+}
+
+void test_str_basic__printf(void)
+{
+ git_str buf2 = GIT_STR_INIT;
+ git_str_printf(&buf2, "%s %s %d ", "shoop", "da", 23);
+ cl_assert(git_str_oom(&buf2) == 0);
+ cl_assert_equal_s(git_str_cstr(&buf2), "shoop da 23 ");
+
+ git_str_printf(&buf2, "%s %d", "woop", 42);
+ cl_assert(git_str_oom(&buf2) == 0);
+ cl_assert_equal_s(git_str_cstr(&buf2), "shoop da 23 woop 42");
+ git_str_dispose(&buf2);
+}
diff --git a/tests/buf/oom.c b/tests/str/oom.c
index 726234ef8..3d59ead01 100644
--- a/tests/buf/oom.c
+++ b/tests/str/oom.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
/* Override default allocators with ones that will fail predictably. */
@@ -18,7 +17,7 @@ static void *oom_realloc(void *p, size_t n, const char *file, int line)
return (n > 100) ? NULL : std_alloc.grealloc(p, n, file, line);
}
-void test_buf_oom__initialize(void)
+void test_str_oom__initialize(void)
{
git_stdalloc_init_allocator(&std_alloc);
git_stdalloc_init_allocator(&oom_alloc);
@@ -29,31 +28,31 @@ void test_buf_oom__initialize(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, &oom_alloc));
}
-void test_buf_oom__cleanup(void)
+void test_str_oom__cleanup(void)
{
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, NULL));
}
-void test_buf_oom__grow(void)
+void test_str_oom__grow(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_grow(&buf, 42));
- cl_assert(!git_buf_oom(&buf));
+ cl_git_pass(git_str_grow(&buf, 42));
+ cl_assert(!git_str_oom(&buf));
- cl_assert(git_buf_grow(&buf, 101) == -1);
- cl_assert(git_buf_oom(&buf));
+ cl_assert(git_str_grow(&buf, 101) == -1);
+ cl_assert(git_str_oom(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_buf_oom__grow_by(void)
+void test_str_oom__grow_by(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_grow_by(&buf, 42));
- cl_assert(!git_buf_oom(&buf));
+ cl_git_pass(git_str_grow_by(&buf, 42));
+ cl_assert(!git_str_oom(&buf));
- cl_assert(git_buf_grow_by(&buf, 101) == -1);
- cl_assert(git_buf_oom(&buf));
+ cl_assert(git_str_grow_by(&buf, 101) == -1);
+ cl_assert(git_str_oom(&buf));
}
diff --git a/tests/buf/percent.c b/tests/str/percent.c
index 8c47b833d..339389075 100644
--- a/tests/buf/percent.c
+++ b/tests/str/percent.c
@@ -1,28 +1,27 @@
#include "clar_libgit2.h"
-#include "buffer.h"
static void expect_decode_pass(const char *expected, const char *encoded)
{
- git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+ git_str in = GIT_STR_INIT, out = GIT_STR_INIT;
/*
* ensure that we only read the given length of the input buffer
* by putting garbage at the end. this will ensure that we do
* not, eg, rely on nul-termination or walk off the end of the buf.
*/
- cl_git_pass(git_buf_puts(&in, encoded));
- cl_git_pass(git_buf_PUTS(&in, "TRAILER"));
+ cl_git_pass(git_str_puts(&in, encoded));
+ cl_git_pass(git_str_PUTS(&in, "TRAILER"));
- cl_git_pass(git_buf_decode_percent(&out, in.ptr, strlen(encoded)));
+ cl_git_pass(git_str_decode_percent(&out, in.ptr, strlen(encoded)));
- cl_assert_equal_s(expected, git_buf_cstr(&out));
- cl_assert_equal_i(strlen(expected), git_buf_len(&out));
+ cl_assert_equal_s(expected, git_str_cstr(&out));
+ cl_assert_equal_i(strlen(expected), git_str_len(&out));
- git_buf_dispose(&in);
- git_buf_dispose(&out);
+ git_str_dispose(&in);
+ git_str_dispose(&out);
}
-void test_buf_percent__decode_succeeds(void)
+void test_str_percent__decode_succeeds(void)
{
expect_decode_pass("", "");
expect_decode_pass(" ", "%20");
@@ -37,7 +36,7 @@ void test_buf_percent__decode_succeeds(void)
expect_decode_pass("foo bar ", "foo%20bar%20");
}
-void test_buf_percent__ignores_invalid(void)
+void test_str_percent__ignores_invalid(void)
{
expect_decode_pass("githu%%.com", "githu%%.com");
expect_decode_pass("github.co%2", "github.co%2");
diff --git a/tests/buf/quote.c b/tests/str/quote.c
index 8867ae7d6..2c6546247 100644
--- a/tests/buf/quote.c
+++ b/tests/str/quote.c
@@ -1,20 +1,19 @@
#include "clar_libgit2.h"
-#include "buffer.h"
static void expect_quote_pass(const char *expected, const char *str)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&buf, str));
- cl_git_pass(git_buf_quote(&buf));
+ cl_git_pass(git_str_puts(&buf, str));
+ cl_git_pass(git_str_quote(&buf));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- cl_assert_equal_i(strlen(expected), git_buf_len(&buf));
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ cl_assert_equal_i(strlen(expected), git_str_len(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_buf_quote__quote_succeeds(void)
+void test_str_quote__quote_succeeds(void)
{
expect_quote_pass("", "");
expect_quote_pass("foo", "foo");
@@ -30,28 +29,28 @@ void test_buf_quote__quote_succeeds(void)
static void expect_unquote_pass(const char *expected, const char *quoted)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&buf, quoted));
- cl_git_pass(git_buf_unquote(&buf));
+ cl_git_pass(git_str_puts(&buf, quoted));
+ cl_git_pass(git_str_unquote(&buf));
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- cl_assert_equal_i(strlen(expected), git_buf_len(&buf));
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ cl_assert_equal_i(strlen(expected), git_str_len(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void expect_unquote_fail(const char *quoted)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&buf, quoted));
- cl_git_fail(git_buf_unquote(&buf));
+ cl_git_pass(git_str_puts(&buf, quoted));
+ cl_git_fail(git_str_unquote(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_buf_quote__unquote_succeeds(void)
+void test_str_quote__unquote_succeeds(void)
{
expect_unquote_pass("", "\"\"");
expect_unquote_pass(" ", "\" \"");
@@ -68,7 +67,7 @@ void test_buf_quote__unquote_succeeds(void)
expect_unquote_pass("0xff: \377", "\"0xff: \\377\"");
}
-void test_buf_quote__unquote_fails(void)
+void test_str_quote__unquote_fails(void)
{
expect_unquote_fail("no quotes at all");
expect_unquote_fail("\"no trailing quote");
diff --git a/tests/str/splice.c b/tests/str/splice.c
new file mode 100644
index 000000000..14e844e2f
--- /dev/null
+++ b/tests/str/splice.c
@@ -0,0 +1,92 @@
+#include "clar_libgit2.h"
+
+static git_str _buf;
+
+void test_str_splice__initialize(void) {
+ git_str_init(&_buf, 16);
+}
+
+void test_str_splice__cleanup(void) {
+ git_str_dispose(&_buf);
+}
+
+void test_str_splice__preprend(void)
+{
+ git_str_sets(&_buf, "world!");
+
+ cl_git_pass(git_str_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__append(void)
+{
+ git_str_sets(&_buf, "Hello");
+
+ cl_git_pass(git_str_splice(&_buf, git_str_len(&_buf), 0, " world!", strlen(" world!")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__insert_at(void)
+{
+ git_str_sets(&_buf, "Hell world!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__remove_at(void)
+{
+ git_str_sets(&_buf, "Hello world of warcraft!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__replace(void)
+{
+ git_str_sets(&_buf, "Hell0 w0rld!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__replace_with_longer(void)
+{
+ git_str_sets(&_buf, "Hello you!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__replace_with_shorter(void)
+{
+ git_str_sets(&_buf, "Brave new world!");
+
+ cl_git_pass(git_str_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__truncate(void)
+{
+ git_str_sets(&_buf, "Hello world!!");
+
+ cl_git_pass(git_str_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
+
+void test_str_splice__dont_do_anything(void)
+{
+ git_str_sets(&_buf, "Hello world!");
+
+ cl_git_pass(git_str_splice(&_buf, 3, 0, "Hello", 0));
+
+ cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
+}
diff --git a/tests/stress/diff.c b/tests/stress/diff.c
index 2ea0d4076..aecf08bbe 100644
--- a/tests/stress/diff.c
+++ b/tests/stress/diff.c
@@ -90,7 +90,7 @@ void test_stress_diff__rename_big_files(void)
git_index *index;
char tmp[64];
int i, j;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("renames");
@@ -99,7 +99,7 @@ void test_stress_diff__rename_big_files(void)
for (i = 0; i < 100; i += 1) {
p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
for (j = i * 256; j > 0; --j)
- git_buf_printf(&b, "more content %d\n", i);
+ git_str_printf(&b, "more content %d\n", i);
cl_git_mkfile(tmp, b.ptr);
}
@@ -108,7 +108,7 @@ void test_stress_diff__rename_big_files(void)
cl_git_pass(git_index_add_bypath(index, tmp + strlen("renames/")));
}
- git_buf_dispose(&b);
+ git_str_dispose(&b);
git_index_free(index);
test_with_many(100);
@@ -119,13 +119,13 @@ void test_stress_diff__rename_many_files(void)
git_index *index;
char tmp[64];
int i;
- git_buf b = GIT_BUF_INIT;
+ git_str b = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("renames");
cl_git_pass(git_repository_index(&index, g_repo));
- git_buf_printf(&b, "%08d\n" ANOTHER_POEM "%08d\n" ANOTHER_POEM ANOTHER_POEM, 0, 0);
+ git_str_printf(&b, "%08d\n" ANOTHER_POEM "%08d\n" ANOTHER_POEM ANOTHER_POEM, 0, 0);
for (i = 0; i < 2500; i += 1) {
p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
@@ -133,7 +133,7 @@ void test_stress_diff__rename_many_files(void)
b.ptr[8] = '\n';
cl_git_mkfile(tmp, b.ptr);
}
- git_buf_dispose(&b);
+ git_str_dispose(&b);
for (i = 0; i < 2500; i += 1) {
p_snprintf(tmp, sizeof(tmp), "renames/newfile%03d", i);
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index fc458f826..b564123dd 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -17,20 +17,20 @@ void test_submodule_add__cleanup(void)
static void assert_submodule_url(const char* name, const char *url)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
- cl_git_pass(git_buf_printf(&key, "submodule.%s.url", name));
- assert_config_entry_value(g_repo, git_buf_cstr(&key), url);
+ cl_git_pass(git_str_printf(&key, "submodule.%s.url", name));
+ assert_config_entry_value(g_repo, git_str_cstr(&key), url);
- git_buf_dispose(&key);
+ git_str_dispose(&key);
}
void test_submodule_add__url_absolute(void)
{
git_submodule *sm;
git_repository *repo;
- git_buf dot_git_content = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
g_repo = setup_fixture_submod2();
@@ -63,7 +63,7 @@ void test_submodule_add__url_absolute(void)
cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/", dot_git_content.ptr);
git_repository_free(repo);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
/* add a submodule not using a gitlink */
@@ -151,11 +151,11 @@ void test_submodule_add__path_exists_in_index(void)
{
git_index *index;
git_submodule *sm;
- git_buf filename = GIT_BUF_INIT;
+ git_str filename = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("testrepo");
- cl_git_pass(git_buf_joinpath(&filename, "subdirectory", "test.txt"));
+ cl_git_pass(git_str_joinpath(&filename, "subdirectory", "test.txt"));
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
@@ -164,14 +164,14 @@ void test_submodule_add__path_exists_in_index(void)
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
git_submodule_free(sm);
- git_buf_dispose(&filename);
+ git_str_dispose(&filename);
}
void test_submodule_add__file_exists_in_index(void)
{
git_index *index;
git_submodule *sm;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
g_repo = cl_git_sandbox_init("testrepo");
@@ -182,7 +182,7 @@ void test_submodule_add__file_exists_in_index(void)
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
git_submodule_free(sm);
- git_buf_dispose(&name);
+ git_str_dispose(&name);
}
void test_submodule_add__submodule_clone(void)
diff --git a/tests/submodule/escape.c b/tests/submodule/escape.c
index 08eb76809..bcd52b510 100644
--- a/tests/submodule/escape.c
+++ b/tests/submodule/escape.c
@@ -33,17 +33,17 @@ void test_submodule_escape__from_gitdir(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
unsigned int sm_location;
g_repo = setup_fixture_submodule_simple();
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"" EVIL_SM_NAME "\"]\n"
" path = testrepo\n"
" url = ../testrepo.git\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Find it all the different ways we know about it */
foundit = 0;
@@ -67,17 +67,17 @@ void test_submodule_escape__from_gitdir_windows(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
unsigned int sm_location;
g_repo = setup_fixture_submodule_simple();
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"" EVIL_SM_NAME_WINDOWS "\"]\n"
" path = testrepo\n"
" url = ../testrepo.git\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* Find it all the different ways we know about it */
foundit = 0;
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index a1d870b9e..bf865a9e8 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -15,13 +15,13 @@ void test_submodule_init__absolute_url(void)
{
git_submodule *sm;
git_config *cfg;
- git_buf absolute_url = GIT_BUF_INIT;
+ git_str absolute_url = GIT_STR_INIT;
const char *config_url;
g_repo = setup_fixture_submodule_simple();
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
- cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+ cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
/* write the absolute url to the .gitmodules file*/
cl_git_pass(git_submodule_set_url(g_repo, "testrepo", absolute_url.ptr));
@@ -39,7 +39,7 @@ void test_submodule_init__absolute_url(void)
cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
- git_buf_dispose(&absolute_url);
+ git_str_dispose(&absolute_url);
git_config_free(cfg);
git_submodule_free(sm);
}
@@ -48,13 +48,13 @@ void test_submodule_init__relative_url(void)
{
git_submodule *sm;
git_config *cfg;
- git_buf absolute_url = GIT_BUF_INIT;
+ git_str absolute_url = GIT_STR_INIT;
const char *config_url;
g_repo = setup_fixture_submodule_simple();
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
- cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+ cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
@@ -69,7 +69,7 @@ void test_submodule_init__relative_url(void)
cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
- git_buf_dispose(&absolute_url);
+ git_str_dispose(&absolute_url);
git_config_free(cfg);
git_submodule_free(sm);
}
@@ -78,7 +78,7 @@ void test_submodule_init__relative_url_detached_head(void)
{
git_submodule *sm;
git_config *cfg;
- git_buf absolute_url = GIT_BUF_INIT;
+ git_str absolute_url = GIT_STR_INIT;
const char *config_url;
git_reference *head_ref = NULL;
git_object *head_commit = NULL;
@@ -92,7 +92,7 @@ void test_submodule_init__relative_url_detached_head(void)
cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit)));
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
- cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+ cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
@@ -107,7 +107,7 @@ void test_submodule_init__relative_url_detached_head(void)
cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
- git_buf_dispose(&absolute_url);
+ git_str_dispose(&absolute_url);
git_config_free(cfg);
git_object_free(head_commit);
git_reference_free(head_ref);
diff --git a/tests/submodule/inject_option.c b/tests/submodule/inject_option.c
index cfc02acff..e28ff8489 100644
--- a/tests/submodule/inject_option.c
+++ b/tests/submodule/inject_option.c
@@ -33,14 +33,14 @@ void test_submodule_inject_option__url(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"naughty\"]\n"
" path = testrepo\n"
" url = -u./payload\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* We do want to find it, but with the appropriate field empty */
foundit = 0;
@@ -58,14 +58,14 @@ void test_submodule_inject_option__path(void)
{
int foundit;
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
cl_git_rewritefile(buf.ptr,
"[submodule \"naughty\"]\n"
" path = --something\n"
" url = blah.git\n");
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* We do want to find it, but with the appropriate field empty */
foundit = 0;
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index f49ebb4bd..acfdc838c 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -255,7 +255,7 @@ static void add_submodule_with_commit(const char *name)
git_submodule *sm;
git_repository *smrepo;
git_index *idx;
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
cl_git_pass(git_submodule_add_setup(&sm, g_repo,
"https://github.com/libgit2/libgit2.git", name, 1));
@@ -265,9 +265,9 @@ static void add_submodule_with_commit(const char *name)
cl_git_pass(git_submodule_open(&smrepo, sm));
cl_git_pass(git_repository_index(&idx, smrepo));
- cl_git_pass(git_buf_joinpath(&p, git_repository_workdir(smrepo), "file"));
+ cl_git_pass(git_str_joinpath(&p, git_repository_workdir(smrepo), "file"));
cl_git_mkfile(p.ptr, "new file");
- git_buf_dispose(&p);
+ git_str_dispose(&p);
cl_git_pass(git_index_add_bypath(idx, "file"));
cl_git_pass(git_index_write(idx));
@@ -284,7 +284,7 @@ static void add_submodule_with_commit(const char *name)
void test_submodule_lookup__just_added(void)
{
git_submodule *sm;
- git_buf snap1 = GIT_BUF_INIT, snap2 = GIT_BUF_INIT;
+ git_str snap1 = GIT_STR_INIT, snap2 = GIT_STR_INIT;
git_reference *original_head = NULL;
refute_submodule_exists(g_repo, "sm_just_added", GIT_ENOTFOUND);
@@ -333,7 +333,7 @@ void test_submodule_lookup__just_added(void)
baseline_tests();
cl_git_rewritefile("submod2/.gitmodules", snap2.ptr);
- git_buf_dispose(&snap2);
+ git_str_dispose(&snap2);
refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
@@ -344,7 +344,7 @@ void test_submodule_lookup__just_added(void)
baseline_tests();
cl_git_rewritefile("submod2/.gitmodules", snap1.ptr);
- git_buf_dispose(&snap1);
+ git_str_dispose(&snap1);
refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 654f677e6..fd3b0f80b 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -213,7 +213,7 @@ void test_submodule_modify__set_url(void)
void test_submodule_modify__set_relative_url(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_repository *repo;
git_submodule *sm;
@@ -222,12 +222,12 @@ void test_submodule_modify__set_relative_url(void)
cl_git_pass(git_submodule_sync(sm));
cl_git_pass(git_submodule_open(&repo, sm));
- cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), "relative-url"));
+ cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "relative-url"));
assert_config_entry_value(g_repo, "submodule."SM1".url", path.ptr);
assert_config_entry_value(repo, "remote.origin.url", path.ptr);
git_repository_free(repo);
git_submodule_free(sm);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c
index e47ee3983..e82230e87 100644
--- a/tests/submodule/nosubs.c
+++ b/tests/submodule/nosubs.c
@@ -69,7 +69,7 @@ void test_submodule_nosubs__add_and_delete(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_submodule *sm;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2"));
cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2"));
@@ -85,7 +85,7 @@ void test_submodule_nosubs__add_and_delete(void)
cl_git_pass(git_futils_readbuffer(&buf, "status/.gitmodules"));
cl_assert(strstr(buf.ptr, "[submodule \"submodules/libgit2\"]") != NULL);
cl_assert(strstr(buf.ptr, "path = submodules/libgit2") != NULL);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* lookup */
diff --git a/tests/submodule/open.c b/tests/submodule/open.c
index a8a5dccc3..4f31feedf 100644
--- a/tests/submodule/open.c
+++ b/tests/submodule/open.c
@@ -23,33 +23,33 @@ void test_submodule_open__cleanup(void)
static void assert_sm_valid(git_repository *parent, git_repository *child, const char *sm_name)
{
- git_buf expected = GIT_BUF_INIT, actual = GIT_BUF_INIT;
+ git_str expected = GIT_STR_INIT, actual = GIT_STR_INIT;
/* assert working directory */
- cl_git_pass(git_buf_joinpath(&expected, git_repository_workdir(parent), sm_name));
+ cl_git_pass(git_str_joinpath(&expected, git_repository_workdir(parent), sm_name));
cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL));
- cl_git_pass(git_buf_sets(&actual, git_repository_workdir(child)));
+ cl_git_pass(git_str_sets(&actual, git_repository_workdir(child)));
cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_clear(&expected);
- git_buf_clear(&actual);
+ git_str_clear(&expected);
+ git_str_clear(&actual);
/* assert common directory */
- cl_git_pass(git_buf_joinpath(&expected, git_repository_commondir(parent), "modules"));
- cl_git_pass(git_buf_joinpath(&expected, expected.ptr, sm_name));
+ cl_git_pass(git_str_joinpath(&expected, git_repository_commondir(parent), "modules"));
+ cl_git_pass(git_str_joinpath(&expected, expected.ptr, sm_name));
cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL));
- cl_git_pass(git_buf_sets(&actual, git_repository_commondir(child)));
+ cl_git_pass(git_str_sets(&actual, git_repository_commondir(child)));
cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
cl_assert_equal_s(expected.ptr, actual.ptr);
/* assert git directory */
- cl_git_pass(git_buf_sets(&actual, git_repository_path(child)));
+ cl_git_pass(git_str_sets(&actual, git_repository_path(child)));
cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL));
cl_assert_equal_s(expected.ptr, actual.ptr);
- git_buf_dispose(&expected);
- git_buf_dispose(&actual);
+ git_str_dispose(&expected);
+ git_str_dispose(&actual);
}
void test_submodule_open__opening_via_lookup_succeeds(void)
@@ -61,18 +61,18 @@ void test_submodule_open__opening_via_lookup_succeeds(void)
void test_submodule_open__direct_open_succeeds(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
cl_git_pass(git_repository_open(&g_child, path.ptr));
assert_sm_valid(g_parent, g_child, "sm_unchanged");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_submodule_open__direct_open_succeeds_for_broken_sm_with_gitdir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
/*
* This is actually not a valid submodule, but we
@@ -82,9 +82,9 @@ void test_submodule_open__direct_open_succeeds_for_broken_sm_with_gitdir(void)
* add a test for this.
*/
cl_git_mkfile("submod2/.git/modules/sm_unchanged/gitdir", ".git");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_parent), "sm_unchanged"));
cl_git_pass(git_repository_open(&g_child, path.ptr));
assert_sm_valid(g_parent, g_child, "sm_unchanged");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index 9962af311..3927afc2e 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -11,7 +11,7 @@ void test_submodule_repository_init__basic(void)
{
git_submodule *sm;
git_repository *repo;
- git_buf dot_git_content = GIT_BUF_INIT;
+ git_str dot_git_content = GIT_STR_INIT;
g_repo = setup_fixture_submod2();
@@ -34,5 +34,5 @@ void test_submodule_repository_init__basic(void)
git_submodule_free(sm);
git_repository_free(repo);
- git_buf_dispose(&dot_git_content);
+ git_str_dispose(&dot_git_content);
}
diff --git a/tests/submodule/status.c b/tests/submodule/status.c
index 06595cc9a..1d41337b7 100644
--- a/tests/submodule/status.c
+++ b/tests/submodule/status.c
@@ -31,10 +31,10 @@ void test_submodule_status__unchanged(void)
static void rm_submodule(const char *name)
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), name));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), name));
cl_git_pass(git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void add_submodule_to_index(const char *name)
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index 1d4759616..95d20a009 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "path.h"
#include "util.h"
#include "posix.h"
@@ -12,12 +11,12 @@
*/
void rewrite_gitmodules(const char *workdir)
{
- git_buf in_f = GIT_BUF_INIT, out_f = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str in_f = GIT_STR_INIT, out_f = GIT_STR_INIT, path = GIT_STR_INIT;
FILE *in, *out;
char line[256];
- cl_git_pass(git_buf_joinpath(&in_f, workdir, "gitmodules"));
- cl_git_pass(git_buf_joinpath(&out_f, workdir, ".gitmodules"));
+ cl_git_pass(git_str_joinpath(&in_f, workdir, "gitmodules"));
+ cl_git_pass(git_str_joinpath(&out_f, workdir, ".gitmodules"));
cl_assert((in = fopen(in_f.ptr, "rb")) != NULL);
cl_assert((out = fopen(out_f.ptr, "wb")) != NULL);
@@ -32,16 +31,16 @@ void rewrite_gitmodules(const char *workdir)
scan += strlen("path =");
while (*scan == ' ') scan++;
- git_buf_joinpath(&path, workdir, scan);
- git_buf_rtrim(&path);
- git_buf_joinpath(&path, path.ptr, ".gitted");
+ git_str_joinpath(&path, workdir, scan);
+ git_str_rtrim(&path);
+ git_str_joinpath(&path, path.ptr, ".gitted");
- if (!git_buf_oom(&path) && p_access(path.ptr, F_OK) == 0) {
- git_buf_joinpath(&out_f, workdir, scan);
- git_buf_rtrim(&out_f);
- git_buf_joinpath(&out_f, out_f.ptr, ".git");
+ if (!git_str_oom(&path) && p_access(path.ptr, F_OK) == 0) {
+ git_str_joinpath(&out_f, workdir, scan);
+ git_str_rtrim(&out_f);
+ git_str_joinpath(&out_f, out_f.ptr, ".git");
- if (!git_buf_oom(&out_f))
+ if (!git_str_oom(&out_f))
p_rename(path.ptr, out_f.ptr);
}
}
@@ -57,18 +56,18 @@ void rewrite_gitmodules(const char *workdir)
while (*scan == ' ') scan++;
if (*scan == '.') {
- git_buf_joinpath(&path, workdir, scan);
- git_buf_rtrim(&path);
+ git_str_joinpath(&path, workdir, scan);
+ git_str_rtrim(&path);
} else if (!*scan || *scan == '\n') {
- git_buf_joinpath(&path, workdir, "../testrepo.git");
+ git_str_joinpath(&path, workdir, "../testrepo.git");
} else {
fputs(line, out);
continue;
}
git_path_prettify(&path, path.ptr, NULL);
- git_buf_putc(&path, '\n');
- cl_assert(!git_buf_oom(&path));
+ git_str_putc(&path, '\n');
+ cl_assert(!git_str_oom(&path));
fwrite(line, scan - line, sizeof(char), out);
fputs(path.ptr, out);
@@ -79,9 +78,9 @@ void rewrite_gitmodules(const char *workdir)
cl_must_pass(p_unlink(in_f.ptr));
- git_buf_dispose(&in_f);
- git_buf_dispose(&out_f);
- git_buf_dispose(&path);
+ git_str_dispose(&in_f);
+ git_str_dispose(&out_f);
+ git_str_dispose(&path);
}
static void cleanup_fixture_submodules(void *payload)
diff --git a/tests/valgrind-supp-mac.txt b/tests/valgrind-supp-mac.txt
index a104199e2..3298abee6 100644
--- a/tests/valgrind-supp-mac.txt
+++ b/tests/valgrind-supp-mac.txt
@@ -3,9 +3,9 @@
Memcheck:Leak
...
fun:git__realloc
- fun:git_buf_try_grow
- fun:git_buf_grow
- fun:git_buf_vprintf
+ fun:git_str_try_grow
+ fun:git_str_grow
+ fun:git_str_vprintf
fun:git_error_set
}
{
diff --git a/tests/win32/forbidden.c b/tests/win32/forbidden.c
index e02f41179..5c007987b 100644
--- a/tests/win32/forbidden.c
+++ b/tests/win32/forbidden.c
@@ -1,7 +1,6 @@
#include "clar_libgit2.h"
#include "repository.h"
-#include "buffer.h"
#include "submodule.h"
static const char *repo_name = "win32-forbidden";
diff --git a/tests/win32/longpath.c b/tests/win32/longpath.c
index f8b8c4b0a..4be86db5a 100644
--- a/tests/win32/longpath.c
+++ b/tests/win32/longpath.c
@@ -2,11 +2,10 @@
#include "git2/clone.h"
#include "clone.h"
-#include "buffer.h"
#include "futils.h"
#include "repository.h"
-static git_buf path = GIT_BUF_INIT;
+static git_str path = GIT_STR_INIT;
#define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"
@@ -18,20 +17,20 @@ void test_win32_longpath__initialize(void)
size_t remain = MAX_PATH - base_len;
size_t i;
- git_buf_clear(&path);
- git_buf_puts(&path, base);
- git_buf_putc(&path, '/');
+ git_str_clear(&path);
+ git_str_puts(&path, base);
+ git_str_putc(&path, '/');
cl_assert(remain < (MAX_PATH - 5));
for (i = 0; i < (remain - 5); i++)
- git_buf_putc(&path, 'a');
+ git_str_putc(&path, 'a');
#endif
}
void test_win32_longpath__cleanup(void)
{
- git_buf_dispose(&path);
+ git_str_dispose(&path);
cl_git_sandbox_cleanup();
}
@@ -49,7 +48,7 @@ void test_win32_longpath__workdir_path_validated(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("testrepo");
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
cl_git_pass(git_repository_workdir_path(&out, repo, "a.txt"));
@@ -60,7 +59,7 @@ void test_win32_longpath__workdir_path_validated(void)
cl_repo_set_bool(repo, "core.longpaths", true);
cl_git_pass(git_repository_workdir_path(&out, repo, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"));
cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
- git_buf_dispose(&out);
+ git_str_dispose(&out);
#endif
}
@@ -68,7 +67,7 @@ void test_win32_longpath__workdir_path_validated(void)
static void assert_longpath_status_and_add(git_repository *repo, const char *wddata, const char *repodata) {
git_index *index;
git_blob *blob;
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
const git_index_entry *entry;
unsigned int status_flags;
@@ -91,7 +90,7 @@ static void assert_longpath_status_and_add(git_repository *repo, const char *wdd
git_blob_free(blob);
git_index_free(index);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
#endif
diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c
index 2a1206032..8bb95d1f7 100644
--- a/tests/worktree/merge.c
+++ b/tests/worktree/merge.c
@@ -57,7 +57,7 @@ void test_worktree_merge__merge_setup(void)
{
git_reference *ours_ref, *theirs_ref;
git_annotated_commit *ours, *theirs;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned i;
cl_git_pass(git_reference_lookup(&ours_ref, fixture.worktree, MASTER_BRANCH));
@@ -70,13 +70,13 @@ void test_worktree_merge__merge_setup(void)
ours, (const git_annotated_commit **)&theirs, 1));
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir,
merge_files[i]));
cl_assert(git_path_exists(path.ptr));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_reference_free(ours_ref);
git_reference_free(theirs_ref);
git_annotated_commit_free(ours);
@@ -85,7 +85,7 @@ void test_worktree_merge__merge_setup(void)
void test_worktree_merge__merge_conflict(void)
{
- git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, buf = GIT_STR_INIT;
git_reference *theirs_ref;
git_annotated_commit *theirs;
git_index *index;
@@ -111,11 +111,11 @@ void test_worktree_merge__merge_conflict(void)
git_annotated_commit_free(theirs);
git_index_free(index);
- cl_git_pass(git_buf_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
+ cl_git_pass(git_str_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
cl_git_pass(git_futils_readbuffer(&buf, path.ptr));
cl_assert_equal_s(buf.ptr, CONFLICT_BRANCH_FILE_TXT);
- git_buf_dispose(&path);
- git_buf_dispose(&buf);
+ git_str_dispose(&path);
+ git_str_dispose(&buf);
}
diff --git a/tests/worktree/open.c b/tests/worktree/open.c
index 52d47334c..0c3fdc173 100644
--- a/tests/worktree/open.c
+++ b/tests/worktree/open.c
@@ -55,17 +55,17 @@ void test_worktree_open__repository_through_gitlink(void)
void test_worktree_open__repository_through_gitdir(void)
{
- git_buf gitdir_path = GIT_BUF_INIT;
+ git_str gitdir_path = GIT_STR_INIT;
git_repository *wt;
- cl_git_pass(git_buf_joinpath(&gitdir_path, COMMON_REPO, ".git"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, COMMON_REPO, ".git"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
cl_git_pass(git_repository_open(&wt, gitdir_path.ptr));
assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO);
- git_buf_dispose(&gitdir_path);
+ git_str_dispose(&gitdir_path);
git_repository_free(wt);
}
diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c
index 27dc667ea..5ae17ca19 100644
--- a/tests/worktree/refs.c
+++ b/tests/worktree/refs.c
@@ -177,9 +177,9 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
{
git_reference *head, *branch, *lookup;
git_commit *commit;
- git_buf refpath = GIT_BUF_INIT;
+ git_str refpath = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&refpath,
+ cl_git_pass(git_str_joinpath(&refpath,
git_repository_commondir(fixture.worktree), "refs/heads/testbranch"));
cl_assert(!git_path_exists(refpath.ptr));
@@ -194,5 +194,5 @@ void test_worktree_refs__creating_refs_uses_commondir(void)
git_reference_free(branch);
git_reference_free(head);
git_commit_free(commit);
- git_buf_dispose(&refpath);
+ git_str_dispose(&refpath);
}
diff --git a/tests/worktree/submodule.c b/tests/worktree/submodule.c
index 2e62c039c..4c6c657d3 100644
--- a/tests/worktree/submodule.c
+++ b/tests/worktree/submodule.c
@@ -61,14 +61,14 @@ void test_worktree_submodule__open_discovered_submodule_worktree(void)
void test_worktree_submodule__resolve_relative_url(void)
{
- git_buf wt_path = GIT_BUF_INIT;
+ git_str wt_path = GIT_STR_INIT;
git_buf sm_relative_path = GIT_BUF_INIT, wt_relative_path = GIT_BUF_INIT;
git_repository *repo;
git_worktree *wt;
cl_git_pass(git_futils_mkdir("subdir", 0755, GIT_MKDIR_PATH));
cl_git_pass(git_path_prettify_dir(&wt_path, "subdir", NULL));
- cl_git_pass(git_buf_joinpath(&wt_path, wt_path.ptr, "wt"));
+ cl_git_pass(git_str_joinpath(&wt_path, wt_path.ptr, "wt"));
/* Open child repository, which is a submodule */
cl_git_pass(git_repository_open(&child.repo, WORKTREE_CHILD));
@@ -86,7 +86,7 @@ void test_worktree_submodule__resolve_relative_url(void)
git_worktree_free(wt);
git_repository_free(repo);
- git_buf_dispose(&wt_path);
+ git_str_dispose(&wt_path);
git_buf_dispose(&sm_relative_path);
git_buf_dispose(&wt_relative_path);
}
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index 9b87bfae6..a9a50fbf1 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -40,11 +40,11 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
{ "gitdir", "HEAD" },
{ "HEAD", "commondir" },
};
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_strarray wts;
size_t i, j, len;
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/invalid"));
cl_git_pass(p_mkdir(path.ptr, 0755));
@@ -54,8 +54,8 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
for (i = 0; i < ARRAY_SIZE(filesets); i++) {
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
- git_buf_truncate(&path, len);
- cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
+ git_str_truncate(&path, len);
+ cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
cl_git_pass(p_close(p_creat(path.ptr, 0644)));
}
@@ -65,13 +65,13 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
git_strarray_dispose(&wts);
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
- git_buf_truncate(&path, len);
- cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
+ git_str_truncate(&path, len);
+ cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
p_unlink(path.ptr);
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_worktree_worktree__list_in_worktree_repo(void)
@@ -100,11 +100,11 @@ void test_worktree_worktree__list_without_worktrees(void)
void test_worktree_worktree__lookup(void)
{
git_worktree *wt;
- git_buf gitdir_path = GIT_BUF_INIT;
+ git_str gitdir_path = GIT_STR_INIT;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
- cl_git_pass(git_buf_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
+ cl_git_pass(git_str_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
cl_assert_equal_s(wt->parent_path, fixture.repo->workdir);
@@ -112,7 +112,7 @@ void test_worktree_worktree__lookup(void)
cl_assert_equal_s(wt->commondir_path, fixture.repo->gitdir);
cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
- git_buf_dispose(&gitdir_path);
+ git_str_dispose(&gitdir_path);
git_worktree_free(wt);
}
@@ -143,10 +143,10 @@ void test_worktree_worktree__open_invalid_commondir(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/commondir"));
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/commondir"));
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/commondir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
@@ -154,8 +154,8 @@ void test_worktree_worktree__open_invalid_commondir(void)
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -163,10 +163,10 @@ void test_worktree_worktree__open_invalid_gitdir(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
+ cl_git_pass(git_str_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
@@ -174,8 +174,8 @@ void test_worktree_worktree__open_invalid_gitdir(void)
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
- git_buf_dispose(&path);
+ git_str_dispose(&buf);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -183,16 +183,16 @@ void test_worktree_worktree__open_invalid_parent(void)
{
git_worktree *wt;
git_repository *repo;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
+ cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf,
fixture.worktree->gitlink, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_worktree_free(wt);
}
@@ -201,9 +201,9 @@ void test_worktree_worktree__init(void)
git_worktree *wt;
git_repository *repo;
git_reference *branch;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Open and verify created repo */
@@ -211,7 +211,7 @@ void test_worktree_worktree__init(void)
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-new/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-new", GIT_BRANCH_LOCAL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
@@ -222,12 +222,12 @@ void test_worktree_worktree__add_locked(void)
git_worktree *wt;
git_repository *repo;
git_reference *branch;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
opts.lock = 1;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-locked", path.ptr, &opts));
/* Open and verify created repo */
@@ -236,7 +236,7 @@ void test_worktree_worktree__add_locked(void)
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-locked/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-locked", GIT_BRANCH_LOCAL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
@@ -247,16 +247,16 @@ void test_worktree_worktree__init_existing_branch(void)
git_reference *head, *branch;
git_commit *commit;
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-new", commit, false));
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
@@ -268,7 +268,7 @@ void test_worktree_worktree__add_with_explicit_branch(void)
git_commit *commit;
git_worktree *wt;
git_repository *wtrepo;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
@@ -277,13 +277,13 @@ void test_worktree_worktree__add_with_explicit_branch(void)
opts.ref = branch;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-with-different-name", path.ptr, &opts));
cl_git_pass(git_repository_open_from_worktree(&wtrepo, wt));
cl_git_pass(git_repository_head(&wthead, wtrepo));
cl_assert_equal_s(git_reference_name(wthead), "refs/heads/worktree-with-ref");
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
@@ -296,15 +296,15 @@ void test_worktree_worktree__add_with_explicit_branch(void)
void test_worktree_worktree__init_existing_worktree(void)
{
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr, NULL));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(wt);
}
@@ -312,42 +312,42 @@ void test_worktree_worktree__init_existing_path(void)
{
const char *wtfiles[] = { "HEAD", "commondir", "gitdir", "index" };
git_worktree *wt;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned i;
/* Delete files to verify they have not been created by
* the init call */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_git_pass(p_unlink(path.ptr));
}
- cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Verify files have not been re-created */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
- cl_git_pass(git_buf_joinpath(&path,
+ cl_git_pass(git_str_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_assert(!git_path_exists(path.ptr));
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_worktree_worktree__init_submodule(void)
{
git_repository *repo, *sm, *wt;
git_worktree *worktree;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cleanup_fixture_worktree(&fixture);
repo = setup_fixture_submod2();
- cl_git_pass(git_buf_joinpath(&path, repo->workdir, "sm_unchanged"));
+ cl_git_pass(git_str_joinpath(&path, repo->workdir, "sm_unchanged"));
cl_git_pass(git_repository_open(&sm, path.ptr));
- cl_git_pass(git_buf_joinpath(&path, repo->workdir, "../worktree/"));
+ cl_git_pass(git_str_joinpath(&path, repo->workdir, "../worktree/"));
cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
@@ -356,10 +356,10 @@ void test_worktree_worktree__init_submodule(void)
cl_git_pass(git_path_prettify_dir(&path, sm->commondir, NULL));
cl_assert_equal_s(sm->commondir, wt->commondir);
- cl_git_pass(git_buf_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
+ cl_git_pass(git_str_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
cl_assert_equal_s(path.ptr, wt->gitdir);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
git_worktree_free(worktree);
git_repository_free(sm);
git_repository_free(wt);
@@ -388,13 +388,13 @@ void test_worktree_worktree__name(void)
void test_worktree_worktree__path(void)
{
git_worktree *wt;
- git_buf expected_path = GIT_BUF_INIT;
+ git_str expected_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
+ cl_git_pass(git_str_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(git_worktree_path(wt), expected_path.ptr);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&expected_path);
git_worktree_free(wt);
}