Commit 9bc8c80f by Edward Thomson

odb: actually insert the empty blob in tests

parent becadafc
...@@ -2,105 +2,103 @@ ...@@ -2,105 +2,103 @@
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/index.h" #include "git2/index.h"
git_repository *repo = NULL; static git_repository *g_repo;
static git_odb *g_odb;
static git_index *g_index;
static git_oid g_empty_id;
void test_index_collision__initialize(void)
{
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_repository_odb(&g_odb, g_repo));
cl_git_pass(git_repository_index(&g_index, g_repo));
cl_git_pass(git_odb_write(&g_empty_id, g_odb, "", 0, GIT_OBJ_BLOB));
}
void test_index_collision__cleanup(void) void test_index_collision__cleanup(void)
{ {
git_index_free(g_index);
git_odb_free(g_odb);
cl_git_sandbox_cleanup(); cl_git_sandbox_cleanup();
repo = NULL;
} }
void test_index_collision__add(void) void test_index_collision__add(void)
{ {
git_index *index;
git_index_entry entry; git_index_entry entry;
git_oid tree_id; git_oid tree_id;
git_tree *tree; git_tree *tree;
repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_repository_index(&index, repo));
memset(&entry, 0, sizeof(entry)); memset(&entry, 0, sizeof(entry));
entry.ctime.seconds = 12346789; entry.ctime.seconds = 12346789;
entry.mtime.seconds = 12346789; entry.mtime.seconds = 12346789;
entry.mode = 0100644; entry.mode = 0100644;
entry.file_size = 0; entry.file_size = 0;
git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); git_oid_cpy(&entry.id, &g_empty_id);
entry.path = "a/b"; entry.path = "a/b";
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
/* create a tree/blob collision */ /* create a tree/blob collision */
entry.path = "a/b/c"; entry.path = "a/b/c";
cl_git_fail(git_index_add(index, &entry)); cl_git_fail(git_index_add(g_index, &entry));
cl_git_pass(git_index_write_tree(&tree_id, index)); cl_git_pass(git_index_write_tree(&tree_id, g_index));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_id)); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
git_tree_free(tree); git_tree_free(tree);
git_index_free(index);
} }
void test_index_collision__add_with_highstage_1(void) void test_index_collision__add_with_highstage_1(void)
{ {
git_index *index;
git_index_entry entry; git_index_entry entry;
repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_repository_index(&index, repo));
memset(&entry, 0, sizeof(entry)); memset(&entry, 0, sizeof(entry));
entry.ctime.seconds = 12346789; entry.ctime.seconds = 12346789;
entry.mtime.seconds = 12346789; entry.mtime.seconds = 12346789;
entry.mode = 0100644; entry.mode = 0100644;
entry.file_size = 0; entry.file_size = 0;
git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); git_oid_cpy(&entry.id, &g_empty_id);
entry.path = "a/b"; entry.path = "a/b";
GIT_IDXENTRY_STAGE_SET(&entry, 2); GIT_IDXENTRY_STAGE_SET(&entry, 2);
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
/* create a blob beneath the previous tree entry */ /* create a blob beneath the previous tree entry */
entry.path = "a/b/c"; entry.path = "a/b/c";
entry.flags = 0; entry.flags = 0;
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
/* create another tree entry above the blob */ /* create another tree entry above the blob */
entry.path = "a/b"; entry.path = "a/b";
GIT_IDXENTRY_STAGE_SET(&entry, 1); GIT_IDXENTRY_STAGE_SET(&entry, 1);
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
git_index_free(index);
} }
void test_index_collision__add_with_highstage_2(void) void test_index_collision__add_with_highstage_2(void)
{ {
git_index *index;
git_index_entry entry; git_index_entry entry;
repo = cl_git_sandbox_init("empty_standard_repo"); cl_git_pass(git_repository_index(&g_index, g_repo));
cl_git_pass(git_repository_index(&index, repo));
memset(&entry, 0, sizeof(entry)); memset(&entry, 0, sizeof(entry));
entry.ctime.seconds = 12346789; entry.ctime.seconds = 12346789;
entry.mtime.seconds = 12346789; entry.mtime.seconds = 12346789;
entry.mode = 0100644; entry.mode = 0100644;
entry.file_size = 0; entry.file_size = 0;
git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); git_oid_cpy(&entry.id, &g_empty_id);
entry.path = "a/b/c"; entry.path = "a/b/c";
GIT_IDXENTRY_STAGE_SET(&entry, 1); GIT_IDXENTRY_STAGE_SET(&entry, 1);
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
/* create a blob beneath the previous tree entry */ /* create a blob beneath the previous tree entry */
entry.path = "a/b/c"; entry.path = "a/b/c";
GIT_IDXENTRY_STAGE_SET(&entry, 2); GIT_IDXENTRY_STAGE_SET(&entry, 2);
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
/* create another tree entry above the blob */ /* create another tree entry above the blob */
entry.path = "a/b"; entry.path = "a/b";
GIT_IDXENTRY_STAGE_SET(&entry, 3); GIT_IDXENTRY_STAGE_SET(&entry, 3);
cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_add(g_index, &entry));
git_index_free(index);
} }
...@@ -240,14 +240,18 @@ void test_reset_hard__switch_file_to_dir(void) ...@@ -240,14 +240,18 @@ void test_reset_hard__switch_file_to_dir(void)
{ {
git_index_entry entry = {{ 0 }}; git_index_entry entry = {{ 0 }};
git_index *idx; git_index *idx;
git_odb *odb;
git_object *commit; git_object *commit;
git_tree *tree; git_tree *tree;
git_signature *sig; git_signature *sig;
git_oid src_tree_id, tgt_tree_id; git_oid src_tree_id, tgt_tree_id;
git_oid src_id, tgt_id; git_oid src_id, tgt_id;
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_write(&entry.id, odb, "", 0, GIT_OBJ_BLOB));
git_odb_free(odb);
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
cl_git_pass(git_index_new(&idx)); cl_git_pass(git_index_new(&idx));
cl_git_pass(git_signature_now(&sig, "foo", "bar")); cl_git_pass(git_signature_now(&sig, "foo", "bar"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment