Skip to content

Commit 9bc8c80

Browse files
author
Edward Thomson
committed
odb: actually insert the empty blob in tests
1 parent becadaf commit 9bc8c80

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

tests/index/collision.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,105 +2,103 @@
22
#include "git2/repository.h"
33
#include "git2/index.h"
44

5-
git_repository *repo = NULL;
5+
static git_repository *g_repo;
6+
static git_odb *g_odb;
7+
static git_index *g_index;
8+
static git_oid g_empty_id;
9+
10+
void test_index_collision__initialize(void)
11+
{
12+
g_repo = cl_git_sandbox_init("empty_standard_repo");
13+
cl_git_pass(git_repository_odb(&g_odb, g_repo));
14+
cl_git_pass(git_repository_index(&g_index, g_repo));
15+
16+
cl_git_pass(git_odb_write(&g_empty_id, g_odb, "", 0, GIT_OBJ_BLOB));
17+
}
618

719
void test_index_collision__cleanup(void)
820
{
21+
git_index_free(g_index);
22+
git_odb_free(g_odb);
923
cl_git_sandbox_cleanup();
10-
repo = NULL;
1124
}
1225

1326
void test_index_collision__add(void)
1427
{
15-
git_index *index;
1628
git_index_entry entry;
1729
git_oid tree_id;
1830
git_tree *tree;
1931

20-
repo = cl_git_sandbox_init("empty_standard_repo");
21-
cl_git_pass(git_repository_index(&index, repo));
22-
2332
memset(&entry, 0, sizeof(entry));
2433
entry.ctime.seconds = 12346789;
2534
entry.mtime.seconds = 12346789;
2635
entry.mode = 0100644;
2736
entry.file_size = 0;
28-
git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
37+
git_oid_cpy(&entry.id, &g_empty_id);
2938

3039
entry.path = "a/b";
31-
cl_git_pass(git_index_add(index, &entry));
40+
cl_git_pass(git_index_add(g_index, &entry));
3241

3342
/* create a tree/blob collision */
3443
entry.path = "a/b/c";
35-
cl_git_fail(git_index_add(index, &entry));
44+
cl_git_fail(git_index_add(g_index, &entry));
3645

37-
cl_git_pass(git_index_write_tree(&tree_id, index));
38-
cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));
46+
cl_git_pass(git_index_write_tree(&tree_id, g_index));
47+
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
3948

4049
git_tree_free(tree);
41-
git_index_free(index);
4250
}
4351

4452
void test_index_collision__add_with_highstage_1(void)
4553
{
46-
git_index *index;
4754
git_index_entry entry;
4855

49-
repo = cl_git_sandbox_init("empty_standard_repo");
50-
cl_git_pass(git_repository_index(&index, repo));
51-
5256
memset(&entry, 0, sizeof(entry));
5357
entry.ctime.seconds = 12346789;
5458
entry.mtime.seconds = 12346789;
5559
entry.mode = 0100644;
5660
entry.file_size = 0;
57-
git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
61+
git_oid_cpy(&entry.id, &g_empty_id);
5862

5963
entry.path = "a/b";
6064
GIT_IDXENTRY_STAGE_SET(&entry, 2);
61-
cl_git_pass(git_index_add(index, &entry));
65+
cl_git_pass(git_index_add(g_index, &entry));
6266

6367
/* create a blob beneath the previous tree entry */
6468
entry.path = "a/b/c";
6569
entry.flags = 0;
66-
cl_git_pass(git_index_add(index, &entry));
70+
cl_git_pass(git_index_add(g_index, &entry));
6771

6872
/* create another tree entry above the blob */
6973
entry.path = "a/b";
7074
GIT_IDXENTRY_STAGE_SET(&entry, 1);
71-
cl_git_pass(git_index_add(index, &entry));
72-
73-
git_index_free(index);
75+
cl_git_pass(git_index_add(g_index, &entry));
7476
}
7577

7678
void test_index_collision__add_with_highstage_2(void)
7779
{
78-
git_index *index;
7980
git_index_entry entry;
8081

81-
repo = cl_git_sandbox_init("empty_standard_repo");
82-
cl_git_pass(git_repository_index(&index, repo));
82+
cl_git_pass(git_repository_index(&g_index, g_repo));
8383

8484
memset(&entry, 0, sizeof(entry));
8585
entry.ctime.seconds = 12346789;
8686
entry.mtime.seconds = 12346789;
8787
entry.mode = 0100644;
8888
entry.file_size = 0;
89-
git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
89+
git_oid_cpy(&entry.id, &g_empty_id);
9090

9191
entry.path = "a/b/c";
9292
GIT_IDXENTRY_STAGE_SET(&entry, 1);
93-
cl_git_pass(git_index_add(index, &entry));
93+
cl_git_pass(git_index_add(g_index, &entry));
9494

9595
/* create a blob beneath the previous tree entry */
9696
entry.path = "a/b/c";
9797
GIT_IDXENTRY_STAGE_SET(&entry, 2);
98-
cl_git_pass(git_index_add(index, &entry));
98+
cl_git_pass(git_index_add(g_index, &entry));
9999

100100
/* create another tree entry above the blob */
101101
entry.path = "a/b";
102102
GIT_IDXENTRY_STAGE_SET(&entry, 3);
103-
cl_git_pass(git_index_add(index, &entry));
104-
105-
git_index_free(index);
103+
cl_git_pass(git_index_add(g_index, &entry));
106104
}

tests/reset/hard.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,18 @@ void test_reset_hard__switch_file_to_dir(void)
240240
{
241241
git_index_entry entry = {{ 0 }};
242242
git_index *idx;
243+
git_odb *odb;
243244
git_object *commit;
244245
git_tree *tree;
245246
git_signature *sig;
246247
git_oid src_tree_id, tgt_tree_id;
247248
git_oid src_id, tgt_id;
248249

250+
cl_git_pass(git_repository_odb(&odb, repo));
251+
cl_git_pass(git_odb_write(&entry.id, odb, "", 0, GIT_OBJ_BLOB));
252+
git_odb_free(odb);
253+
249254
entry.mode = GIT_FILEMODE_BLOB;
250-
cl_git_pass(git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
251255
cl_git_pass(git_index_new(&idx));
252256
cl_git_pass(git_signature_now(&sig, "foo", "bar"));
253257

0 commit comments

Comments
 (0)