int git_repository_open(git_repository **repo_out, const char *path) { git_repository *repo; int error = GIT_SUCCESS; assert(repo_out && path); repo = repository_alloc(); if (repo == NULL) return GIT_ENOMEM; error = guess_repository_dirs(repo, path); if (error < GIT_SUCCESS) goto cleanup; error = check_repository_dirs(repo); if (error < GIT_SUCCESS) goto cleanup; error = init_odb(repo); if (error < GIT_SUCCESS) goto cleanup; *repo_out = repo; return GIT_SUCCESS; cleanup: git_repository_free(repo); return error; }
int git_repository_open2(git_repository **repo_out, const char *git_dir, const char *git_object_directory, const char *git_index_file, const char *git_work_tree) { git_repository *repo; int error = GIT_SUCCESS; assert(repo_out); repo = repository_alloc(); if (repo == NULL) return GIT_ENOMEM; error = assign_repository_DIRs(repo, git_dir, git_object_directory, git_index_file, git_work_tree); if (error < GIT_SUCCESS) goto cleanup; error = init_odb(repo); if (error < GIT_SUCCESS) goto cleanup; *repo_out = repo; return GIT_SUCCESS; cleanup: git_repository_free(repo); return error; }
int git_repository_open_bare( git_repository **repo_ptr, const char *bare_path) { int error; git_buf path = GIT_BUF_INIT; git_repository *repo = NULL; if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0) return error; if (!valid_repository_path(&path)) { git_buf_free(&path); giterr_set(GITERR_REPOSITORY, "Path is not a repository: %s", bare_path); return GIT_ENOTFOUND; } repo = repository_alloc(); GITERR_CHECK_ALLOC(repo); repo->path_repository = git_buf_detach(&path); GITERR_CHECK_ALLOC(repo->path_repository); /* of course we're bare! */ repo->is_bare = 1; repo->workdir = NULL; *repo_ptr = repo; return 0; }
int git_repository_open_ext( git_repository **repo_ptr, const char *start_path, uint32_t flags, const char *ceiling_dirs) { int error; git_buf path = GIT_BUF_INIT, parent = GIT_BUF_INIT; git_repository *repo; *repo_ptr = NULL; if ((error = find_repo(&path, &parent, start_path, flags, ceiling_dirs)) < 0) return error; repo = repository_alloc(); GITERR_CHECK_ALLOC(repo); repo->path_repository = git_buf_detach(&path); GITERR_CHECK_ALLOC(repo->path_repository); if ((error = load_config_data(repo)) < 0 || (error = load_workdir(repo, &parent)) < 0) { git_repository_free(repo); return error; } git_buf_free(&parent); *repo_ptr = repo; return 0; }
int git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare) { int error = GIT_SUCCESS; git_repository *repo = NULL; repo_init results; assert(repo_out && path); results.path_repository = NULL; results.is_bare = is_bare; error = repo_init_find_dir(&results, path); if (error < GIT_SUCCESS) goto cleanup; if (!repo_init_check_head_existence(results.path_repository)) return repo_init_reinit(&results); error = repo_init_structure(&results); if (error < GIT_SUCCESS) goto cleanup; repo = repository_alloc(); if (repo == NULL) { error = GIT_ENOMEM; goto cleanup; } error = guess_repository_dirs(repo, results.path_repository); if (error < GIT_SUCCESS) goto cleanup; assert(repo->is_bare == is_bare); error = init_odb(repo); if (error < GIT_SUCCESS) goto cleanup; error = repo_init_createhead(repo); if (error < GIT_SUCCESS) goto cleanup; /* should never fail */ assert(check_repository_dirs(repo) == GIT_SUCCESS); free(results.path_repository); *repo_out = repo; return GIT_SUCCESS; cleanup: free(results.path_repository); git_repository_free(repo); return error; }
int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb) { git_repository *repo; repo = repository_alloc(); GITERR_CHECK_ALLOC(repo); git_repository_set_odb(repo, odb); *repo_out = repo; return 0; }
int git_repository_open_ext( git_repository **repo_ptr, const char *start_path, unsigned int flags, const char *ceiling_dirs) { int error; git_buf path = GIT_BUF_INIT, parent = GIT_BUF_INIT; git_repository *repo; if (repo_ptr) *repo_ptr = NULL; error = find_repo(&path, &parent, start_path, flags, ceiling_dirs); if (error < 0 || !repo_ptr) return error; repo = repository_alloc(); GITERR_CHECK_ALLOC(repo); repo->path_repository = git_buf_detach(&path); GITERR_CHECK_ALLOC(repo->path_repository); if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) repo->is_bare = 1; else { git_config *config = NULL; if ((error = git_repository_config_snapshot(&config, repo)) < 0 || (error = load_config_data(repo, config)) < 0 || (error = load_workdir(repo, config, &parent)) < 0) git_repository_free(repo); git_config_free(config); } if (!error) *repo_ptr = repo; git_buf_free(&parent); return error; }
int git_repository_open3(git_repository **repo_out, const char *git_dir, git_odb *object_database, const char *git_index_file, const char *git_work_tree) { git_repository *repo; int error = GIT_SUCCESS; assert(repo_out); if (object_database == NULL) return GIT_ERROR; repo = repository_alloc(); if (repo == NULL) return GIT_ENOMEM; error = assign_repository_dirs(repo, git_dir, NULL, git_index_file, git_work_tree); if (error < GIT_SUCCESS) goto cleanup; error = check_repository_dirs(repo); if (error < GIT_SUCCESS) goto cleanup; repo->db = object_database; *repo_out = repo; return GIT_SUCCESS; cleanup: git_repository_free(repo); return error; }
int git_repository_new(git_repository **out) { *out = repository_alloc(); return 0; }