]>
git.proxmox.com Git - libgit2.git/blob - tests/odb/foreach.c
1 #include "clar_libgit2.h"
3 #include "git2/odb_backend.h"
8 static git_repository
*_repo
;
10 void test_odb_foreach__cleanup(void)
13 git_repository_free(_repo
);
19 static int foreach_cb(const git_oid
*oid
, void *data
)
30 * $ git --git-dir tests/resources/testrepo.git count-objects --verbose
39 void test_odb_foreach__foreach(void)
43 cl_git_pass(git_repository_open(&_repo
, cl_fixture("testrepo.git")));
44 git_repository_odb(&_odb
, _repo
);
46 cl_git_pass(git_odb_foreach(_odb
, foreach_cb
, &nobj
));
47 cl_assert_equal_i(47 + 1640, nobj
); /* count + in-pack */
50 void test_odb_foreach__one_pack(void)
52 git_odb_backend
*backend
= NULL
;
55 cl_git_pass(git_odb_new(&_odb
));
56 cl_git_pass(git_odb_backend_one_pack(&backend
, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
57 cl_git_pass(git_odb_add_backend(_odb
, backend
, 1));
60 cl_git_pass(git_odb_foreach(_odb
, foreach_cb
, &nobj
));
61 cl_assert(nobj
== 1628);
64 static int foreach_stop_cb(const git_oid
*oid
, void *data
)
71 return (*nobj
== 1000) ? -321 : 0;
74 static int foreach_stop_first_cb(const git_oid
*oid
, void *data
)
84 void test_odb_foreach__interrupt_foreach(void)
89 cl_git_pass(git_repository_open(&_repo
, cl_fixture("testrepo.git")));
90 git_repository_odb(&_odb
, _repo
);
92 cl_assert_equal_i(-321, git_odb_foreach(_odb
, foreach_stop_cb
, &nobj
));
93 cl_assert(nobj
== 1000);
96 git_repository_free(_repo
);
98 cl_git_pass(git_repository_init(&_repo
, "onlyloose.git", true));
99 git_repository_odb(&_odb
, _repo
);
101 cl_git_pass(git_odb_write(&id
, _odb
, "", 0, GIT_OBJ_BLOB
));
102 cl_assert_equal_i(-123, git_odb_foreach(_odb
, foreach_stop_first_cb
, &nobj
));
105 void test_odb_foreach__files_in_objects_dir(void)
107 git_repository
*repo
;
109 git_buf buf
= GIT_BUF_INIT
;
112 cl_fixture_sandbox("testrepo.git");
113 cl_git_pass(git_repository_open(&repo
, "testrepo.git"));
115 cl_git_pass(git_buf_printf(&buf
, "%s/objects/somefile", git_repository_path(repo
)));
116 cl_git_mkfile(buf
.ptr
, "");
119 cl_git_pass(git_repository_odb(&odb
, repo
));
120 cl_git_pass(git_odb_foreach(odb
, foreach_cb
, &nobj
));
121 cl_assert_equal_i(47 + 1640, nobj
); /* count + in-pack */
124 git_repository_free(repo
);
125 cl_fixture_cleanup("testrepo.git");