Commit ad563552 by Yuang Li

use shallow feature flag in shallow clone support source code

parent 6bab22f4
...@@ -500,29 +500,35 @@ int git_commit__parse_raw(void *commit, const char *data, size_t size) ...@@ -500,29 +500,35 @@ int git_commit__parse_raw(void *commit, const char *data, size_t size)
int git_commit__parse_ext(git_commit *commit, git_odb_object *odb_obj, unsigned int flags) int git_commit__parse_ext(git_commit *commit, git_odb_object *odb_obj, unsigned int flags)
{ {
git_repository *repo = git_object_owner((git_object *)commit);
git_commit_graft *graft;
int error;
int error;
if ((error = commit_parse(commit, git_odb_object_data(odb_obj), if ((error = commit_parse(commit, git_odb_object_data(odb_obj),
git_odb_object_size(odb_obj), flags)) < 0) git_odb_object_size(odb_obj), flags)) < 0)
return error; return error;
/* Perform necessary grafts */ if (GIT_OPT_ENABLE_SHALLOW) {
if (git_grafts_get(&graft, repo->grafts, git_odb_object_id(odb_obj)) == 0 ||
git_grafts_get(&graft, repo->shallow_grafts, git_odb_object_id(odb_obj)) == 0) { git_repository *repo = git_object_owner((git_object *)commit);
size_t idx; git_commit_graft *graft;
git_oid *oid;
git_array_clear(commit->parent_ids); /* Perform necessary grafts */
git_array_init_to_size(commit->parent_ids, git_array_size(graft->parents)); if (git_grafts_get(&graft, repo->grafts, git_odb_object_id(odb_obj)) == 0 ||
git_array_foreach(graft->parents, idx, oid) { git_grafts_get(&graft, repo->shallow_grafts, git_odb_object_id(odb_obj)) == 0) {
git_oid *id = git_array_alloc(commit->parent_ids); size_t idx;
GIT_ERROR_CHECK_ALLOC(id); git_oid *oid;
git_array_clear(commit->parent_ids);
git_oid_cpy(id, oid); git_array_init_to_size(commit->parent_ids, git_array_size(graft->parents));
git_array_foreach(graft->parents, idx, oid) {
git_oid *id = git_array_alloc(commit->parent_ids);
GIT_ERROR_CHECK_ALLOC(id);
git_oid_cpy(id, oid);
}
} }
}
}
return 0; return 0;
} }
......
...@@ -926,7 +926,7 @@ int git_repository_open_ext( ...@@ -926,7 +926,7 @@ int git_repository_open_ext(
if ((error = check_extensions(config, version)) < 0) if ((error = check_extensions(config, version)) < 0)
goto cleanup; goto cleanup;
if ((error = load_grafts(repo)) < 0) if (GIT_OPT_ENABLE_SHALLOW && (error = load_grafts(repo)) < 0)
goto cleanup; goto cleanup;
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
......
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