summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-02-20 20:30:16 +0000
committerGitHub <noreply@github.com>2023-02-20 20:30:16 +0000
commit96e85df607863f94b55aba088c1395095b52bba7 (patch)
tree15bd7e1a60674aac2e3f02941cabde74644722a4 /src
parent795758d2ada5b4760664050230343920eab528f6 (diff)
parent2ae3bbf32b85a12a75f878aff2a9a95690821960 (diff)
downloadlibgit2-96e85df607863f94b55aba088c1395095b52bba7.tar.gz
Merge pull request #6492 from cavaquinho/fix/bare-repo-oid-type
#6491: Sets oid_type on repos open with git_repository_open_bare
Diffstat (limited to 'src')
-rw-r--r--src/libgit2/repository.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 489d627a0..a3e7b9e13 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -733,6 +733,43 @@ out:
return error;
}
+static int obtain_config_and_set_oid_type(
+ git_config **config_ptr,
+ git_repository *repo)
+{
+ int error;
+ git_config *config = NULL;
+ int version = 0;
+
+ /*
+ * We'd like to have the config, but git doesn't particularly
+ * care if it's not there, so we need to deal with that.
+ */
+
+ error = git_repository_config_snapshot(&config, repo);
+ if (error < 0 && error != GIT_ENOTFOUND)
+ goto out;
+
+ if (config &&
+ (error = check_repositoryformatversion(&version, config)) < 0)
+ goto out;
+
+ if ((error = check_extensions(config, version)) < 0)
+ goto out;
+
+ if (version > 0) {
+ if ((error = load_objectformat(repo, config)) < 0)
+ goto out;
+ } else {
+ repo->oid_type = GIT_OID_SHA1;
+ }
+
+out:
+ *config_ptr = config;
+
+ return error;
+}
+
int git_repository_open_bare(
git_repository **repo_ptr,
const char *bare_path)
@@ -741,6 +778,7 @@ int git_repository_open_bare(
git_repository *repo = NULL;
bool is_valid;
int error;
+ git_config *config;
if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
(error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
@@ -766,8 +804,15 @@ int git_repository_open_bare(
repo->is_worktree = 0;
repo->workdir = NULL;
+ if ((error = obtain_config_and_set_oid_type(&config, repo)) < 0)
+ goto cleanup;
+
*repo_ptr = repo;
- return 0;
+
+cleanup:
+ git_config_free(config);
+
+ return error;
}
static int _git_repository_open_ext_from_env(
@@ -974,7 +1019,6 @@ int git_repository_open_ext(
gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
git_repository *repo = NULL;
git_config *config = NULL;
- int version = 0;
if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
return _git_repository_open_ext_from_env(repo_ptr, start_path);
@@ -1007,20 +1051,8 @@ int git_repository_open_ext(
goto cleanup;
repo->is_worktree = is_worktree;
- /*
- * We'd like to have the config, but git doesn't particularly
- * care if it's not there, so we need to deal with that.
- */
-
- error = git_repository_config_snapshot(&config, repo);
- if (error < 0 && error != GIT_ENOTFOUND)
- goto cleanup;
-
- if (config &&
- (error = check_repositoryformatversion(&version, config)) < 0)
- goto cleanup;
-
- if ((error = check_extensions(config, version)) < 0)
+ error = obtain_config_and_set_oid_type(&config, repo);
+ if (error < 0)
goto cleanup;
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) {
@@ -1032,13 +1064,6 @@ int git_repository_open_ext(
goto cleanup;
}
- if (version > 0) {
- if ((error = load_objectformat(repo, config)) < 0)
- goto cleanup;
- } else {
- repo->oid_type = GIT_OID_SHA1;
- }
-
/*
* Ensure that the git directory and worktree are
* owned by the current user.