Commit 10e25735 by yuangli

attempt to build

parent afa79ca0
...@@ -3194,89 +3194,91 @@ int git_repository_state_cleanup(git_repository *repo) ...@@ -3194,89 +3194,91 @@ int git_repository_state_cleanup(git_repository *repo)
int git_repository__shallow_roots(git_array_oid_t *out, git_repository *repo) int git_repository__shallow_roots(git_array_oid_t *out, git_repository *repo)
{ {
git_buf path = GIT_BUF_INIT; // git_buf path = GIT_BUF_INIT;
git_buf contents = GIT_BUF_INIT; // git_buf contents = GIT_BUF_INIT;
int error, updated, line_num = 1; // int error, updated, line_num = 1;
char *line; // char *line;
char *buffer; // char *buffer;
assert(out && repo); // assert(out && repo);
if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0) // if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
return error; // return error;
error = git_futils_readbuffer_updated(&contents, git_buf_cstr(&path), &repo->shallow_checksum, &updated); // //error = git_futils_readbuffer_updated(&contents, git_buf_cstr(&path), &repo->shallow_checksum, &updated);
git_buf_dispose(&path); // error = git_futils_readbuffer_updated(&contents, git_buf_cstr(&path), &repo->shallow_grafts->git_grafts->path_checksum, &updated);
// git_buf_dispose(&path);
if (error < 0 && error != GIT_ENOTFOUND)
return error; // if (error < 0 && error != GIT_ENOTFOUND)
// return error;
/* cancel out GIT_ENOTFOUND */
git_error_clear(); // /* cancel out GIT_ENOTFOUND */
error = 0; // git_error_clear();
// error = 0;
if (!updated) {
*out = repo->shallow_oids; // if (!updated) {
goto cleanup; // out = repo->shallow_grafts;
} // goto cleanup;
// }
git_array_clear(repo->shallow_oids);
// git_array_clear(repo->shallow_grafts);
buffer = contents.ptr;
while ((line = git__strsep(&buffer, "\n")) != NULL) { // buffer = contents.ptr;
git_oid *oid = git_array_alloc(repo->shallow_oids); // while ((line = git__strsep(&buffer, "\n")) != NULL) {
// git_oid *oid = git_array_alloc(repo->shallow_grafts);
error = git_oid_fromstr(oid, line);
if (error < 0) { // error = git_oid_fromstr(oid, line);
git_error_set(GIT_ERROR_REPOSITORY, "Invalid OID at line %d", line_num); // if (error < 0) {
git_array_clear(repo->shallow_oids); // git_error_set(GIT_ERROR_REPOSITORY, "Invalid OID at line %d", line_num);
error = -1; // git_array_clear(repo->shallow_grafts);
goto cleanup; // error = -1;
} // goto cleanup;
++line_num; // }
} // ++line_num;
// }
if (*buffer) {
git_error_set(GIT_ERROR_REPOSITORY, "No EOL at line %d", line_num); // if (*buffer) {
git_array_clear(repo->shallow_oids); // git_error_set(GIT_ERROR_REPOSITORY, "No EOL at line %d", line_num);
error = -1; // git_array_clear(repo->shallow_grafts);
goto cleanup; // error = -1;
} // goto cleanup;
// }
*out = repo->shallow_oids;
// *out = repo->shallow_grafts;
cleanup:
git_buf_dispose(&contents); // cleanup:
// git_buf_dispose(&contents);
return error;
// return error;
return 0;
} }
int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t roots) int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t roots)
{ {
git_filebuf file = GIT_FILEBUF_INIT; // git_filebuf file = GIT_FILEBUF_INIT;
git_buf path = GIT_BUF_INIT; // git_buf path = GIT_BUF_INIT;
int error = 0; // int error = 0;
size_t idx; // size_t idx;
git_oid *oid; // git_oid *oid;
assert(repo); // assert(repo);
if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0) // if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
return error; // return error;
if ((error = git_filebuf_open(&file, git_buf_cstr(&path), GIT_FILEBUF_HASH_CONTENTS, 0666)) < 0) // if ((error = git_filebuf_open(&file, git_buf_cstr(&path), GIT_FILEBUF_HASH_CONTENTS, 0666)) < 0)
return error; // return error;
git_array_foreach(roots, idx, oid) { // git_array_foreach(roots, idx, oid) {
git_filebuf_write(&file, git_oid_tostr_s(oid), GIT_OID_HEXSZ); // git_filebuf_write(&file, git_oid_tostr_s(oid), GIT_OID_HEXSZ);
git_filebuf_write(&file, "\n", 1); // git_filebuf_write(&file, "\n", 1);
} // }
git_filebuf_commit(&file); // git_filebuf_commit(&file);
/* WIP: reload shallow */ // /* WIP: reload shallow */
if (load_shallow(repo) < 0) // if (load_shallow(repo) < 0)
return -1; // return -1;
return 0; return 0;
} }
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "futils.h" #include "futils.h"
#include "repository.h"
void test_clone_shallow__initialize(void) void test_clone_shallow__initialize(void)
{ {
...@@ -33,7 +34,7 @@ void test_clone_shallow__clone_depth(void) ...@@ -33,7 +34,7 @@ void test_clone_shallow__clone_depth(void)
cl_assert_equal_b(true, git_repository_is_shallow(repo)); cl_assert_equal_b(true, git_repository_is_shallow(repo));
cl_git_pass(git_repository_shallow_roots(&roots, repo)); cl_git_pass(git_repository__shallow_roots(&roots, repo));
cl_assert_equal_i(1, roots.count); cl_assert_equal_i(1, roots.count);
cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ids[0])); cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ids[0]));
......
#include "clar_libgit2.h"
#include "futils.h"
#include "grafts.h"
static git_repository *g_repo;
void test_repo_grafts__initialize(void)
{
g_repo = cl_git_sandbox_init("grafted.git");
}
void test_repo_grafts__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_grafts__graft_register(void)
{
git_oid oid_src;
git_commit_graft *graft;
git_graftmap *grafts = git_oidmap_alloc();
git_array_oid_t parents = GIT_ARRAY_INIT;
git_oid *oid1 = git_array_alloc(parents);
cl_git_pass(git_oid_fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9"));
git_oid_cpy(oid1, &oid_src);
git_oid_fromstr(&oid_src, "f503807ffa920e407a600cfaee96b7152259acc7");
cl_git_pass(git__graft_register(grafts, &oid_src, parents));
git_array_clear(parents);
cl_assert_equal_i(1, git_oidmap_size(grafts));
cl_git_pass(git__graft_for_oid(&graft, grafts, &oid_src));
cl_assert_equal_s("f503807ffa920e407a600cfaee96b7152259acc7", git_oid_tostr_s(&graft->oid));
cl_assert_equal_i(1, git_array_size(graft->parents));
cl_assert_equal_s("2f3053cbff8a4ca2f0666de364ddb734a28a31a9", git_oid_tostr_s(git_array_get(graft->parents, 0)));
git__graft_clear(grafts);
git_oidmap_free(grafts);
}
void test_repo_grafts__grafted_revwalk(void)
{
git_revwalk *w;
git_oid oids[10];
size_t i = 0;
git_commit *commit;
cl_git_pass(git_revwalk_new(&w, g_repo));
cl_git_pass(git_revwalk_push_ref(w, "refs/heads/branch"));
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[0]), "8a00e91619098618be97c0d2ceabb05a2c58edd9");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[1]), "f503807ffa920e407a600cfaee96b7152259acc7");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[2]), "2f3053cbff8a4ca2f0666de364ddb734a28a31a9");
cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oids[i++], w));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oids[0]));
cl_assert_equal_i(1, git_commit_parentcount(commit));
git_commit_free(commit);
git_revwalk_free(w);
}
void test_repo_grafts__grafted_objects(void)
{
git_oid oid;
git_commit *commit;
cl_git_pass(git_oid_fromstr(&oid, "f503807ffa920e407a600cfaee96b7152259acc7"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
cl_assert_equal_i(1, git_commit_parentcount(commit));
git_commit_free(commit);
cl_git_pass(git_oid_fromstr(&oid, "0512adebd3782157f0d5c9b22b043f87b4aaff9e"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
cl_assert_equal_i(1, git_commit_parentcount(commit));
git_commit_free(commit);
cl_git_pass(git_oid_fromstr(&oid, "66cc22a015f6ca75b34c82d28f78ba663876bade"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
cl_assert_equal_i(4, git_commit_parentcount(commit));
git_commit_free(commit);
}
void test_repo_grafts__grafted_merge_revwalk(void)
{
git_revwalk *w;
git_oid oids[10];
size_t i = 0;
cl_git_pass(git_revwalk_new(&w, g_repo));
cl_git_pass(git_revwalk_push_ref(w, "refs/heads/bottom"));
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "66cc22a015f6ca75b34c82d28f78ba663876bade");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "e414f42f4e6bc6934563a2349a8600f0ab68618e");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "8a00e91619098618be97c0d2ceabb05a2c58edd9");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "1c18e80a276611bb9b146590616bbc5aebdf2945");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "d7224d49d6d5aff6ade596ed74f4bcd4f77b29e2");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "0512adebd3782157f0d5c9b22b043f87b4aaff9e");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "f503807ffa920e407a600cfaee96b7152259acc7");
cl_git_pass(git_revwalk_next(&oids[i++], w));
cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "2f3053cbff8a4ca2f0666de364ddb734a28a31a9");
cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oids[i++], w));
git_revwalk_free(w);
}
#include "clar_libgit2.h"
#include "futils.h"
static git_repository *g_repo;
static git_oid g_shallow_oid;
void test_repo_shallow__initialize(void)
{
cl_git_pass(git_oid_fromstr(&g_shallow_oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
}
void test_repo_shallow__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_shallow__no_shallow_file(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
}
void test_repo_shallow__empty_shallow_file(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_mkfile("testrepo.git/shallow", "");
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
}
void test_repo_shallow__shallow_repo(void)
{
g_repo = cl_git_sandbox_init("shallow.git");
cl_assert_equal_i(1, git_repository_is_shallow(g_repo));
}
void test_repo_shallow__clears_errors(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
cl_assert_equal_p(NULL, git_error_last());
}
void test_repo_shallow__shallow_oids(void)
{
git_oidarray oids, oids2;
g_repo = cl_git_sandbox_init("shallow.git");
cl_git_pass(git_repository_shallow_roots(&oids, g_repo));
cl_assert_equal_i(1, oids.count);
cl_assert_equal_oid(&g_shallow_oid, &oids.ids[0]);
cl_git_pass(git_repository_shallow_roots(&oids2, g_repo));
cl_assert_equal_p(oids.ids, oids2.ids);
}
void test_repo_shallow__cache_clearing(void)
{
git_oidarray oids, oids2;
git_oid tmp_oid;
git_oid_fromstr(&tmp_oid, "0000000000000000000000000000000000000000");
g_repo = cl_git_sandbox_init("shallow.git");
cl_git_pass(git_repository_shallow_roots(&oids, g_repo));
cl_assert_equal_i(1, oids.count);
cl_assert_equal_oid(&g_shallow_oid, &oids.ids[0]);
cl_git_mkfile("shallow.git/shallow",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644\n"
"0000000000000000000000000000000000000000\n"
);
cl_git_pass(git_repository_shallow_roots(&oids2, g_repo));
cl_assert_equal_i(2, oids2.count);
cl_assert_equal_oid(&g_shallow_oid, &oids2.ids[0]);
cl_assert_equal_oid(&tmp_oid, &oids2.ids[1]);
}
void test_repo_shallow__errors_on_borked(void)
{
git_oidarray oids;
g_repo = cl_git_sandbox_init("shallow.git");
cl_git_mkfile("shallow.git/shallow", "lolno");
cl_git_fail_with(-1, git_repository_shallow_roots(&oids, g_repo));
cl_git_mkfile("shallow.git/shallow", "lolno\n");
cl_git_fail_with(-1, git_repository_shallow_roots(&oids, g_repo));
}
void test_repo_shallow__revwalk_behavior(void)
{
git_revwalk *w;
git_oid oid_1, oid_2, oid_3;
g_repo = cl_git_sandbox_init("shallow.git");
cl_git_pass(git_revwalk_new(&w, g_repo));
cl_git_pass(git_revwalk_push_head(w));
cl_git_pass(git_revwalk_next(&oid_1, w)); // a65fedf39aefe402d3bb6e24df4d4f5fe4547750
cl_git_pass(git_revwalk_next(&oid_2, w)); // be3563ae3f795b2b4353bcce3a527ad0a4f7f644
cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid_3, w));
cl_assert_equal_s(git_oid_tostr_s(&oid_1), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_assert_equal_s(git_oid_tostr_s(&oid_2), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
git_revwalk_free(w);
}
void test_repo_shallow__grafted_object(void)
{
git_commit *commit;
g_repo = cl_git_sandbox_init("shallow.git");
cl_git_pass(git_commit_lookup(&commit, g_repo, &g_shallow_oid));
cl_assert_equal_i(0, git_commit_parentcount(commit));
git_commit_free(commit);
}
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