summaryrefslogtreecommitdiff
path: root/src/libgit2
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-12-03 13:07:23 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-12 21:26:11 +0000
commit3dfc12d5e210a6e15c7c54f3514eeeb12fb2108a (patch)
treee8376a195ed6b5e68a341e55c7aa41307081a392 /src/libgit2
parentacb00e4eae66bfed84046bccb60bf59707fe9626 (diff)
downloadlibgit2-3dfc12d5e210a6e15c7c54f3514eeeb12fb2108a.tar.gz
repo: internal setter for `objectformat`
Provide an internal function to set the repository's `objectformat`, both in the internal object and in the configuration.
Diffstat (limited to 'src/libgit2')
-rw-r--r--src/libgit2/repository.c30
-rw-r--r--src/libgit2/repository.h8
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 5d51be6b7..9c55aaca5 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -1648,6 +1648,36 @@ done:
return error;
}
+int git_repository__set_objectformat(
+ git_repository *repo,
+ git_oid_t oid_type)
+{
+ git_config *cfg;
+
+ /*
+ * Older clients do not necessarily understand the
+ * `objectformat` extension, even when it's set to an
+ * object format that they understand (SHA1). Do not set
+ * the objectformat extension unless we're not using the
+ * default object format.
+ */
+ if (oid_type == GIT_OID_DEFAULT)
+ return 0;
+
+ if (git_repository_config__weakptr(&cfg, repo) < 0)
+ return -1;
+
+ if (git_config_set_int32(cfg,
+ "core.repositoryformatversion", 1) < 0 ||
+ git_config_set_string(cfg, "extensions.objectformat",
+ git_oid_type_name(oid_type)) < 0)
+ return -1;
+
+ repo->oid_type = oid_type;
+
+ return 0;
+}
+
int git_repository__extensions(char ***out, size_t *out_len)
{
git_vector extensions;
diff --git a/src/libgit2/repository.h b/src/libgit2/repository.h
index b1e212a32..75380ae53 100644
--- a/src/libgit2/repository.h
+++ b/src/libgit2/repository.h
@@ -257,4 +257,12 @@ int git_repository__extensions(char ***out, size_t *out_len);
int git_repository__set_extensions(const char **extensions, size_t len);
void git_repository__free_extensions(void);
+/*
+ * Set the object format (OID type) for a repository; this will set
+ * both the configuration and the internal value for the oid type.
+ */
+int git_repository__set_objectformat(
+ git_repository *repo,
+ git_oid_t oid_type);
+
#endif