diff options
| author | yuangli <yuangli@mathworks.com> | 2022-07-07 09:26:18 +0100 |
|---|---|---|
| committer | yuangli <yuangli@mathworks.com> | 2022-07-07 09:26:18 +0100 |
| commit | 3e64f150ccfae3b7828a293fdd78daaf61e76ccf (patch) | |
| tree | 8b127643a31978bbe07b59dd36483ed35dc2a5ed /src | |
| parent | 10e2573550b0753f4aa0728bb2bbacf57d2377d0 (diff) | |
| download | libgit2-3e64f150ccfae3b7828a293fdd78daaf61e76ccf.tar.gz | |
rewrite shallow_root
Diffstat (limited to 'src')
| -rw-r--r-- | src/repository.c | 110 |
1 files changed, 87 insertions, 23 deletions
diff --git a/src/repository.c b/src/repository.c index bef719f4a..42ee263a3 100644 --- a/src/repository.c +++ b/src/repository.c @@ -3192,13 +3192,56 @@ int git_repository_state_cleanup(git_repository *repo) return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files)); } -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 contents = GIT_BUF_INIT; // int error, updated, line_num = 1; // char *line; -// char *buffer; +// chror = 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; + +// /* cancel out GIT_ENOTFOUND */ +// git_error_clear(); +// error = 0; + +// if (!updated) { +// out = repo->shallow_grafts; +// goto cleanup; +// } + +// git_array_clear(repo->shallow_grafts); + +// buffer = contents.ptr; +// 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) { +// git_error_set(GIT_ERROR_REPOSITORY, "Invalid OID at line %d", line_num); +// git_array_clear(repo->shallow_grafts); +// error = -1; +// goto cleanup; +// } +// ++line_num; +// } + +// if (*buffer) { +// git_error_set(GIT_ERROR_REPOSITORY, "No EOL at line %d", line_num); +// git_array_clear(repo->shallow_grafts); +// error = -1; +// goto cleanup; +// } + +// *out = repo->shallow_grafts; + +// cleanup: +// git_buf_dispose(&contents); + +// return error;ar *buffer; // assert(out && repo); @@ -3249,40 +3292,61 @@ int git_repository__shallow_roots(git_array_oid_t *out, git_repository *repo) // cleanup: // git_buf_dispose(&contents); - // return error; - return 0; +// return error; +// } + +int git_repository__shallow_roots(git_array_oid_t *out, git_repository *repo) { + int error =0; + if (!repo->shallow_grafts) + load_grafts(repo); + + git_grafts_refresh(repo->shallow_grafts); + return git_grafts_get_oids(out, repo->shallow_grafts); } int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t roots) { - // git_filebuf file = GIT_FILEBUF_INIT; - // git_buf path = GIT_BUF_INIT; - // int error = 0; - // size_t idx; - // git_oid *oid; + git_filebuf file = GIT_FILEBUF_INIT; + git_buf path = GIT_BUF_INIT; + int error = 0; + size_t idx; + git_oid *oid; - // assert(repo); + assert(repo); - // if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0) - // return error; + if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0) + return error; - // if ((error = git_filebuf_open(&file, git_buf_cstr(&path), GIT_FILEBUF_HASH_CONTENTS, 0666)) < 0) - // return error; + if ((error = git_filebuf_open(&file, git_buf_cstr(&path), GIT_FILEBUF_HASH_CONTENTS, 0666)) < 0) + return error; - // git_array_foreach(roots, idx, oid) { - // git_filebuf_write(&file, git_oid_tostr_s(oid), GIT_OID_HEXSZ); - // git_filebuf_write(&file, "\n", 1); - // } + git_array_foreach(roots, idx, oid) { + git_filebuf_write(&file, git_oid_tostr_s(oid), GIT_OID_HEXSZ); + git_filebuf_write(&file, "\n", 1); + } - // git_filebuf_commit(&file); + git_filebuf_commit(&file); - // /* WIP: reload shallow */ - // if (load_shallow(repo) < 0) - // return -1; + if (load_grafts(repo) < 0) + return -1; return 0; } +int git_repository_shallow_roots(git_oidarray *out, git_repository *repo) +{ + int ret; + git_array_oid_t array = GIT_ARRAY_INIT; + + assert(out); + + ret = git_repository__shallow_roots(&array, repo); + + git_oidarray__from_array(out, &array); + + return ret; +} + int git_repository_is_shallow(git_repository *repo) { git_buf path = GIT_BUF_INIT; |
