]>
git.proxmox.com Git - libgit2.git/blob - tests/pack/midx.c
9dd949363e6200a8d5c7b219b283773eec07191a
1 #include "clar_libgit2.h"
4 #include <git2/sys/midx.h>
9 void test_pack_midx__parse(void)
12 struct git_midx_file
*idx
;
13 struct git_midx_entry e
;
15 git_str midx_path
= GIT_STR_INIT
;
17 cl_git_pass(git_repository_open(&repo
, cl_fixture("testrepo.git")));
18 cl_git_pass(git_str_joinpath(&midx_path
, git_repository_path(repo
), "objects/pack/multi-pack-index"));
19 cl_git_pass(git_midx_open(&idx
, git_str_cstr(&midx_path
)));
20 cl_assert_equal_i(git_midx_needs_refresh(idx
, git_str_cstr(&midx_path
)), 0);
22 cl_git_pass(git_oid_fromstr(&id
, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
23 cl_git_pass(git_midx_entry_find(&e
, idx
, &id
, GIT_OID_HEXSZ
));
24 cl_assert_equal_oid(&e
.sha1
, &id
);
26 (const char *)git_vector_get(&idx
->packfile_names
, e
.pack_index
),
27 "pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx");
30 git_repository_free(repo
);
31 git_str_dispose(&midx_path
);
34 void test_pack_midx__lookup(void)
40 cl_git_pass(git_repository_open(&repo
, cl_fixture("testrepo.git")));
42 cl_git_pass(git_oid_fromstr(&id
, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
43 cl_git_pass(git_commit_lookup_prefix(&commit
, repo
, &id
, GIT_OID_HEXSZ
));
44 cl_assert_equal_s(git_commit_message(commit
), "packed commit one\n");
46 git_commit_free(commit
);
47 git_repository_free(repo
);
50 void test_pack_midx__writer(void)
53 git_midx_writer
*w
= NULL
;
54 git_buf midx
= GIT_BUF_INIT
;
55 git_str expected_midx
= GIT_STR_INIT
, path
= GIT_STR_INIT
;
57 cl_git_pass(git_repository_open(&repo
, cl_fixture("testrepo.git")));
59 cl_git_pass(git_str_joinpath(&path
, git_repository_path(repo
), "objects/pack"));
60 cl_git_pass(git_midx_writer_new(&w
, git_str_cstr(&path
)));
62 cl_git_pass(git_midx_writer_add(w
, "pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx"));
63 cl_git_pass(git_midx_writer_add(w
, "pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx"));
64 cl_git_pass(git_midx_writer_add(w
, "pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"));
66 cl_git_pass(git_midx_writer_dump(&midx
, w
));
67 cl_git_pass(git_str_joinpath(&path
, git_repository_path(repo
), "objects/pack/multi-pack-index"));
68 cl_git_pass(git_futils_readbuffer(&expected_midx
, git_str_cstr(&path
)));
70 cl_assert_equal_i(midx
.size
, git_str_len(&expected_midx
));
71 cl_assert_equal_strn(midx
.ptr
, git_str_cstr(&expected_midx
), midx
.size
);
73 git_buf_dispose(&midx
);
74 git_str_dispose(&expected_midx
);
75 git_str_dispose(&path
);
76 git_midx_writer_free(w
);
77 git_repository_free(repo
);
80 void test_pack_midx__odb_create(void)
84 git_clone_options opts
= GIT_CLONE_OPTIONS_INIT
;
85 git_str midx
= GIT_STR_INIT
, expected_midx
= GIT_STR_INIT
, midx_path
= GIT_STR_INIT
;
89 opts
.local
= GIT_CLONE_LOCAL
;
90 cl_git_pass(git_clone(&repo
, cl_fixture("testrepo/.gitted"), "./clone.git", &opts
));
91 cl_git_pass(git_str_joinpath(&midx_path
, git_repository_path(repo
), "objects/pack/multi-pack-index"));
92 cl_git_fail(p_stat(git_str_cstr(&midx_path
), &st
));
94 cl_git_pass(git_repository_odb(&odb
, repo
));
95 cl_git_pass(git_odb_write_multi_pack_index(odb
));
98 cl_git_pass(p_stat(git_str_cstr(&midx_path
), &st
));
100 cl_git_pass(git_futils_readbuffer(&expected_midx
, cl_fixture("testrepo.git/objects/pack/multi-pack-index")));
101 cl_git_pass(git_futils_readbuffer(&midx
, git_str_cstr(&midx_path
)));
102 cl_assert_equal_i(git_str_len(&midx
), git_str_len(&expected_midx
));
103 cl_assert_equal_strn(git_str_cstr(&midx
), git_str_cstr(&expected_midx
), git_str_len(&midx
));
105 git_repository_free(repo
);
106 git_str_dispose(&midx
);
107 git_str_dispose(&midx_path
);
108 git_str_dispose(&expected_midx
);
110 cl_git_pass(git_futils_rmdir_r("./clone.git", NULL
, GIT_RMDIR_REMOVE_FILES
));