summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtienne Samson <samson.etienne@gmail.com>2018-08-02 21:40:51 +0200
committerPatrick Steinhardt <ps@pks.im>2020-06-27 14:33:58 +0200
commita8b1d5156cf25c6b24feb084c55e8133b43d6390 (patch)
tree404c5d1f6604fcac71a2276ca395dd2d393b9312
parent3c17f22976d62e5fc2743186b4b1b567aadf104a (diff)
downloadlibgit2-a8b1d5156cf25c6b24feb084c55e8133b43d6390.tar.gz
repo: graft shallow roots on open
-rw-r--r--src/repository.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c
index da27f545b..977c71002 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -654,6 +654,27 @@ cleanup:
return error;
}
+static int load_shallow(git_repository *repo)
+{
+ int error = 0;
+ git_array_oid_t roots = GIT_ARRAY_INIT;
+ git_array_oid_t parents = GIT_ARRAY_INIT;
+ size_t i;
+ git_oid *graft_oid;
+
+ /* Graft shallow roots */
+ if ((error = git_repository__shallow_roots(&roots, repo)) < 0) {
+ return error;
+ }
+
+ git_array_foreach(roots, i, graft_oid) {
+ if ((error = git__graft_register(repo->grafts, graft_oid, parents)) < 0) {
+ return error;
+ }
+ }
+ return 0;
+}
+
int git_repository_open_bare(
git_repository **repo_ptr,
const char *bare_path)
@@ -946,6 +967,9 @@ int git_repository_open_ext(
if ((error = load_grafts(repo)) < 0)
goto cleanup;
+ if ((error = load_shallow(repo)) < 0)
+ goto cleanup;
+
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
repo->is_bare = 1;
else {