static int repo_init_config( const char *repo_dir, const char *work_dir, uint32_t flags, uint32_t mode) { int error = 0; git_buf cfg_path = GIT_BUF_INIT, worktree_path = GIT_BUF_INIT; git_config *config = NULL; bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0); bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0); if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0) goto cleanup; if (is_reinit && (error = check_repositoryformatversion(config)) < 0) goto cleanup; #define SET_REPO_CONFIG(TYPE, NAME, VAL) do { \ if ((error = git_config_set_##TYPE(config, NAME, VAL)) < 0) \ goto cleanup; } while (0) SET_REPO_CONFIG(bool, "core.bare", is_bare); SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION); if ((error = repo_init_fs_configs( config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0) goto cleanup; if (!is_bare) { SET_REPO_CONFIG(bool, "core.logallrefupdates", true); if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) { if ((error = git_buf_sets(&worktree_path, work_dir)) < 0) goto cleanup; if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK)) if ((error = git_path_make_relative(&worktree_path, repo_dir)) < 0) goto cleanup; SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr); } else if (is_reinit) { if (git_config_delete_entry(config, "core.worktree") < 0) giterr_clear(); } }
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; }