diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-27 22:18:27 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-29 11:33:58 +0100 |
commit | 375c1cec10aa6cbb39eaf3b37293280ee305adf9 (patch) | |
tree | a172fba82cd1fc4df41d62a966b03a15b1fbb1d7 | |
parent | ca92646688fae0e44bb82a8a27c804aa6c328c2a (diff) | |
download | libgit2-375c1cec10aa6cbb39eaf3b37293280ee305adf9.tar.gz |
settings: user-facing functions write to a userbuf
-rw-r--r-- | include/git2/common.h | 4 | ||||
-rw-r--r-- | src/settings.c | 13 | ||||
-rw-r--r-- | tests/checkout/index.c | 4 | ||||
-rw-r--r-- | tests/clar_libgit2.c | 14 | ||||
-rw-r--r-- | tests/core/env.c | 16 | ||||
-rw-r--r-- | tests/filter/systemattrs.c | 8 | ||||
-rw-r--r-- | tests/repo/init.c | 4 |
7 files changed, 35 insertions, 28 deletions
diff --git a/include/git2/common.h b/include/git2/common.h index d6696061d..685b7a378 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -230,7 +230,7 @@ typedef enum { * >Set the maximum amount of memory that can be mapped at any time * by the library * - * * opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf) + * * opts(GIT_OPT_GET_SEARCH_PATH, int level, git_userbuf *buf) * * > Get the search path for a given level of config data. "level" must * > be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`, @@ -280,7 +280,7 @@ typedef enum { * > Get the current bytes in cache and the maximum that would be * > allowed in the cache. * - * * opts(GIT_OPT_GET_TEMPLATE_PATH, git_buf *out) + * * opts(GIT_OPT_GET_TEMPLATE_PATH, git_userbuf *out) * * > Get the default template path. * > The path is written to the `out` buffer. diff --git a/src/settings.c b/src/settings.c index f9f6b8497..65fd32ba2 100644 --- a/src/settings.c +++ b/src/settings.c @@ -24,6 +24,7 @@ #include "odb.h" #include "refs.h" #include "index.h" +#include "userbuf.h" #include "transports/smart.h" #include "transports/http.h" #include "streams/openssl.h" @@ -126,14 +127,14 @@ int git_libgit2_opts(int key, ...) case GIT_OPT_GET_SEARCH_PATH: if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0) { - git_buf *out = va_arg(ap, git_buf *); + git_userbuf *out = va_arg(ap, git_userbuf *); const git_buf *tmp; - git_buf_sanitize(out); + git_userbuf_sanitize(out); if ((error = git_sysdir_get(&tmp, error)) < 0) break; - error = git_buf_sets(out, tmp->ptr); + error = git_buf_sets((git_buf *)out, tmp->ptr); } break; @@ -165,14 +166,14 @@ int git_libgit2_opts(int key, ...) case GIT_OPT_GET_TEMPLATE_PATH: { - git_buf *out = va_arg(ap, git_buf *); + git_userbuf *out = va_arg(ap, git_userbuf *); const git_buf *tmp; - git_buf_sanitize(out); + git_userbuf_sanitize(out); if ((error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0) break; - error = git_buf_sets(out, tmp->ptr); + error = git_buf_sets((git_buf *)out, tmp->ptr); } break; diff --git a/tests/checkout/index.c b/tests/checkout/index.c index 508975365..c5efbfb57 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_userbuf g_global_path = GIT_USERBUF_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_userbuf_dispose(&g_global_path); cl_git_sandbox_cleanup(); diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c index 4e4675fea..f588bf493 100644 --- a/tests/clar_libgit2.c +++ b/tests/clar_libgit2.c @@ -564,20 +564,20 @@ void cl_fake_home_cleanup(void *payload) void cl_fake_home(void) { - git_buf path = GIT_BUF_INIT; + git_userbuf restore = GIT_USERBUF_INIT; + git_buf home = GIT_BUF_INIT; cl_git_pass(git_libgit2_opts( - GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &path)); - - _cl_restore_home = git_buf_detach(&path); + GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &restore)); + _cl_restore_home = restore.ptr; cl_set_cleanup(cl_fake_home_cleanup, NULL); if (!git_path_exists("home")) cl_must_pass(p_mkdir("home", 0777)); - cl_git_pass(git_path_prettify(&path, "home", NULL)); + cl_git_pass(git_path_prettify(&home, "home", NULL)); cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); - git_buf_dispose(&path); + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home.ptr)); + git_buf_dispose(&home); } void cl_sandbox_set_search_path_defaults(void) diff --git a/tests/core/env.c b/tests/core/env.c index 3c34b2c4d..2f9731c0d 100644 --- a/tests/core/env.c +++ b/tests/core/env.c @@ -212,7 +212,7 @@ void test_core_env__1(void) static void check_global_searchpath( const char *path, int position, const char *file, git_buf *temp) { - git_buf out = GIT_BUF_INIT; + git_userbuf out = GIT_BUF_INIT; /* build and set new path */ if (position < 0) @@ -245,7 +245,7 @@ static void check_global_searchpath( cl_assert_equal_i( GIT_ENOTFOUND, git_sysdir_find_global_file(temp, file)); - git_buf_dispose(&out); + git_userbuf_dispose(&out); } void test_core_env__2(void) @@ -301,21 +301,23 @@ void test_core_env__2(void) void test_core_env__substitution(void) { - git_buf buf = GIT_BUF_INIT, expected = GIT_BUF_INIT; + git_userbuf buf = GIT_USERBUF_INIT; + git_buf joined = GIT_BUF_INIT, expected = GIT_BUF_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_userbuf_dispose(&buf); - git_buf_clear(&buf); - cl_git_pass(git_buf_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_buf_join(&joined, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b")); + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, joined.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_assert_equal_s(expected.ptr, buf.ptr); + git_buf_dispose(&joined); git_buf_dispose(&expected); - git_buf_dispose(&buf); + git_userbuf_dispose(&buf); } diff --git a/tests/filter/systemattrs.c b/tests/filter/systemattrs.c index 1e2aec650..66e2f758a 100644 --- a/tests/filter/systemattrs.c +++ b/tests/filter/systemattrs.c @@ -7,19 +7,23 @@ static git_buf system_attr_path = GIT_BUF_INIT; void test_filter_systemattrs__initialize(void) { + git_userbuf system_path = GIT_USERBUF_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)); + GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_path)); cl_git_pass(git_buf_joinpath(&system_attr_path, - system_attr_path.ptr, "gitattributes")); + 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_userbuf_dispose(&system_path); } void test_filter_systemattrs__cleanup(void) diff --git a/tests/repo/init.c b/tests/repo/init.c index 5a95229e6..f5c06b055 100644 --- a/tests/repo/init.c +++ b/tests/repo/init.c @@ -12,7 +12,7 @@ enum repo_mode { }; static git_repository *_repo = NULL; -static git_buf _global_path = GIT_BUF_INIT; +static git_userbuf _global_path = GIT_USERBUF_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, _global_path.ptr); - git_buf_dispose(&_global_path); + git_userbuf_dispose(&_global_path); cl_fixture_cleanup("tmp_global_path"); } |