summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-12-04 14:22:02 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-12 22:02:00 +0000
commitaf20d13b18dbab4de9f244402c255bc85e907ac1 (patch)
tree6ebbb7e1a60397ed7b0638b3381ef4bdebf65a61
parent53fcd5b8f5f069ee9a2567280dca81b74192da74 (diff)
downloadlibgit2-af20d13b18dbab4de9f244402c255bc85e907ac1.tar.gz
repo: dump backends on oid type change
-rw-r--r--src/libgit2/repository.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 2da6caf3a..928f4635c 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -1674,6 +1674,12 @@ int git_repository__set_objectformat(
if (oid_type == GIT_OID_DEFAULT)
return 0;
+ if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) {
+ git_error_set(GIT_ERROR_REPOSITORY,
+ "cannot change object id type of existing repository");
+ return -1;
+ }
+
if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1;
@@ -1683,7 +1689,18 @@ int git_repository__set_objectformat(
git_oid_type_name(oid_type)) < 0)
return -1;
- repo->oid_type = oid_type;
+ /*
+ * During repo init, we may create some backends with the
+ * default oid type. Clear them so that we create them with
+ * the proper oid type.
+ */
+ if (repo->oid_type != oid_type) {
+ set_index(repo, NULL);
+ set_odb(repo, NULL);
+ set_refdb(repo, NULL);
+
+ repo->oid_type = oid_type;
+ }
return 0;
}