8000 [WIP] Shallow smart transport support by tiennou · Pull Request #4747 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Shallow smart transport support #4747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repo: load grafts on open
This wires git_repository to open the .git/info/grafts file and load its contents as git_commit_grafts objects.
  • Loading branch information
tiennou committed Feb 3, 2019
commit 39d60690adebbe4e4db27d8e47e3e7128d35eace
5 changes: 5 additions & 0 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,9 @@ int git_buf_splice(
const char *data,
size_t nb_to_insert);

/* warning: this will wreck your buf contents */
#define git_buf_foreach_line(line_start, line_end, line_num, buf) \
while (((line_start) = git__strsep(&(buf)->ptr, "\n")) != NULL && \
((line_end) = (line_start) + strlen((line_start))) != NULL && ++(line_num))

#endif
1 change: 1 addition & 0 deletions src/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "object.h"
#include "array.h"
#include "oidarray.h"
#include "graft.h"

void git_commit__free(void *_commit)
{
Expand Down
80 changes: 80 additions & 0 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ void git_repository__cleanup(git_repository *repo)
git_cache_clear(&repo->objects);
git_attr_cache_flush(repo);

git__graft_clear(repo->grafts);
git_oidmap_free(repo->grafts);

set_config(repo, NULL);
set_index(repo, NULL);
set_odb(repo, NULL);
Expand Down Expand Up @@ -241,6 +244,8 @@ static git_repository *repository_alloc(void)
/* set all the entries in the cvar cache to `unset` */
git_repository__cvar_cache_clear(repo);

repo->grafts = git_oidmap_alloc();

return repo;

on_error:
Expand Down Expand Up @@ -562,6 +567,78 @@ static int find_repo(
return error;
}

static int load_grafts(git_repository *repo)
{
git_buf graft_path = GIT_BUF_INIT;
git_buf contents = GIT_BUF_INIT;
git_buf dup_contents;
const char *line_start;
const char *line_end;
int line_num = 0;
int error, updated;
git_array_oid_t parents = GIT_ARRAY_INIT;

if ((error = git_repository_item_path(&graft_path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0)
return error;

if (git_buf_joinpath(&graft_path, graft_path.ptr, "grafts")) {
git_buf_dispose(&graft_path);
return error;
}

error = git_futils_readbuffer_updated(&contents, git_buf_cstr(&graft_path), &repo->graft_checksum, &updated);
git_buf_dispose(&graft_path);

if (error == GIT_ENOTFOUND || !updated)
return 0;

if (error < 0)
goto cleanup;

if (updated) {
git__graft_clear(repo->grafts);
}

dup_contents.ptr = contents.ptr;
git_buf_foreach_line(line_start, line_end, line_num, &dup_contents) {
git_oid graft_oid, parent_oid;

error = git_oid_fromstrn(&graft_oid, line_start, GIT_OID_HEXSZ);
if (error < 0) {
git_error_set(GIT_ERROR_REPOSITORY, "Invalid OID at line %d", line_num);
error = -1;
}
line_start += GIT_OID_HEXSZ;

if (*(line_start++) == ' ') {
while (git_oid_fromstrn(&parent_oid, line_start, GIT_OID_HEXSZ) == 0) {
git_oid *id = git_array_alloc(parents);

git_oid_cpy(id, &parent_oid);
line_start += GIT_OID_HEXSZ;
if (line_start >= line_end) {
break;
}
line_start += 1;
}
}

if (git__graft_register(repo->grafts, &graft_oid, parents) < 0) {
git_error_set(GIT_ERROR_REPOSITORY, "Invalid graft at line %d", line_num);
error = -1;
goto cleanup;
}
git_array_clear(parents);
line_num++;
}

cleanup:
git_array_clear(parents);
git_buf_dispose(&contents);

return error;
}

int git_repository_open_bare(
git_repository **repo_ptr,
const char *bare_path)
Expand Down Expand Up @@ -845,6 +922,9 @@ int git_repository_open_ext(
if (config && (error = check_repositoryformatversion(config)) < 0)
goto cleanup;

if ((error = load_grafts(repo)) < 0)
goto cleanup;

if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
repo->is_bare = 1;
else {
Expand Down
4 changes: 4 additions & 0 deletions src/repository.h
8AD9
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "attrcache.h"
#include "submodule.h"
#include "diff_driver.h"
#include "graft.h"

#define DOT_GIT ".git"
#define GIT_DIR DOT_GIT "/"
Expand Down Expand Up @@ -152,6 +153,9 @@ struct git_repository {

unsigned int lru_counter;

git_graftmap *grafts;
git_oid graft_checksum;

git_atomic attr_session_key;

git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
Expand Down
0