|
Packit Service |
20376f |
#include "clar_libgit2.h"
|
|
Packit Service |
20376f |
#include "odb.h"
|
|
Packit Service |
20376f |
#include "filebuf.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
static git_buf destpath, filepath;
|
|
Packit Service |
20376f |
static const char *paths[] = {
|
|
Packit Service |
20376f |
"A.git", "B.git", "C.git", "D.git", "E.git", "F.git", "G.git"
|
|
Packit Service |
20376f |
};
|
|
Packit Service |
20376f |
static git_filebuf file;
|
|
Packit Service |
20376f |
static git_repository *repo;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void test_odb_alternates__cleanup(void)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
size_t i;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_buf_free(&destpath);
|
|
Packit Service |
20376f |
git_buf_free(&filepath);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
for (i = 0; i < ARRAY_SIZE(paths); i++)
|
|
Packit Service |
20376f |
cl_fixture_cleanup(paths[i]);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
static void init_linked_repo(const char *path, const char *alternate)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_buf_clear(&destpath);
|
|
Packit Service |
20376f |
git_buf_clear(&filepath);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
cl_git_pass(git_repository_init(&repo, path, 1));
|
|
Packit Service |
20376f |
cl_git_pass(git_path_prettify(&destpath, alternate, NULL));
|
|
Packit Service |
20376f |
cl_git_pass(git_buf_joinpath(&destpath, destpath.ptr, "objects"));
|
|
Packit Service |
20376f |
cl_git_pass(git_buf_joinpath(&filepath, git_repository_path(repo), "objects/info"));
|
|
Packit Service |
20376f |
cl_git_pass(git_futils_mkdir(filepath.ptr, 0755, GIT_MKDIR_PATH));
|
|
Packit Service |
20376f |
cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0, 0666));
|
|
Packit Service |
20376f |
git_filebuf_printf(&file, "%s\n", git_buf_cstr(&destpath));
|
|
Packit Service |
20376f |
cl_git_pass(git_filebuf_commit(&file));
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_repository_free(repo);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void test_odb_alternates__chained(void)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_commit *commit;
|
|
Packit Service |
20376f |
git_oid oid;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Set the alternate A -> testrepo.git */
|
|
Packit Service |
20376f |
init_linked_repo(paths[0], cl_fixture("testrepo.git"));
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Set the alternate B -> A */
|
|
Packit Service |
20376f |
init_linked_repo(paths[1], paths[0]);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Now load B and see if we can find an object from testrepo.git */
|
|
Packit Service |
20376f |
cl_git_pass(git_repository_open(&repo, paths[1]));
|
|
Packit Service |
20376f |
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
|
|
Packit Service |
20376f |
cl_git_pass(git_commit_lookup(&commit, repo, &oid));
|
|
Packit Service |
20376f |
git_commit_free(commit);
|
|
Packit Service |
20376f |
git_repository_free(repo);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void test_odb_alternates__long_chain(void)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_commit *commit;
|
|
Packit Service |
20376f |
git_oid oid;
|
|
Packit Service |
20376f |
size_t i;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Set the alternate A -> testrepo.git */
|
|
Packit Service |
20376f |
init_linked_repo(paths[0], cl_fixture("testrepo.git"));
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Set up the five-element chain */
|
|
Packit Service |
20376f |
for (i = 1; i < ARRAY_SIZE(paths); i++) {
|
|
Packit Service |
20376f |
init_linked_repo(paths[i], paths[i-1]);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Now load the last one and see if we can find an object from testrepo.git */
|
|
Packit Service |
20376f |
cl_git_pass(git_repository_open(&repo, paths[ARRAY_SIZE(paths)-1]));
|
|
Packit Service |
20376f |
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
|
|
Packit Service |
20376f |
cl_git_fail(git_commit_lookup(&commit, repo, &oid));
|
|
Packit Service |
20376f |
git_repository_free(repo);
|
|
Packit Service |
20376f |
}
|