summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-06-25 23:28:17 -0700
committerVicent Martí <vicent@github.com>2012-06-25 23:28:17 -0700
commited754a75e145352c02da62b5d56df5866d7eec26 (patch)
tree0c5a485e1ba6a535a380283de3374fc3a7d17192 /src
parentc6713398ba24b6e9df0950e432fbee1bf5d20373 (diff)
parentd6d8cc276d986a4b8eb606527607ffa9292ff97f (diff)
downloadlibgit2-ed754a75e145352c02da62b5d56df5866d7eec26.tar.gz
Merge pull request #783 from nulltoken/topic/reinit-coverage
Repo reinit fix + enhanced test coverage
Diffstat (limited to 'src')
-rw-r--r--src/repository.c47
1 files changed, 13 insertions, 34 deletions
diff --git a/src/repository.c b/src/repository.c
index 23a95b23e..bee7b3ee6 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -602,14 +602,10 @@ void git_repository_set_index(git_repository *repo, git_index *index)
GIT_REFCOUNT_INC(index);
}
-static int check_repositoryformatversion(git_repository *repo)
+static int check_repositoryformatversion(git_config *config)
{
- git_config *config;
int version;
- if (git_repository_config__weakptr(&config, repo) < 0)
- return -1;
-
if (git_config_get_int32(&version, config, "core.repositoryformatversion") < 0)
return -1;
@@ -623,26 +619,6 @@ static int check_repositoryformatversion(git_repository *repo)
return 0;
}
-static int repo_init_reinit(git_repository **repo_out, const char *repository_path, int is_bare)
-{
- git_repository *repo = NULL;
-
- GIT_UNUSED(is_bare);
-
- if (git_repository_open(&repo, repository_path) < 0)
- return -1;
-
- if (check_repositoryformatversion(repo) < 0) {
- git_repository_free(repo);
- return -1;
- }
-
- /* TODO: reinitialize the templates */
-
- *repo_out = repo;
- return 0;
-}
-
static int repo_init_createhead(const char *git_dir)
{
git_buf ref_path = GIT_BUF_INIT;
@@ -717,6 +693,12 @@ static int repo_init_config(const char *git_dir, bool is_bare, bool is_reinit)
return -1;
}
+ if (is_reinit && check_repositoryformatversion(config) < 0) {
+ git_buf_free(&cfg_path);
+ git_config_free(config);
+ return -1;
+ }
+
SET_REPO_CONFIG(bool, "core.bare", is_bare);
SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
SET_REPO_CONFIG(bool, "core.filemode", is_chmod_supported(git_buf_cstr(&cfg_path)));
@@ -850,21 +832,18 @@ int git_repository_init(git_repository **repo_out, const char *path, unsigned is
is_reinit = git_path_isdir(repository_path.ptr) && valid_repository_path(&repository_path);
if (is_reinit) {
- if (repo_init_reinit(repo_out, repository_path.ptr, is_bare) < 0)
- goto cleanup;
+ /* TODO: reinitialize the templates */
- result = repo_init_config(repository_path.ptr, is_bare, is_reinit);
- goto cleanup;
- }
+ if (repo_init_config(repository_path.ptr, is_bare, is_reinit) < 0)
+ goto cleanup;
- if (repo_init_structure(repository_path.ptr, is_bare) < 0 ||
+ } else if (repo_init_structure(repository_path.ptr, is_bare) < 0 ||
repo_init_config(repository_path.ptr, is_bare, is_reinit) < 0 ||
- repo_init_createhead(repository_path.ptr) < 0 ||
- git_repository_open(repo_out, repository_path.ptr) < 0) {
+ repo_init_createhead(repository_path.ptr) < 0) {
goto cleanup;
}
- result = 0;
+ result = git_repository_open(repo_out, repository_path.ptr);
cleanup:
git_buf_free(&repository_path);