8000 repo: dump backends on oid type change · libgit2/libgit2@83a5b18 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83a5b18

Browse files
committed
repo: dump backends on oid type change
1 parent 77ba1f9 commit 83a5b18

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/libgit2/repository.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ int git_repository_open_ext(
10321032
goto cleanup;
10331033
}
10341034

1035-
if ((error = load_objectformat(repo, config)) < 0)
1035+
if (version > 0 &&
1036+
(error = load_objectformat(repo, config)) < 0)
10361037
goto cleanup;
10371038

10381039
/*
@@ -1670,6 +1671,12 @@ int git_repository__set_objectformat(
16701671
if (oid_type == GIT_OID_DEFAULT)
16711672
return 0;
16721673

1674+
if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) {
1675+
git_error_set(GIT_ERROR_REPOSITORY,
1676+
"cannot change object id type of existing repository");
1677+
return -1;
1678+
}
1679+
16731680
if (git_repository_config__weakptr(&cfg, repo) < 0)
16741681
return -1;
16751682

@@ -1679,7 +1686,18 @@ int git_repository__set_objectformat(
16791686
git_oid_type_name(oid_type)) < 0)
16801687
return -1;
16811688

1682-
repo->oid_type = oid_type;
1689+
/*
1690+
* During repo init, we may create some backends with the
1691+
* default oid type. Clear them so that we create them with
1692+
* the proper oid type.
1693+
*/
1694+
if (repo->oid_type != oid_type) {
1695+
set_index(repo, NULL);
1696+
set_odb(repo, NULL);
1697+
set_refdb(repo, NULL);
1698+
1699+
repo->oid_type = oid_type;
1700+
}
16831701

16841702
return 0;< 3D68 /div>
16851703
}

0 commit comments

Comments
 (0)
0