Skip to content

Commit af20d13

Browse files
committed
repo: dump backends on oid type change
1 parent 53fcd5b commit af20d13

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/libgit2/repository.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,12 @@ int git_repository__set_objectformat(
16741674
if (oid_type == GIT_OID_DEFAULT)
16751675
return 0;
16761676

1677+
if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) {
1678+
git_error_set(GIT_ERROR_REPOSITORY,
1679+
"cannot change object id type of existing repository");
1680+
return -1;
1681+
}
1682+
16771683
if (git_repository_config__weakptr(&cfg, repo) < 0)
16781684
return -1;
16791685

@@ -1683,7 +1689,18 @@ int git_repository__set_objectformat(
16831689
git_oid_type_name(oid_type)) < 0)
16841690
return -1;
16851691

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

16881705
return 0;
16891706
}

0 commit comments

Comments
 (0)