summaryrefslogtreecommitdiff
path: root/tests-clay/repo
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-11-30 11:27:15 -0800
committerRussell Belfer <arrbee@arrbee.com>2011-12-07 23:08:15 -0800
commit97769280ba9938ae27f6e06cbd0d5e8a768a86b9 (patch)
tree4fe43e99acb55f904f6b586bd7c5158610f9512f /tests-clay/repo
parenta22b14d32dd8d5f06f121aa154d45bac3b10a305 (diff)
downloadlibgit2-97769280ba9938ae27f6e06cbd0d5e8a768a86b9.tar.gz
Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX buffers on the stack for manipulating paths to use git_buf objects instead. The patch is pretty careful not to touch the public API for libgit2, so there are a few places that still use GIT_PATH_MAX. This extends and changes some details of the git_buf implementation to add a couple of extra functions and to make error handling easier. This includes serious alterations to all the path.c functions, and several of the fileops.c ones, too. Also, there are a number of new functions that parallel existing ones except that use a git_buf instead of a stack-based buffer (such as git_config_find_global_r that exists alongsize git_config_find_global). This also modifies the win32 version of p_realpath to allocate whatever buffer size is needed to accommodate the realpath instead of hardcoding a GIT_PATH_MAX limit, but that change needs to be tested still.
Diffstat (limited to 'tests-clay/repo')
-rw-r--r--tests-clay/repo/init.c10
-rw-r--r--tests-clay/repo/open.c17
2 files changed, 15 insertions, 12 deletions
diff --git a/tests-clay/repo/init.c b/tests-clay/repo/init.c
index 9677541ed..e235ffaeb 100644
--- a/tests-clay/repo/init.c
+++ b/tests-clay/repo/init.c
@@ -77,17 +77,19 @@ void test_repo_init__bare_repo_noslash(void)
#if 0
BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory")
- char path_repository[GIT_PATH_MAX];
+ git_buf path_repository = GIT_BUF_INIT;
char current_workdir[GIT_PATH_MAX];
const mode_t mode = 0777;
git_repository* repo;
must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
- git_path_join(path_repository, TEMP_REPO_FOLDER, "a/b/c/");
- must_pass(git_futils_mkdir_r(path_repository, mode));
+ must_pass(git_buf_joinpath(&path_repository, TEMP_REPO_FOLDER, "a/b/c/"));
+ must_pass(git_futils_mkdir_r(path_repository.ptr, mode));
- must_pass(chdir(path_repository));
+ must_pass(chdir(path_repository.ptr));
+
+ git_buf_free(&path_repository);
must_pass(git_repository_init(&repo, "../d/e.git", 1));
must_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/"));
diff --git a/tests-clay/repo/open.c b/tests-clay/repo/open.c
index 235af1447..05b01ceb2 100644
--- a/tests-clay/repo/open.c
+++ b/tests-clay/repo/open.c
@@ -26,23 +26,24 @@ void test_repo_open__standard_empty_repo(void)
/* TODO TODO */
#if 0
BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of the current working directory")
- char new_current_workdir[GIT_PATH_MAX];
char current_workdir[GIT_PATH_MAX];
- char path_repository[GIT_PATH_MAX];
+ git_buf new_current_workdir = GIT_BUF_INIT;
+ git_buf path_repository = GIT_BUF_INIT;
const mode_t mode = 0777;
git_repository* repo;
/* Setup the repository to open */
must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
- strcpy(path_repository, current_workdir);
- git_path_join_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git");
- must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository));
+ must_pass(git_buf_join_n(&path_repository, 3, current_workdir, TEMP_REPO_FOLDER, "a/d/e.git"));
+ must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository.ptr));
+ git_buf_free(&path_repository);
/* Change the current working directory */
- git_path_join(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/");
- must_pass(git_futils_mkdir_r(new_current_workdir, mode));
- must_pass(chdir(new_current_workdir));
+ must_pass(git_buf_joinpath(&new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/"));
+ must_pass(git_futils_mkdir_r(new_current_workdir.ptr, mode));
+ must_pass(chdir(new_current_workdir.ptr));
+ git_buf_free(&new_current_workdir);
must_pass(git_repository_open(&repo, "../../d/e.git"));