]> git.proxmox.com Git - libgit2.git/blame - tests/odb/foreach.c
Doc fixes
[libgit2.git] / tests / odb / foreach.c
CommitLineData
521aedad
CMN
1#include "clar_libgit2.h"
2#include "odb.h"
3#include "git2/odb_backend.h"
4#include "pack.h"
5
6static git_odb *_odb;
7static git_repository *_repo;
521aedad 8
521aedad
CMN
9void test_odb_foreach__cleanup(void)
10{
11 git_odb_free(_odb);
12 git_repository_free(_repo);
81f73a87
VM
13
14 _odb = NULL;
15 _repo = NULL;
521aedad
CMN
16}
17
c3fb7d04 18static int foreach_cb(const git_oid *oid, void *data)
521aedad 19{
25e0b157
RB
20 int *nobj = data;
21 (*nobj)++;
521aedad 22
25e0b157 23 GIT_UNUSED(oid);
521aedad
CMN
24
25 return 0;
26}
27
1d733b57 28/*
83e1efbf 29 * $ git --git-dir tests/resources/testrepo.git count-objects --verbose
24cb87e2 30 * count: 47
31 * size: 4
1d733b57 32 * in-pack: 1640
33 * packs: 3
34 * size-pack: 425
35 * prune-packable: 0
36 * garbage: 0
37 */
521aedad
CMN
38void test_odb_foreach__foreach(void)
39{
25e0b157
RB
40 int nobj = 0;
41
507523c3
CMN
42 cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
43 git_repository_odb(&_odb, _repo);
44
25e0b157 45 cl_git_pass(git_odb_foreach(_odb, foreach_cb, &nobj));
24cb87e2 46 cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */
521aedad 47}
507523c3
CMN
48
49void test_odb_foreach__one_pack(void)
50{
51 git_odb_backend *backend = NULL;
25e0b157 52 int nobj = 0;
507523c3
CMN
53
54 cl_git_pass(git_odb_new(&_odb));
55 cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
56 cl_git_pass(git_odb_add_backend(_odb, backend, 1));
57 _repo = NULL;
58
25e0b157 59 cl_git_pass(git_odb_foreach(_odb, foreach_cb, &nobj));
507523c3
CMN
60 cl_assert(nobj == 1628);
61}
5dca2010 62
c3fb7d04 63static int foreach_stop_cb(const git_oid *oid, void *data)
5dca2010 64{
25e0b157
RB
65 int *nobj = data;
66 (*nobj)++;
5dca2010 67
25e0b157 68 GIT_UNUSED(oid);
5dca2010 69
25e0b157 70 return (*nobj == 1000) ? -321 : 0;
5dca2010
RB
71}
72
73void test_odb_foreach__interrupt_foreach(void)
74{
25e0b157
RB
75 int nobj = 0;
76
81f73a87
VM
77 cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
78 git_repository_odb(&_odb, _repo);
79
25e0b157 80 cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj));
5dca2010
RB
81 cl_assert(nobj == 1000);
82}