mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-04 15:20:50 +00:00

It turns out that commit 31e9cfc4cbcaf1b38cdd3dbe3282a8f57e5366a5 did not fix the GIT_USUSED behavior on all platforms. This commit walks through and really cleans things up more thoroughly, getting rid of the unnecessary stuff. To remove the use of some GIT_UNUSED, I ended up adding a couple of new iterators for hashtables that allow you to iterator just over keys or just over values. In making this change, I found a bug in the clar tests (where we were doing *count++ but meant to do (*count)++ to increment the value). I fixed that but then found the test failing because it was not really using an empty repo. So, I took some of the code that I wrote for iterator testing and moved it to clar_helpers.c, then made use of that to make it easier to open fixtures on a per test basis even within a single test file.
91 lines
2.1 KiB
C
91 lines
2.1 KiB
C
#include "clar_libgit2.h"
|
|
#include "posix.h"
|
|
|
|
void clar_on_init(void)
|
|
{
|
|
git_threads_init();
|
|
}
|
|
|
|
void clar_on_shutdown(void)
|
|
{
|
|
git_threads_shutdown();
|
|
}
|
|
|
|
void cl_git_mkfile(const char *filename, const char *content)
|
|
{
|
|
int fd;
|
|
|
|
fd = p_creat(filename, 0666);
|
|
cl_assert(fd != 0);
|
|
|
|
if (content) {
|
|
cl_must_pass(p_write(fd, content, strlen(content)));
|
|
} else {
|
|
cl_must_pass(p_write(fd, filename, strlen(filename)));
|
|
cl_must_pass(p_write(fd, "\n", 1));
|
|
}
|
|
|
|
cl_must_pass(p_close(fd));
|
|
}
|
|
|
|
void cl_git_append2file(const char *filename, const char *new_content)
|
|
{
|
|
int fd = p_open(filename, O_WRONLY | O_APPEND | O_CREAT);
|
|
cl_assert(fd != 0);
|
|
if (!new_content)
|
|
new_content = "\n";
|
|
cl_must_pass(p_write(fd, new_content, strlen(new_content)));
|
|
cl_must_pass(p_close(fd));
|
|
cl_must_pass(p_chmod(filename, 0644));
|
|
}
|
|
|
|
static const char *_cl_sandbox = NULL;
|
|
static git_repository *_cl_repo = NULL;
|
|
|
|
git_repository *cl_git_sandbox_init(const char *sandbox)
|
|
{
|
|
/* Copy the whole sandbox folder from our fixtures to our test sandbox
|
|
* area. After this it can be accessed with `./sandbox`
|
|
*/
|
|
cl_fixture_sandbox(sandbox);
|
|
_cl_sandbox = sandbox;
|
|
|
|
p_chdir(sandbox);
|
|
|
|
/* Rename `sandbox/.gitted` to `sandbox/.git` which must be done since
|
|
* we cannot store a folder named `.git` inside the fixtures folder of
|
|
* our libgit2 repo.
|
|
*/
|
|
cl_git_pass(p_rename(".gitted", ".git"));
|
|
|
|
/* If we have `gitattributes`, rename to `.gitattributes`. This may
|
|
* be necessary if we don't want the attributes to be applied in the
|
|
* libgit2 repo, but just during testing.
|
|
*/
|
|
if (p_access("gitattributes", F_OK) == 0)
|
|
cl_git_pass(p_rename("gitattributes", ".gitattributes"));
|
|
|
|
/* As with `gitattributes`, we may need `gitignore` just for testing. */
|
|
if (p_access("gitignore", F_OK) == 0)
|
|
cl_git_pass(p_rename("gitignore", ".gitignore"));
|
|
|
|
p_chdir("..");
|
|
|
|
/* Now open the sandbox repository and make it available for tests */
|
|
cl_git_pass(git_repository_open(&_cl_repo, sandbox));
|
|
|
|
return _cl_repo;
|
|
}
|
|
|
|
void cl_git_sandbox_cleanup(void)
|
|
{
|
|
if (_cl_repo) {
|
|
git_repository_free(_cl_repo);
|
|
_cl_repo = NULL;
|
|
}
|
|
if (_cl_sandbox) {
|
|
cl_fixture_cleanup(_cl_sandbox);
|
|
_cl_sandbox = NULL;
|
|
}
|
|
}
|