Hash :
114f5a6c
Author :
Date :
2013-06-10T10:10:39
Reorganize diff and add basic diff driver This is a significant reorganization of the diff code to break it into a set of more clearly distinct files and to document the new organization. Hopefully this will make the diff code easier to understand and to extend. This adds a new `git_diff_driver` object that looks of diff driver information from the attributes and the config so that things like function content in diff headers can be provided. The full driver spec is not implemented in the commit - this is focused on the reorganization of the code and putting the driver hooks in place. This also removes a few #includes from src/repository.h that were overbroad, but as a result required extra #includes in a variety of places since including src/repository.h no longer results in pulling in the whole world.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#include "clar_libgit2.h"
#include "odb.h"
#include "filebuf.h"
static git_buf destpath, filepath;
static const char *paths[] = {
"A.git", "B.git", "C.git", "D.git", "E.git", "F.git", "G.git"
};
static git_filebuf file;
static git_repository *repo;
void test_odb_alternates__cleanup(void)
{
size_t i;
git_buf_free(&destpath);
git_buf_free(&filepath);
for (i = 0; i < ARRAY_SIZE(paths); i++)
cl_fixture_cleanup(paths[i]);
}
static void init_linked_repo(const char *path, const char *alternate)
{
git_buf_clear(&destpath);
git_buf_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_futils_mkdir(filepath.ptr, NULL, 0755, GIT_MKDIR_PATH));
cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0));
git_filebuf_printf(&file, "%s\n", git_buf_cstr(&destpath));
cl_git_pass(git_filebuf_commit(&file, 0644));
git_repository_free(repo);
}
void test_odb_alternates__chained(void)
{
git_commit *commit;
git_oid oid;
/* Set the alternate A -> testrepo.git */
init_linked_repo(paths[0], cl_fixture("testrepo.git"));
/* Set the alternate B -> A */
init_linked_repo(paths[1], paths[0]);
/* Now load B and see if we can find an object from testrepo.git */
cl_git_pass(git_repository_open(&repo, paths[1]));
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_git_pass(git_commit_lookup(&commit, repo, &oid));
git_commit_free(commit);
git_repository_free(repo);
}
void test_odb_alternates__long_chain(void)
{
git_commit *commit;
git_oid oid;
size_t i;
/* Set the alternate A -> testrepo.git */
init_linked_repo(paths[0], cl_fixture("testrepo.git"));
/* Set up the five-element chain */
for (i = 1; i < ARRAY_SIZE(paths); i++) {
init_linked_repo(paths[i], paths[i-1]);
}
/* Now load the last one and see if we can find an object from testrepo.git */
cl_git_pass(git_repository_open(&repo, paths[ARRAY_SIZE(paths)-1]));
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_git_fail(git_commit_lookup(&commit, repo, &oid));
git_repository_free(repo);
}